v1.0.0 initial release
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class Auth implements ContextualAttribute
|
||||
{
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public function __construct(public ?string $guard = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the authentication guard.
|
||||
*
|
||||
* @param self $attribute
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return \Illuminate\Contracts\Auth\Guard|\Illuminate\Contracts\Auth\StatefulGuard
|
||||
*/
|
||||
public static function resolve(self $attribute, Container $container)
|
||||
{
|
||||
return $container->make('auth')->guard($attribute->guard);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class Authenticated implements ContextualAttribute
|
||||
{
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public function __construct(public ?string $guard = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the currently authenticated user.
|
||||
*
|
||||
* @param self $attribute
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
||||
*/
|
||||
public static function resolve(self $attribute, Container $container)
|
||||
{
|
||||
return call_user_func($container->make('auth')->userResolver(), $attribute->guard);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class Cache implements ContextualAttribute
|
||||
{
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public function __construct(public ?string $store = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the cache store.
|
||||
*
|
||||
* @param self $attribute
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
public static function resolve(self $attribute, Container $container)
|
||||
{
|
||||
return $container->make('cache')->store($attribute->store);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class Config implements ContextualAttribute
|
||||
{
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public function __construct(public string $key, public mixed $default = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the configuration value.
|
||||
*
|
||||
* @param self $attribute
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return mixed
|
||||
*/
|
||||
public static function resolve(self $attribute, Container $container)
|
||||
{
|
||||
return $container->make('config')->get($attribute->key, $attribute->default);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
use Illuminate\Log\Context\Repository;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class Context implements ContextualAttribute
|
||||
{
|
||||
/**
|
||||
* Create a new attribute instance.
|
||||
*/
|
||||
public function __construct(public string $key, public mixed $default = null, public bool $hidden = false)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the context value.
|
||||
*
|
||||
* @param self $attribute
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return mixed
|
||||
*/
|
||||
public static function resolve(self $attribute, Container $container): mixed
|
||||
{
|
||||
$repository = $container->make(Repository::class);
|
||||
|
||||
return match ($attribute->hidden) {
|
||||
true => $repository->getHidden($attribute->key, $attribute->default),
|
||||
false => $repository->get($attribute->key, $attribute->default),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class CurrentUser extends Authenticated
|
||||
{
|
||||
//
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class DB extends Database
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class Database implements ContextualAttribute
|
||||
{
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public function __construct(public ?string $connection = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the database connection.
|
||||
*
|
||||
* @param self $attribute
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public static function resolve(self $attribute, Container $container)
|
||||
{
|
||||
return $container->make('db')->connection($attribute->connection);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class Give implements ContextualAttribute
|
||||
{
|
||||
/**
|
||||
* Provide a concrete class implementation for dependency injection.
|
||||
*
|
||||
* @template T
|
||||
*
|
||||
* @param class-string<T> $class
|
||||
* @param array|null $params
|
||||
*/
|
||||
public function __construct(
|
||||
public string $class,
|
||||
public array $params = []
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the dependency.
|
||||
*
|
||||
* @param self $attribute
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return mixed
|
||||
*/
|
||||
public static function resolve(self $attribute, Container $container): mixed
|
||||
{
|
||||
return $container->make($attribute->class, $attribute->params);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class Log implements ContextualAttribute
|
||||
{
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public function __construct(public ?string $channel = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the log channel.
|
||||
*
|
||||
* @param self $attribute
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return \Psr\Log\LoggerInterface
|
||||
*/
|
||||
public static function resolve(self $attribute, Container $container)
|
||||
{
|
||||
return $container->make('log')->channel($attribute->channel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class RouteParameter implements ContextualAttribute
|
||||
{
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public function __construct(public string $parameter)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the route parameter.
|
||||
*
|
||||
* @param self $attribute
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return mixed
|
||||
*/
|
||||
public static function resolve(self $attribute, Container $container)
|
||||
{
|
||||
return $container->make('request')->route($attribute->parameter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
class Storage implements ContextualAttribute
|
||||
{
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public function __construct(public ?string $disk = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the storage disk.
|
||||
*
|
||||
* @param self $attribute
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
public static function resolve(self $attribute, Container $container)
|
||||
{
|
||||
return $container->make('filesystem')->disk($attribute->disk);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Illuminate\Container\Attributes;
|
||||
|
||||
use Attribute;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PARAMETER)]
|
||||
final class Tag implements ContextualAttribute
|
||||
{
|
||||
public function __construct(
|
||||
public string $tag,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the tag.
|
||||
*
|
||||
* @param self $attribute
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return mixed
|
||||
*/
|
||||
public static function resolve(self $attribute, Container $container)
|
||||
{
|
||||
return $container->tagged($attribute->tag);
|
||||
}
|
||||
}
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use InvalidArgumentException;
|
||||
use ReflectionFunction;
|
||||
use ReflectionMethod;
|
||||
|
||||
class BoundMethod
|
||||
{
|
||||
/**
|
||||
* Call the given Closure / class@method and inject its dependencies.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @param callable|string $callback
|
||||
* @param array $parameters
|
||||
* @param string|null $defaultMethod
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function call($container, $callback, array $parameters = [], $defaultMethod = null)
|
||||
{
|
||||
if (is_string($callback) && ! $defaultMethod && method_exists($callback, '__invoke')) {
|
||||
$defaultMethod = '__invoke';
|
||||
}
|
||||
|
||||
if (static::isCallableWithAtSign($callback) || $defaultMethod) {
|
||||
return static::callClass($container, $callback, $parameters, $defaultMethod);
|
||||
}
|
||||
|
||||
return static::callBoundMethod($container, $callback, function () use ($container, $callback, $parameters) {
|
||||
return $callback(...array_values(static::getMethodDependencies($container, $callback, $parameters)));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a string reference to a class using Class@method syntax.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @param string $target
|
||||
* @param array $parameters
|
||||
* @param string|null $defaultMethod
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected static function callClass($container, $target, array $parameters = [], $defaultMethod = null)
|
||||
{
|
||||
$segments = explode('@', $target);
|
||||
|
||||
// We will assume an @ sign is used to delimit the class name from the method
|
||||
// name. We will split on this @ sign and then build a callable array that
|
||||
// we can pass right back into the "call" method for dependency binding.
|
||||
$method = count($segments) === 2
|
||||
? $segments[1]
|
||||
: $defaultMethod;
|
||||
|
||||
if (is_null($method)) {
|
||||
throw new InvalidArgumentException('Method not provided.');
|
||||
}
|
||||
|
||||
return static::call(
|
||||
$container,
|
||||
[$container->make($segments[0]), $method],
|
||||
$parameters
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a method that has been bound to the container.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @param callable $callback
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function callBoundMethod($container, $callback, $default)
|
||||
{
|
||||
if (! is_array($callback)) {
|
||||
return Util::unwrapIfClosure($default);
|
||||
}
|
||||
|
||||
// Here we need to turn the array callable into a Class@method string we can use to
|
||||
// examine the container and see if there are any method bindings for this given
|
||||
// method. If there are, we can call this method binding callback immediately.
|
||||
$method = static::normalizeMethod($callback);
|
||||
|
||||
if ($container->hasMethodBinding($method)) {
|
||||
return $container->callMethodBinding($method, $callback[0]);
|
||||
}
|
||||
|
||||
return Util::unwrapIfClosure($default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize the given callback into a Class@method string.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return string
|
||||
*/
|
||||
protected static function normalizeMethod($callback)
|
||||
{
|
||||
$class = is_string($callback[0]) ? $callback[0] : get_class($callback[0]);
|
||||
|
||||
return "{$class}@{$callback[1]}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all dependencies for a given method.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @param callable|string $callback
|
||||
* @param array $parameters
|
||||
* @return array
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected static function getMethodDependencies($container, $callback, array $parameters = [])
|
||||
{
|
||||
$dependencies = [];
|
||||
|
||||
foreach (static::getCallReflector($callback)->getParameters() as $parameter) {
|
||||
static::addDependencyForCallParameter($container, $parameter, $parameters, $dependencies);
|
||||
}
|
||||
|
||||
return array_merge($dependencies, array_values($parameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the proper reflection instance for the given callback.
|
||||
*
|
||||
* @param callable|string $callback
|
||||
* @return \ReflectionFunctionAbstract
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected static function getCallReflector($callback)
|
||||
{
|
||||
if (is_string($callback) && str_contains($callback, '::')) {
|
||||
$callback = explode('::', $callback);
|
||||
} elseif (is_object($callback) && ! $callback instanceof Closure) {
|
||||
$callback = [$callback, '__invoke'];
|
||||
}
|
||||
|
||||
return is_array($callback)
|
||||
? new ReflectionMethod($callback[0], $callback[1])
|
||||
: new ReflectionFunction($callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dependency for the given call parameter.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @param \ReflectionParameter $parameter
|
||||
* @param array $parameters
|
||||
* @param array $dependencies
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
protected static function addDependencyForCallParameter(
|
||||
$container,
|
||||
$parameter,
|
||||
array &$parameters,
|
||||
&$dependencies
|
||||
) {
|
||||
$pendingDependencies = [];
|
||||
|
||||
if (array_key_exists($paramName = $parameter->getName(), $parameters)) {
|
||||
$pendingDependencies[] = $parameters[$paramName];
|
||||
|
||||
unset($parameters[$paramName]);
|
||||
} elseif ($attribute = Util::getContextualAttributeFromDependency($parameter)) {
|
||||
$pendingDependencies[] = $container->resolveFromAttribute($attribute);
|
||||
} elseif (! is_null($className = Util::getParameterClassName($parameter))) {
|
||||
if (array_key_exists($className, $parameters)) {
|
||||
$pendingDependencies[] = $parameters[$className];
|
||||
|
||||
unset($parameters[$className]);
|
||||
} elseif ($parameter->isVariadic()) {
|
||||
$variadicDependencies = $container->make($className);
|
||||
|
||||
$pendingDependencies = array_merge($pendingDependencies, is_array($variadicDependencies)
|
||||
? $variadicDependencies
|
||||
: [$variadicDependencies]);
|
||||
} else {
|
||||
$pendingDependencies[] = $container->make($className);
|
||||
}
|
||||
} elseif ($parameter->isDefaultValueAvailable()) {
|
||||
$pendingDependencies[] = $parameter->getDefaultValue();
|
||||
} elseif (! $parameter->isOptional() && ! array_key_exists($paramName, $parameters)) {
|
||||
$message = "Unable to resolve dependency [{$parameter}] in class {$parameter->getDeclaringClass()->getName()}";
|
||||
|
||||
throw new BindingResolutionException($message);
|
||||
}
|
||||
|
||||
foreach ($pendingDependencies as $dependency) {
|
||||
$container->fireAfterResolvingAttributeCallbacks($parameter->getAttributes(), $dependency);
|
||||
}
|
||||
|
||||
$dependencies = array_merge($dependencies, $pendingDependencies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given string is in Class@method syntax.
|
||||
*
|
||||
* @param mixed $callback
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isCallableWithAtSign($callback)
|
||||
{
|
||||
return is_string($callback) && str_contains($callback, '@');
|
||||
}
|
||||
}
|
||||
+1701
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container;
|
||||
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Container\ContextualBindingBuilder as ContextualBindingBuilderContract;
|
||||
|
||||
class ContextualBindingBuilder implements ContextualBindingBuilderContract
|
||||
{
|
||||
/**
|
||||
* The underlying container instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Container\Container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* The concrete instance.
|
||||
*
|
||||
* @var string|array
|
||||
*/
|
||||
protected $concrete;
|
||||
|
||||
/**
|
||||
* The abstract target.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $needs;
|
||||
|
||||
/**
|
||||
* Create a new contextual binding builder.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @param string|array $concrete
|
||||
*/
|
||||
public function __construct(Container $container, $concrete)
|
||||
{
|
||||
$this->concrete = $concrete;
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the abstract target that depends on the context.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @return $this
|
||||
*/
|
||||
public function needs($abstract)
|
||||
{
|
||||
$this->needs = $abstract;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the implementation for the contextual binding.
|
||||
*
|
||||
* @param \Closure|string|array $implementation
|
||||
* @return void
|
||||
*/
|
||||
public function give($implementation)
|
||||
{
|
||||
foreach (Util::arrayWrap($this->concrete) as $concrete) {
|
||||
$this->container->addContextualBinding($concrete, $this->needs, $implementation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define tagged services to be used as the implementation for the contextual binding.
|
||||
*
|
||||
* @param string $tag
|
||||
* @return void
|
||||
*/
|
||||
public function giveTagged($tag)
|
||||
{
|
||||
$this->give(function ($container) use ($tag) {
|
||||
$taggedServices = $container->tagged($tag);
|
||||
|
||||
return is_array($taggedServices) ? $taggedServices : iterator_to_array($taggedServices);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the configuration item to bind as a primitive.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return void
|
||||
*/
|
||||
public function giveConfig($key, $default = null)
|
||||
{
|
||||
$this->give(fn ($container) => $container->get('config')->get($key, $default));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container;
|
||||
|
||||
use Exception;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class EntryNotFoundException extends Exception implements NotFoundExceptionInterface
|
||||
{
|
||||
//
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Taylor Otwell
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container;
|
||||
|
||||
use Countable;
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
class RewindableGenerator implements Countable, IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* The generator callback.
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
* The number of tagged services.
|
||||
*
|
||||
* @var callable|int
|
||||
*/
|
||||
protected $count;
|
||||
|
||||
/**
|
||||
* Create a new generator instance.
|
||||
*
|
||||
* @param callable $generator
|
||||
* @param callable|int $count
|
||||
*/
|
||||
public function __construct(callable $generator, $count)
|
||||
{
|
||||
$this->count = $count;
|
||||
$this->generator = $generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator from the generator.
|
||||
*
|
||||
* @return \Traversable
|
||||
*/
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return ($this->generator)();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of tagged services.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
if (is_callable($count = $this->count)) {
|
||||
$this->count = $count();
|
||||
}
|
||||
|
||||
return $this->count;
|
||||
}
|
||||
}
|
||||
Vendored
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Container;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Container\ContextualAttribute;
|
||||
use ReflectionAttribute;
|
||||
use ReflectionNamedType;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class Util
|
||||
{
|
||||
/**
|
||||
* If the given value is not an array and not null, wrap it in one.
|
||||
*
|
||||
* From Arr::wrap() in Illuminate\Support.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
public static function arrayWrap($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return is_array($value) ? $value : [$value];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default value of the given value.
|
||||
*
|
||||
* From global value() helper in Illuminate\Support.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed ...$args
|
||||
* @return mixed
|
||||
*/
|
||||
public static function unwrapIfClosure($value, ...$args)
|
||||
{
|
||||
return $value instanceof Closure ? $value(...$args) : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name of the given parameter's type, if possible.
|
||||
*
|
||||
* From Reflector::getParameterClassName() in Illuminate\Support.
|
||||
*
|
||||
* @param \ReflectionParameter $parameter
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getParameterClassName($parameter)
|
||||
{
|
||||
$type = $parameter->getType();
|
||||
|
||||
if (! $type instanceof ReflectionNamedType || $type->isBuiltin()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$name = $type->getName();
|
||||
|
||||
if (! is_null($class = $parameter->getDeclaringClass())) {
|
||||
if ($name === 'self') {
|
||||
return $class->getName();
|
||||
}
|
||||
|
||||
if ($name === 'parent' && $parent = $class->getParentClass()) {
|
||||
return $parent->getName();
|
||||
}
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a contextual attribute from a dependency.
|
||||
*
|
||||
* @param \ReflectionParameter $dependency
|
||||
* @return \ReflectionAttribute|null
|
||||
*/
|
||||
public static function getContextualAttributeFromDependency($dependency)
|
||||
{
|
||||
return $dependency->getAttributes(ContextualAttribute::class, ReflectionAttribute::IS_INSTANCEOF)[0] ?? null;
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "illuminate/container",
|
||||
"description": "The Illuminate Container package.",
|
||||
"license": "MIT",
|
||||
"homepage": "https://laravel.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.2",
|
||||
"illuminate/contracts": "^12.0",
|
||||
"psr/container": "^1.1.1|^2.0.1"
|
||||
},
|
||||
"provide": {
|
||||
"psr/container-implementation": "1.1|2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Container\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "12.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
Reference in New Issue
Block a user