Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
123
vendor/league/container/CHANGELOG.md
vendored
Normal file
123
vendor/league/container/CHANGELOG.md
vendored
Normal file
|
@ -0,0 +1,123 @@
|
|||
# Changelog
|
||||
|
||||
All Notable changes to `League\Container` will be documented in this file
|
||||
|
||||
## 2.3.0
|
||||
|
||||
### Added
|
||||
- Now implementation of the PSR-11.
|
||||
|
||||
### Changed
|
||||
- Can now wrap shared objects as `RawArgument`.
|
||||
- Ability to override shared items.
|
||||
|
||||
### Fixed
|
||||
- Booleans now recognised as accepted values.
|
||||
- Various docblock fixes.
|
||||
- Unused imports removed.
|
||||
- Unreachable arguments no longer passed.
|
||||
|
||||
## 2.2.0
|
||||
|
||||
### Changed
|
||||
- Service providers can now be added multiple times by giving them a signature.
|
||||
|
||||
## 2.1.0
|
||||
|
||||
### Added
|
||||
- Allow resolving of `RawArgument` objects as first class dependencies.
|
||||
|
||||
### Changed
|
||||
- Unnecessary recursion removed from `Container::get`.
|
||||
|
||||
## 2.0.3
|
||||
|
||||
### Fixed
|
||||
- Bug where delegating container was not passed to delegate when needed.
|
||||
- Bug where `Container::extend` would not return a shared definition to extend.
|
||||
|
||||
## 2.0.2
|
||||
|
||||
### Fixed
|
||||
- Bug introduced in 2.0.1 where shared definitions registered via a service provider would never be returned as shared.
|
||||
|
||||
## 2.0.1
|
||||
|
||||
### Fixed
|
||||
- Bug where shared definitions were not stored as shared.
|
||||
|
||||
## 2.0.0
|
||||
|
||||
### Added
|
||||
- Now implementation of the container-interop project.
|
||||
- `BootableServiceProviderInterface` for eagerly loaded service providers.
|
||||
- Delegate container functionality.
|
||||
- `RawArgument` to ensure scalars are not resolved from the container but seen as an argument.
|
||||
|
||||
### Altered
|
||||
- Refactor of definition functionality.
|
||||
- `Container::share` replaces `singleton` functionality to improve understanding.
|
||||
- Auto wiring is now disabled by default.
|
||||
- Auto wiring abstracted to be a delegate container `ReflectionContainer` handling all reflection based functionality.
|
||||
- Inflection functionality abstracted to an aggregate.
|
||||
- Service provider functionality abstracted to an aggregate.
|
||||
- Much bloat removed.
|
||||
- `Container::call` now proxies to `ReflectionContainer::call` and handles argument resolution in a much more efficient way.
|
||||
|
||||
### Removed
|
||||
- Ability to register invokables, this functionality added a layer of complexity too large for the problem it solved.
|
||||
- Container no longer accepts a configuration array, this functionality will now be provided by an external service provider package.
|
||||
|
||||
## 1.4.0
|
||||
|
||||
### Added
|
||||
- Added `isRegisteredCallable` method to public API.
|
||||
- Invoking `call` now accepts named arguments at runtime.
|
||||
|
||||
### Fixed
|
||||
- Container now stores instantiated Service Providers after first instantiation.
|
||||
- Extending a definition now looks in Service Providers as well as just Definitions.
|
||||
|
||||
## 1.3.1 - 2015-02-21
|
||||
|
||||
### Fixed
|
||||
- Fixed bug where arbitrary values were attempted to be resolved as classes.
|
||||
|
||||
## 1.3.0 - 2015-02-09
|
||||
|
||||
### Added
|
||||
- Added `ServiceProvider` functionality to allow cleaner resolving of complex dependencies.
|
||||
- Added `Inflector` functionality to allow for manipulation of resolved objects of a specific type.
|
||||
- Improvements to DRY throughout the package.
|
||||
|
||||
### Fixed
|
||||
- Setter in `ContainerAwareTrait` now returns self (`$this`).
|
||||
|
||||
## 1.2.1 - 2015-01-29
|
||||
|
||||
### Fixed
|
||||
- Allow arbitrary values to be registered via container config.
|
||||
|
||||
## 1.2.0 - 2015-01-13
|
||||
|
||||
### Added
|
||||
- Improvements to `Container::call` functionality.
|
||||
|
||||
### Fixed
|
||||
- General code tidy.
|
||||
- Improvements to test suite.
|
||||
|
||||
## 1.1.1 - 2015-01-13
|
||||
|
||||
### Fixed
|
||||
- Allow singleton to be passed as method argument.
|
||||
|
||||
## 1.1.0 - 2015-01-12
|
||||
|
||||
### Added
|
||||
- Addition of `ContainerAwareTrait` to provide functionality from `ContainerAwareInterface`.
|
||||
|
||||
## 1.0.0 - 2015-01-12
|
||||
|
||||
### Added
|
||||
- Migrated from [Orno\Di](https://github.com/orno/di).
|
29
vendor/league/container/CONTRIBUTING.md
vendored
Normal file
29
vendor/league/container/CONTRIBUTING.md
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Contributing
|
||||
|
||||
Contributions are **welcome** and will be fully **credited**.
|
||||
|
||||
We accept contributions via Pull Requests on [Github](https://github.com/thephpleague/container).
|
||||
|
||||
## Pull Requests
|
||||
|
||||
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
|
||||
|
||||
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
|
||||
|
||||
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
|
||||
|
||||
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
|
||||
|
||||
- **Create feature branches** - Don't ask us to pull from your master branch.
|
||||
|
||||
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
|
||||
|
||||
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.
|
||||
|
||||
## Running Tests
|
||||
|
||||
``` bash
|
||||
$ phpunit
|
||||
```
|
||||
|
||||
**Happy coding**!
|
21
vendor/league/container/LICENSE.md
vendored
Normal file
21
vendor/league/container/LICENSE.md
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
# The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Phil Bennett <philipobenito@gmail.com>
|
||||
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
> of this software and associated documentation files (the "Software"), to deal
|
||||
> in the Software without restriction, including without limitation the rights
|
||||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
> copies of the Software, and to permit persons to whom the Software is
|
||||
> furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in
|
||||
> all copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
> THE SOFTWARE.
|
69
vendor/league/container/README.md
vendored
Normal file
69
vendor/league/container/README.md
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
# Container (Dependency Injection)
|
||||
|
||||
[](https://twitter.com/philipobenito)
|
||||
[](https://github.com/thephpleague/container/releases)
|
||||
[](LICENSE.md)
|
||||
[](https://travis-ci.org/thephpleague/container)
|
||||
[](https://scrutinizer-ci.com/g/thephpleague/container/code-structure)
|
||||
[](https://scrutinizer-ci.com/g/thephpleague/container)
|
||||
[](https://packagist.org/packages/league/container)
|
||||
|
||||
[](https://insight.sensiolabs.com/projects/ad6b4c3e-8f93-4968-8dd3-391d39a4c3c2)
|
||||
|
||||
This package is compliant with [PSR-1], [PSR-2] and [PSR-4]. If you notice compliance oversights,
|
||||
please send a patch via pull request.
|
||||
|
||||
[PSR-1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md
|
||||
[PSR-2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
|
||||
[PSR-4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md
|
||||
[PSR-11]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md
|
||||
|
||||
## Install
|
||||
|
||||
Via Composer
|
||||
|
||||
``` bash
|
||||
$ composer require league/container
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
The following versions of PHP are supported by this version.
|
||||
|
||||
* PHP 5.4
|
||||
* PHP 5.5
|
||||
* PHP 5.6
|
||||
* PHP 7.0
|
||||
* PHP 7.1
|
||||
* HHVM
|
||||
|
||||
## Documentation
|
||||
|
||||
Container has [full documentation](http://container.thephpleague.com), powered by [Jekyll](http://jekyllrb.com/).
|
||||
|
||||
Contribute to this documentation in the [gh-pages branch](https://github.com/thephpleague/container/tree/gh-pages/).
|
||||
|
||||
## Testing
|
||||
|
||||
``` bash
|
||||
$ vendor/bin/phpunit
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Please see [CONTRIBUTING](https://github.com/thephpleague/container/blob/master/CONTRIBUTING.md) for details.
|
||||
|
||||
## Security
|
||||
|
||||
If you discover any security related issues, please email philipobenito@gmail.com instead of using the issue tracker.
|
||||
|
||||
## Credits
|
||||
|
||||
- [Phil Bennett](https://github.com/philipobenito)
|
||||
- [All Contributors](https://github.com/thephpleague/container/contributors)
|
||||
|
||||
All `Orno\Di` contributions can be found [here](https://github.com/orno/di/graphs/contributors).
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT). Please see [License File](https://github.com/thephpleague/container/blob/master/LICENSE.md) for more information.
|
53
vendor/league/container/composer.json
vendored
Normal file
53
vendor/league/container/composer.json
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
"name": "league/container",
|
||||
"description": "A fast and intuitive dependency injection container.",
|
||||
"keywords": [
|
||||
"league",
|
||||
"container",
|
||||
"dependency",
|
||||
"injection",
|
||||
"di",
|
||||
"service",
|
||||
"provider"
|
||||
],
|
||||
"homepage": "https://github.com/thephpleague/container",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Phil Bennett",
|
||||
"email": "philipobenito@gmail.com",
|
||||
"homepage": "http://www.philipobenito.com",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^5.4.0 || ^7.0",
|
||||
"container-interop/container-interop": "^1.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit" : "4.*"
|
||||
},
|
||||
"provide": {
|
||||
"container-interop/container-interop-implementation": "^1.2",
|
||||
"psr/container-implementation": "^1.0"
|
||||
},
|
||||
"replace": {
|
||||
"orno/di": "~2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"League\\Container\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"League\\Container\\Test\\": "tests"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-2.x": "2.x-dev",
|
||||
"dev-1.x": "1.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
26
vendor/league/container/src/Argument/ArgumentResolverInterface.php
vendored
Normal file
26
vendor/league/container/src/Argument/ArgumentResolverInterface.php
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Argument;
|
||||
|
||||
use League\Container\ImmutableContainerAwareInterface;
|
||||
use ReflectionFunctionAbstract;
|
||||
|
||||
interface ArgumentResolverInterface extends ImmutableContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* Resolve an array of arguments to their concrete implementations.
|
||||
*
|
||||
* @param array $arguments
|
||||
* @return array
|
||||
*/
|
||||
public function resolveArguments(array $arguments);
|
||||
|
||||
/**
|
||||
* Resolves the correct arguments to be passed to a method.
|
||||
*
|
||||
* @param \ReflectionFunctionAbstract $method
|
||||
* @param array $args
|
||||
* @return array
|
||||
*/
|
||||
public function reflectArguments(ReflectionFunctionAbstract $method, array $args = []);
|
||||
}
|
82
vendor/league/container/src/Argument/ArgumentResolverTrait.php
vendored
Normal file
82
vendor/league/container/src/Argument/ArgumentResolverTrait.php
vendored
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Argument;
|
||||
|
||||
use League\Container\Exception\NotFoundException;
|
||||
use League\Container\ReflectionContainer;
|
||||
use ReflectionFunctionAbstract;
|
||||
use ReflectionParameter;
|
||||
|
||||
trait ArgumentResolverTrait
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function resolveArguments(array $arguments)
|
||||
{
|
||||
foreach ($arguments as &$arg) {
|
||||
if ($arg instanceof RawArgumentInterface) {
|
||||
$arg = $arg->getValue();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! is_string($arg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$container = $this->getContainer();
|
||||
|
||||
if (is_null($container) && $this instanceof ReflectionContainer) {
|
||||
$container = $this;
|
||||
}
|
||||
|
||||
if (! is_null($container) && $container->has($arg)) {
|
||||
$arg = $container->get($arg);
|
||||
|
||||
if ($arg instanceof RawArgumentInterface) {
|
||||
$arg = $arg->getValue();
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reflectArguments(ReflectionFunctionAbstract $method, array $args = [])
|
||||
{
|
||||
$arguments = array_map(function (ReflectionParameter $param) use ($method, $args) {
|
||||
$name = $param->getName();
|
||||
$class = $param->getClass();
|
||||
|
||||
if (array_key_exists($name, $args)) {
|
||||
return $args[$name];
|
||||
}
|
||||
|
||||
if (! is_null($class)) {
|
||||
return $class->getName();
|
||||
}
|
||||
|
||||
if ($param->isDefaultValueAvailable()) {
|
||||
return $param->getDefaultValue();
|
||||
}
|
||||
|
||||
throw new NotFoundException(sprintf(
|
||||
'Unable to resolve a value for parameter (%s) in the function/method (%s)',
|
||||
$name,
|
||||
$method->getName()
|
||||
));
|
||||
}, $method->getParameters());
|
||||
|
||||
return $this->resolveArguments($arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \League\Container\ContainerInterface
|
||||
*/
|
||||
abstract public function getContainer();
|
||||
}
|
27
vendor/league/container/src/Argument/RawArgument.php
vendored
Normal file
27
vendor/league/container/src/Argument/RawArgument.php
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Argument;
|
||||
|
||||
class RawArgument implements RawArgumentInterface
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
13
vendor/league/container/src/Argument/RawArgumentInterface.php
vendored
Normal file
13
vendor/league/container/src/Argument/RawArgumentInterface.php
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Argument;
|
||||
|
||||
interface RawArgumentInterface
|
||||
{
|
||||
/**
|
||||
* Return the value of the raw argument.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue();
|
||||
}
|
305
vendor/league/container/src/Container.php
vendored
Normal file
305
vendor/league/container/src/Container.php
vendored
Normal file
|
@ -0,0 +1,305 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container;
|
||||
|
||||
use Interop\Container\ContainerInterface as InteropContainerInterface;
|
||||
use League\Container\Argument\RawArgumentInterface;
|
||||
use League\Container\Definition\DefinitionFactory;
|
||||
use League\Container\Definition\DefinitionFactoryInterface;
|
||||
use League\Container\Definition\DefinitionInterface;
|
||||
use League\Container\Exception\NotFoundException;
|
||||
use League\Container\Inflector\InflectorAggregate;
|
||||
use League\Container\Inflector\InflectorAggregateInterface;
|
||||
use League\Container\ServiceProvider\ServiceProviderAggregate;
|
||||
use League\Container\ServiceProvider\ServiceProviderAggregateInterface;
|
||||
|
||||
class Container implements ContainerInterface
|
||||
{
|
||||
/**
|
||||
* @var \League\Container\Definition\DefinitionFactoryInterface
|
||||
*/
|
||||
protected $definitionFactory;
|
||||
|
||||
/**
|
||||
* @var \League\Container\Definition\DefinitionInterface[]
|
||||
*/
|
||||
protected $definitions = [];
|
||||
|
||||
/**
|
||||
* @var \League\Container\Definition\DefinitionInterface[]
|
||||
*/
|
||||
protected $sharedDefinitions = [];
|
||||
|
||||
/**
|
||||
* @var \League\Container\Inflector\InflectorAggregateInterface
|
||||
*/
|
||||
protected $inflectors;
|
||||
|
||||
/**
|
||||
* @var \League\Container\ServiceProvider\ServiceProviderAggregateInterface
|
||||
*/
|
||||
protected $providers;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $shared = [];
|
||||
|
||||
/**
|
||||
* @var \Interop\Container\ContainerInterface[]
|
||||
*/
|
||||
protected $delegates = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \League\Container\ServiceProvider\ServiceProviderAggregateInterface|null $providers
|
||||
* @param \League\Container\Inflector\InflectorAggregateInterface|null $inflectors
|
||||
* @param \League\Container\Definition\DefinitionFactoryInterface|null $definitionFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ServiceProviderAggregateInterface $providers = null,
|
||||
InflectorAggregateInterface $inflectors = null,
|
||||
DefinitionFactoryInterface $definitionFactory = null
|
||||
) {
|
||||
// set required dependencies
|
||||
$this->providers = (is_null($providers))
|
||||
? (new ServiceProviderAggregate)->setContainer($this)
|
||||
: $providers->setContainer($this);
|
||||
|
||||
$this->inflectors = (is_null($inflectors))
|
||||
? (new InflectorAggregate)->setContainer($this)
|
||||
: $inflectors->setContainer($this);
|
||||
|
||||
$this->definitionFactory = (is_null($definitionFactory))
|
||||
? (new DefinitionFactory)->setContainer($this)
|
||||
: $definitionFactory->setContainer($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($alias, array $args = [])
|
||||
{
|
||||
try {
|
||||
return $this->getFromThisContainer($alias, $args);
|
||||
} catch (NotFoundException $exception) {
|
||||
if ($this->providers->provides($alias)) {
|
||||
$this->providers->register($alias);
|
||||
|
||||
return $this->getFromThisContainer($alias, $args);
|
||||
}
|
||||
|
||||
$resolved = $this->getFromDelegate($alias, $args);
|
||||
|
||||
return $this->inflectors->inflect($resolved);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($alias)
|
||||
{
|
||||
if (array_key_exists($alias, $this->definitions) || $this->hasShared($alias)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->providers->provides($alias)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasInDelegate($alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean to determine if the container has a shared instance of an alias.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param boolean $resolved
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasShared($alias, $resolved = false)
|
||||
{
|
||||
$shared = ($resolved === false) ? array_merge($this->shared, $this->sharedDefinitions) : $this->shared;
|
||||
|
||||
return (array_key_exists($alias, $shared));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($alias, $concrete = null, $share = false)
|
||||
{
|
||||
unset($this->shared[$alias]);
|
||||
unset($this->definitions[$alias]);
|
||||
unset($this->sharedDefinitions[$alias]);
|
||||
|
||||
if (is_null($concrete)) {
|
||||
$concrete = $alias;
|
||||
}
|
||||
|
||||
$definition = $this->definitionFactory->getDefinition($alias, $concrete);
|
||||
|
||||
if ($definition instanceof DefinitionInterface) {
|
||||
if ($share === false) {
|
||||
$this->definitions[$alias] = $definition;
|
||||
} else {
|
||||
$this->sharedDefinitions[$alias] = $definition;
|
||||
}
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
// dealing with a value that cannot build a definition
|
||||
$this->shared[$alias] = $concrete;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function share($alias, $concrete = null)
|
||||
{
|
||||
return $this->add($alias, $concrete, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addServiceProvider($provider)
|
||||
{
|
||||
$this->providers->add($provider);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function extend($alias)
|
||||
{
|
||||
if ($this->providers->provides($alias)) {
|
||||
$this->providers->register($alias);
|
||||
}
|
||||
|
||||
if (array_key_exists($alias, $this->definitions)) {
|
||||
return $this->definitions[$alias];
|
||||
}
|
||||
|
||||
if (array_key_exists($alias, $this->sharedDefinitions)) {
|
||||
return $this->sharedDefinitions[$alias];
|
||||
}
|
||||
|
||||
throw new NotFoundException(
|
||||
sprintf('Unable to extend alias (%s) as it is not being managed as a definition', $alias)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function inflector($type, callable $callback = null)
|
||||
{
|
||||
return $this->inflectors->add($type, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function call(callable $callable, array $args = [])
|
||||
{
|
||||
return (new ReflectionContainer)->setContainer($this)->call($callable, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegate a backup container to be checked for services if it
|
||||
* cannot be resolved via this container.
|
||||
*
|
||||
* @param \Interop\Container\ContainerInterface $container
|
||||
* @return $this
|
||||
*/
|
||||
public function delegate(InteropContainerInterface $container)
|
||||
{
|
||||
$this->delegates[] = $container;
|
||||
|
||||
if ($container instanceof ImmutableContainerAwareInterface) {
|
||||
$container->setContainer($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if service is registered in one of the delegated backup containers.
|
||||
*
|
||||
* @param string $alias
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasInDelegate($alias)
|
||||
{
|
||||
foreach ($this->delegates as $container) {
|
||||
if ($container->has($alias)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to get a service from the stack of delegated backup containers.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getFromDelegate($alias, array $args = [])
|
||||
{
|
||||
foreach ($this->delegates as $container) {
|
||||
if ($container->has($alias)) {
|
||||
return $container->get($alias, $args);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new NotFoundException(
|
||||
sprintf('Alias (%s) is not being managed by the container', $alias)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a service that has been registered in this container.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getFromThisContainer($alias, array $args = [])
|
||||
{
|
||||
if ($this->hasShared($alias, true)) {
|
||||
$shared = $this->inflectors->inflect($this->shared[$alias]);
|
||||
if ($shared instanceof RawArgumentInterface) {
|
||||
return $shared->getValue();
|
||||
}
|
||||
return $shared;
|
||||
}
|
||||
|
||||
if (array_key_exists($alias, $this->sharedDefinitions)) {
|
||||
$shared = $this->inflectors->inflect($this->sharedDefinitions[$alias]->build());
|
||||
$this->shared[$alias] = $shared;
|
||||
return $shared;
|
||||
}
|
||||
|
||||
if (array_key_exists($alias, $this->definitions)) {
|
||||
return $this->inflectors->inflect(
|
||||
$this->definitions[$alias]->build($args)
|
||||
);
|
||||
}
|
||||
|
||||
throw new NotFoundException(
|
||||
sprintf('Alias (%s) is not being managed by the container', $alias)
|
||||
);
|
||||
}
|
||||
}
|
20
vendor/league/container/src/ContainerAwareInterface.php
vendored
Normal file
20
vendor/league/container/src/ContainerAwareInterface.php
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container;
|
||||
|
||||
interface ContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* Set a container
|
||||
*
|
||||
* @param \League\Container\ContainerInterface $container
|
||||
*/
|
||||
public function setContainer(ContainerInterface $container);
|
||||
|
||||
/**
|
||||
* Get the container
|
||||
*
|
||||
* @return \League\Container\ContainerInterface
|
||||
*/
|
||||
public function getContainer();
|
||||
}
|
34
vendor/league/container/src/ContainerAwareTrait.php
vendored
Normal file
34
vendor/league/container/src/ContainerAwareTrait.php
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container;
|
||||
|
||||
trait ContainerAwareTrait
|
||||
{
|
||||
/**
|
||||
* @var \League\Container\ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Set a container.
|
||||
*
|
||||
* @param \League\Container\ContainerInterface $container
|
||||
* @return $this
|
||||
*/
|
||||
public function setContainer(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the container.
|
||||
*
|
||||
* @return \League\Container\ContainerInterface
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
}
|
59
vendor/league/container/src/ContainerInterface.php
vendored
Normal file
59
vendor/league/container/src/ContainerInterface.php
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container;
|
||||
|
||||
interface ContainerInterface extends ImmutableContainerInterface
|
||||
{
|
||||
/**
|
||||
* Add an item to the container.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param mixed|null $concrete
|
||||
* @param boolean $share
|
||||
* @return \League\Container\Definition\DefinitionInterface
|
||||
*/
|
||||
public function add($alias, $concrete = null, $share = false);
|
||||
|
||||
/**
|
||||
* Convenience method to add an item to the container as a shared item.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param mixed|null $concrete
|
||||
* @return \League\Container\Definition\DefinitionInterface
|
||||
*/
|
||||
public function share($alias, $concrete = null);
|
||||
|
||||
/**
|
||||
* Add a service provider to the container.
|
||||
*
|
||||
* @param string|\League\Container\ServiceProvider\ServiceProviderInterface $provider
|
||||
* @return void
|
||||
*/
|
||||
public function addServiceProvider($provider);
|
||||
|
||||
/**
|
||||
* Returns a definition of an item to be extended.
|
||||
*
|
||||
* @param string $alias
|
||||
* @return \League\Container\Definition\DefinitionInterface
|
||||
*/
|
||||
public function extend($alias);
|
||||
|
||||
/**
|
||||
* Allows for manipulation of specific types on resolution.
|
||||
*
|
||||
* @param string $type
|
||||
* @param callable|null $callback
|
||||
* @return \League\Container\Inflector\Inflector|void
|
||||
*/
|
||||
public function inflector($type, callable $callback = null);
|
||||
|
||||
/**
|
||||
* Invoke a callable via the container.
|
||||
*
|
||||
* @param callable $callable
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function call(callable $callable, array $args = []);
|
||||
}
|
62
vendor/league/container/src/Definition/AbstractDefinition.php
vendored
Normal file
62
vendor/league/container/src/Definition/AbstractDefinition.php
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Definition;
|
||||
|
||||
use League\Container\Argument\ArgumentResolverInterface;
|
||||
use League\Container\Argument\ArgumentResolverTrait;
|
||||
use League\Container\ImmutableContainerAwareTrait;
|
||||
|
||||
abstract class AbstractDefinition implements ArgumentResolverInterface, DefinitionInterface
|
||||
{
|
||||
use ArgumentResolverTrait;
|
||||
use ImmutableContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $alias;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $concrete;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param mixed $concrete
|
||||
*/
|
||||
public function __construct($alias, $concrete)
|
||||
{
|
||||
$this->alias = $alias;
|
||||
$this->concrete = $concrete;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withArgument($arg)
|
||||
{
|
||||
$this->arguments[] = $arg;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withArguments(array $args)
|
||||
{
|
||||
foreach ($args as $arg) {
|
||||
$this->withArgument($arg);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
23
vendor/league/container/src/Definition/CallableDefinition.php
vendored
Normal file
23
vendor/league/container/src/Definition/CallableDefinition.php
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Definition;
|
||||
|
||||
class CallableDefinition extends AbstractDefinition
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(array $args = [])
|
||||
{
|
||||
$args = (empty($args)) ? $this->arguments : $args;
|
||||
$resolved = $this->resolveArguments($args);
|
||||
|
||||
if (is_array($this->concrete) && is_string($this->concrete[0])) {
|
||||
$this->concrete[0] = ($this->getContainer()->has($this->concrete[0]))
|
||||
? $this->getContainer()->get($this->concrete[0])
|
||||
: $this->concrete[0];
|
||||
}
|
||||
|
||||
return call_user_func_array($this->concrete, $resolved);
|
||||
}
|
||||
}
|
67
vendor/league/container/src/Definition/ClassDefinition.php
vendored
Normal file
67
vendor/league/container/src/Definition/ClassDefinition.php
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Definition;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
class ClassDefinition extends AbstractDefinition implements ClassDefinitionInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $methods = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withMethodCall($method, array $args = [])
|
||||
{
|
||||
$this->methods[] = [
|
||||
'method' => $method,
|
||||
'arguments' => $args
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withMethodCalls(array $methods = [])
|
||||
{
|
||||
foreach ($methods as $method => $args) {
|
||||
$this->withMethodCall($method, $args);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(array $args = [])
|
||||
{
|
||||
$args = (empty($args)) ? $this->arguments : $args;
|
||||
$resolved = $this->resolveArguments($args);
|
||||
$reflection = new ReflectionClass($this->concrete);
|
||||
$instance = $reflection->newInstanceArgs($resolved);
|
||||
|
||||
return $this->invokeMethods($instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke methods on resolved instance.
|
||||
*
|
||||
* @param object $instance
|
||||
* @return object
|
||||
*/
|
||||
protected function invokeMethods($instance)
|
||||
{
|
||||
foreach ($this->methods as $method) {
|
||||
$args = $this->resolveArguments($method['arguments']);
|
||||
call_user_func_array([$instance, $method['method']], $args);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
}
|
23
vendor/league/container/src/Definition/ClassDefinitionInterface.php
vendored
Normal file
23
vendor/league/container/src/Definition/ClassDefinitionInterface.php
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Definition;
|
||||
|
||||
interface ClassDefinitionInterface extends DefinitionInterface
|
||||
{
|
||||
/**
|
||||
* Add a method to be invoked
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return $this
|
||||
*/
|
||||
public function withMethodCall($method, array $args = []);
|
||||
|
||||
/**
|
||||
* Add multiple methods to be invoked
|
||||
*
|
||||
* @param array $methods
|
||||
* @return $this
|
||||
*/
|
||||
public function withMethodCalls(array $methods = []);
|
||||
}
|
28
vendor/league/container/src/Definition/DefinitionFactory.php
vendored
Normal file
28
vendor/league/container/src/Definition/DefinitionFactory.php
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Definition;
|
||||
|
||||
use League\Container\ImmutableContainerAwareTrait;
|
||||
|
||||
class DefinitionFactory implements DefinitionFactoryInterface
|
||||
{
|
||||
use ImmutableContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefinition($alias, $concrete)
|
||||
{
|
||||
if (is_callable($concrete)) {
|
||||
return (new CallableDefinition($alias, $concrete))->setContainer($this->getContainer());
|
||||
}
|
||||
|
||||
if (is_string($concrete) && class_exists($concrete)) {
|
||||
return (new ClassDefinition($alias, $concrete))->setContainer($this->getContainer());
|
||||
}
|
||||
|
||||
// if the item is not definable we just return the value to be stored
|
||||
// in the container as an arbitrary value/instance
|
||||
return $concrete;
|
||||
}
|
||||
}
|
17
vendor/league/container/src/Definition/DefinitionFactoryInterface.php
vendored
Normal file
17
vendor/league/container/src/Definition/DefinitionFactoryInterface.php
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Definition;
|
||||
|
||||
use League\Container\ImmutableContainerAwareInterface;
|
||||
|
||||
interface DefinitionFactoryInterface extends ImmutableContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* Return a definition based on type of concrete.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param mixed $concrete
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDefinition($alias, $concrete);
|
||||
}
|
30
vendor/league/container/src/Definition/DefinitionInterface.php
vendored
Normal file
30
vendor/league/container/src/Definition/DefinitionInterface.php
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Definition;
|
||||
|
||||
interface DefinitionInterface
|
||||
{
|
||||
/**
|
||||
* Handle instantiation and manipulation of value and return.
|
||||
*
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function build(array $args = []);
|
||||
|
||||
/**
|
||||
* Add an argument to be injected.
|
||||
*
|
||||
* @param mixed $arg
|
||||
* @return $this
|
||||
*/
|
||||
public function withArgument($arg);
|
||||
|
||||
/**
|
||||
* Add multiple arguments to be injected.
|
||||
*
|
||||
* @param array $args
|
||||
* @return $this
|
||||
*/
|
||||
public function withArguments(array $args);
|
||||
}
|
10
vendor/league/container/src/Exception/NotFoundException.php
vendored
Normal file
10
vendor/league/container/src/Exception/NotFoundException.php
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Exception;
|
||||
|
||||
use Interop\Container\Exception\NotFoundException as NotFoundExceptionInterface;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class NotFoundException extends InvalidArgumentException implements NotFoundExceptionInterface
|
||||
{
|
||||
}
|
22
vendor/league/container/src/ImmutableContainerAwareInterface.php
vendored
Normal file
22
vendor/league/container/src/ImmutableContainerAwareInterface.php
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container;
|
||||
|
||||
use Interop\Container\ContainerInterface as InteropContainerInterface;
|
||||
|
||||
interface ImmutableContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* Set a container
|
||||
*
|
||||
* @param \Interop\Container\ContainerInterface $container
|
||||
*/
|
||||
public function setContainer(InteropContainerInterface $container);
|
||||
|
||||
/**
|
||||
* Get the container
|
||||
*
|
||||
* @return \League\Container\ImmutableContainerInterface
|
||||
*/
|
||||
public function getContainer();
|
||||
}
|
36
vendor/league/container/src/ImmutableContainerAwareTrait.php
vendored
Normal file
36
vendor/league/container/src/ImmutableContainerAwareTrait.php
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container;
|
||||
|
||||
use Interop\Container\ContainerInterface as InteropContainerInterface;
|
||||
|
||||
trait ImmutableContainerAwareTrait
|
||||
{
|
||||
/**
|
||||
* @var \Interop\Container\ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Set a container.
|
||||
*
|
||||
* @param \Interop\Container\ContainerInterface $container
|
||||
* @return $this
|
||||
*/
|
||||
public function setContainer(InteropContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the container.
|
||||
*
|
||||
* @return \League\Container\ImmutableContainerInterface
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
}
|
10
vendor/league/container/src/ImmutableContainerInterface.php
vendored
Normal file
10
vendor/league/container/src/ImmutableContainerInterface.php
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container;
|
||||
|
||||
use Interop\Container\ContainerInterface as InteropContainerInterface;
|
||||
|
||||
interface ImmutableContainerInterface extends InteropContainerInterface
|
||||
{
|
||||
|
||||
}
|
103
vendor/league/container/src/Inflector/Inflector.php
vendored
Normal file
103
vendor/league/container/src/Inflector/Inflector.php
vendored
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Inflector;
|
||||
|
||||
use League\Container\ImmutableContainerAwareTrait;
|
||||
use League\Container\Argument\ArgumentResolverInterface;
|
||||
use League\Container\Argument\ArgumentResolverTrait;
|
||||
|
||||
class Inflector implements ArgumentResolverInterface
|
||||
{
|
||||
use ArgumentResolverTrait;
|
||||
use ImmutableContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $methods = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $properties = [];
|
||||
|
||||
/**
|
||||
* Defines a method to be invoked on the subject object.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
* @return $this
|
||||
*/
|
||||
public function invokeMethod($name, array $args)
|
||||
{
|
||||
$this->methods[$name] = $args;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines multiple methods to be invoked on the subject object.
|
||||
*
|
||||
* @param array $methods
|
||||
* @return $this
|
||||
*/
|
||||
public function invokeMethods(array $methods)
|
||||
{
|
||||
foreach ($methods as $name => $args) {
|
||||
$this->invokeMethod($name, $args);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a property to be set on the subject object.
|
||||
*
|
||||
* @param string $property
|
||||
* @param mixed $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperty($property, $value)
|
||||
{
|
||||
$this->properties[$property] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines multiple properties to be set on the subject object.
|
||||
*
|
||||
* @param array $properties
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperties(array $properties)
|
||||
{
|
||||
foreach ($properties as $property => $value) {
|
||||
$this->setProperty($property, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply inflections to an object.
|
||||
*
|
||||
* @param object $object
|
||||
* @return void
|
||||
*/
|
||||
public function inflect($object)
|
||||
{
|
||||
$properties = $this->resolveArguments(array_values($this->properties));
|
||||
$properties = array_combine(array_keys($this->properties), $properties);
|
||||
|
||||
foreach ($properties as $property => $value) {
|
||||
$object->{$property} = $value;
|
||||
}
|
||||
|
||||
foreach ($this->methods as $method => $args) {
|
||||
$args = $this->resolveArguments($args);
|
||||
|
||||
call_user_func_array([$object, $method], $args);
|
||||
}
|
||||
}
|
||||
}
|
53
vendor/league/container/src/Inflector/InflectorAggregate.php
vendored
Normal file
53
vendor/league/container/src/Inflector/InflectorAggregate.php
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Inflector;
|
||||
|
||||
use League\Container\ImmutableContainerAwareTrait;
|
||||
|
||||
class InflectorAggregate implements InflectorAggregateInterface
|
||||
{
|
||||
use ImmutableContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $inflectors = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($type, callable $callback = null)
|
||||
{
|
||||
if (is_null($callback)) {
|
||||
$inflector = new Inflector;
|
||||
$this->inflectors[$type] = $inflector;
|
||||
|
||||
return $inflector;
|
||||
}
|
||||
|
||||
$this->inflectors[$type] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function inflect($object)
|
||||
{
|
||||
foreach ($this->inflectors as $type => $inflector) {
|
||||
if (! $object instanceof $type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($inflector instanceof Inflector) {
|
||||
$inflector->setContainer($this->getContainer());
|
||||
$inflector->inflect($object);
|
||||
continue;
|
||||
}
|
||||
|
||||
// must be dealing with a callable as the inflector
|
||||
call_user_func_array($inflector, [$object]);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
25
vendor/league/container/src/Inflector/InflectorAggregateInterface.php
vendored
Normal file
25
vendor/league/container/src/Inflector/InflectorAggregateInterface.php
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\Inflector;
|
||||
|
||||
use League\Container\ImmutableContainerAwareInterface;
|
||||
|
||||
interface InflectorAggregateInterface extends ImmutableContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* Add an inflector to the aggregate.
|
||||
*
|
||||
* @param string $type
|
||||
* @param callable $callback
|
||||
* @return \League\Container\Inflector\Inflector
|
||||
*/
|
||||
public function add($type, callable $callback = null);
|
||||
|
||||
/**
|
||||
* Applies all inflectors to an object.
|
||||
*
|
||||
* @param object $object
|
||||
* @return object
|
||||
*/
|
||||
public function inflect($object);
|
||||
}
|
87
vendor/league/container/src/ReflectionContainer.php
vendored
Normal file
87
vendor/league/container/src/ReflectionContainer.php
vendored
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container;
|
||||
|
||||
use League\Container\Argument\ArgumentResolverInterface;
|
||||
use League\Container\Argument\ArgumentResolverTrait;
|
||||
use League\Container\Exception\NotFoundException;
|
||||
use ReflectionClass;
|
||||
use ReflectionFunction;
|
||||
use ReflectionMethod;
|
||||
|
||||
class ReflectionContainer implements
|
||||
ArgumentResolverInterface,
|
||||
ImmutableContainerInterface
|
||||
{
|
||||
use ArgumentResolverTrait;
|
||||
use ImmutableContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($alias, array $args = [])
|
||||
{
|
||||
if (! $this->has($alias)) {
|
||||
throw new NotFoundException(
|
||||
sprintf('Alias (%s) is not an existing class and therefore cannot be resolved', $alias)
|
||||
);
|
||||
}
|
||||
|
||||
$reflector = new ReflectionClass($alias);
|
||||
$construct = $reflector->getConstructor();
|
||||
|
||||
if ($construct === null) {
|
||||
return new $alias;
|
||||
}
|
||||
|
||||
return $reflector->newInstanceArgs(
|
||||
$this->reflectArguments($construct, $args)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($alias)
|
||||
{
|
||||
return class_exists($alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke a callable via the container.
|
||||
*
|
||||
* @param callable $callable
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function call(callable $callable, array $args = [])
|
||||
{
|
||||
if (is_string($callable) && strpos($callable, '::') !== false) {
|
||||
$callable = explode('::', $callable);
|
||||
}
|
||||
|
||||
if (is_array($callable)) {
|
||||
if (is_string($callable[0])) {
|
||||
$callable[0] = $this->getContainer()->get($callable[0]);
|
||||
}
|
||||
|
||||
$reflection = new ReflectionMethod($callable[0], $callable[1]);
|
||||
|
||||
if ($reflection->isStatic()) {
|
||||
$callable[0] = null;
|
||||
}
|
||||
|
||||
return $reflection->invokeArgs($callable[0], $this->reflectArguments($reflection, $args));
|
||||
}
|
||||
|
||||
if (is_object($callable)) {
|
||||
$reflection = new ReflectionMethod($callable, '__invoke');
|
||||
|
||||
return $reflection->invokeArgs($callable, $this->reflectArguments($reflection, $args));
|
||||
}
|
||||
|
||||
$reflection = new ReflectionFunction($callable);
|
||||
|
||||
return $reflection->invokeArgs($this->reflectArguments($reflection, $args));
|
||||
}
|
||||
}
|
27
vendor/league/container/src/ServiceProvider/AbstractServiceProvider.php
vendored
Normal file
27
vendor/league/container/src/ServiceProvider/AbstractServiceProvider.php
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\ServiceProvider;
|
||||
|
||||
use League\Container\ContainerAwareTrait;
|
||||
|
||||
abstract class AbstractServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $provides = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provides($alias = null)
|
||||
{
|
||||
if (! is_null($alias)) {
|
||||
return (in_array($alias, $this->provides));
|
||||
}
|
||||
|
||||
return $this->provides;
|
||||
}
|
||||
}
|
31
vendor/league/container/src/ServiceProvider/AbstractSignatureServiceProvider.php
vendored
Normal file
31
vendor/league/container/src/ServiceProvider/AbstractSignatureServiceProvider.php
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\ServiceProvider;
|
||||
|
||||
abstract class AbstractSignatureServiceProvider
|
||||
extends AbstractServiceProvider
|
||||
implements SignatureServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $signature;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withSignature($signature)
|
||||
{
|
||||
$this->signature = $signature;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSignature()
|
||||
{
|
||||
return (is_null($this->signature)) ? get_class($this) : $this->signature;
|
||||
}
|
||||
}
|
14
vendor/league/container/src/ServiceProvider/BootableServiceProviderInterface.php
vendored
Normal file
14
vendor/league/container/src/ServiceProvider/BootableServiceProviderInterface.php
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\ServiceProvider;
|
||||
|
||||
interface BootableServiceProviderInterface extends ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Method will be invoked on registration of a service provider implementing
|
||||
* this interface. Provides ability for eager loading of Service Providers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot();
|
||||
}
|
88
vendor/league/container/src/ServiceProvider/ServiceProviderAggregate.php
vendored
Normal file
88
vendor/league/container/src/ServiceProvider/ServiceProviderAggregate.php
vendored
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\ServiceProvider;
|
||||
|
||||
use League\Container\ContainerAwareInterface;
|
||||
use League\Container\ContainerAwareTrait;
|
||||
|
||||
class ServiceProviderAggregate implements ServiceProviderAggregateInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $providers = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $registered = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($provider)
|
||||
{
|
||||
if (is_string($provider) && class_exists($provider)) {
|
||||
$provider = new $provider;
|
||||
}
|
||||
|
||||
if ($provider instanceof ContainerAwareInterface) {
|
||||
$provider->setContainer($this->getContainer());
|
||||
}
|
||||
|
||||
if ($provider instanceof BootableServiceProviderInterface) {
|
||||
$provider->boot();
|
||||
}
|
||||
|
||||
if ($provider instanceof ServiceProviderInterface) {
|
||||
foreach ($provider->provides() as $service) {
|
||||
$this->providers[$service] = $provider;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(
|
||||
'A service provider must be a fully qualified class name or instance ' .
|
||||
'of (\League\Container\ServiceProvider\ServiceProviderInterface)'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provides($service)
|
||||
{
|
||||
return array_key_exists($service, $this->providers);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register($service)
|
||||
{
|
||||
if (! array_key_exists($service, $this->providers)) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('(%s) is not provided by a service provider', $service)
|
||||
);
|
||||
}
|
||||
|
||||
$provider = $this->providers[$service];
|
||||
$signature = get_class($provider);
|
||||
|
||||
if ($provider instanceof SignatureServiceProviderInterface) {
|
||||
$signature = $provider->getSignature();
|
||||
}
|
||||
|
||||
// ensure that the provider hasn't already been invoked by any other service request
|
||||
if (in_array($signature, $this->registered)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$provider->register();
|
||||
|
||||
$this->registered[] = $signature;
|
||||
}
|
||||
}
|
32
vendor/league/container/src/ServiceProvider/ServiceProviderAggregateInterface.php
vendored
Normal file
32
vendor/league/container/src/ServiceProvider/ServiceProviderAggregateInterface.php
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\ServiceProvider;
|
||||
|
||||
use League\Container\ContainerAwareInterface;
|
||||
|
||||
interface ServiceProviderAggregateInterface extends ContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* Add a service provider to the aggregate.
|
||||
*
|
||||
* @param string|\League\Container\ServiceProvider\ServiceProviderInterface $provider
|
||||
* @return $this
|
||||
*/
|
||||
public function add($provider);
|
||||
|
||||
/**
|
||||
* Determines whether a service is provided by the aggregate.
|
||||
*
|
||||
* @param string $service
|
||||
* @return boolean
|
||||
*/
|
||||
public function provides($service);
|
||||
|
||||
/**
|
||||
* Invokes the register method of a provider that provides a specific service.
|
||||
*
|
||||
* @param string $service
|
||||
* @return void
|
||||
*/
|
||||
public function register($service);
|
||||
}
|
26
vendor/league/container/src/ServiceProvider/ServiceProviderInterface.php
vendored
Normal file
26
vendor/league/container/src/ServiceProvider/ServiceProviderInterface.php
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\ServiceProvider;
|
||||
|
||||
use League\Container\ContainerAwareInterface;
|
||||
|
||||
interface ServiceProviderInterface extends ContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
* Returns a boolean if checking whether this provider provides a specific
|
||||
* service or returns an array of provided services if no argument passed.
|
||||
*
|
||||
* @param string $service
|
||||
* @return boolean|array
|
||||
*/
|
||||
public function provides($service = null);
|
||||
|
||||
/**
|
||||
* Use the register method to register items with the container via the
|
||||
* protected $this->container property or the `getContainer` method
|
||||
* from the ContainerAwareTrait.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register();
|
||||
}
|
24
vendor/league/container/src/ServiceProvider/SignatureServiceProviderInterface.php
vendored
Normal file
24
vendor/league/container/src/ServiceProvider/SignatureServiceProviderInterface.php
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace League\Container\ServiceProvider;
|
||||
|
||||
interface SignatureServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Set a custom signature for the service provider. This enables
|
||||
* registering the same service provider multiple times.
|
||||
*
|
||||
* @param string $signature
|
||||
* @return self
|
||||
*/
|
||||
public function withSignature($signature);
|
||||
|
||||
/**
|
||||
* The signature of the service provider uniquely identifies it, so
|
||||
* that we can quickly determine if it has already been registered.
|
||||
* Defaults to get_class($provider).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSignature();
|
||||
}
|
Reference in a new issue