updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -17,6 +17,9 @@ class BoundMethod
* @param array $parameters
* @param string|null $defaultMethod
* @return mixed
*
* @throws \ReflectionException
* @throws \InvalidArgumentException
*/
public static function call($container, $callback, array $parameters = [], $defaultMethod = null)
{
@@ -49,7 +52,7 @@ class BoundMethod
// 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
$method = count($segments) === 2
? $segments[1] : $defaultMethod;
if (is_null($method)) {
@@ -107,6 +110,8 @@ class BoundMethod
* @param callable|string $callback
* @param array $parameters
* @return array
*
* @throws \ReflectionException
*/
protected static function getMethodDependencies($container, $callback, array $parameters = [])
{
@@ -122,8 +127,10 @@ class BoundMethod
/**
* Get the proper reflection instance for the given callback.
*
* @param callable|string $callback
* @param callable|string $callback
* @return \ReflectionFunctionAbstract
*
* @throws \ReflectionException
*/
protected static function getCallReflector($callback)
{
@@ -143,7 +150,7 @@ class BoundMethod
* @param \ReflectionParameter $parameter
* @param array $parameters
* @param array $dependencies
* @return mixed
* @return void
*/
protected static function addDependencyForCallParameter($container, $parameter,
array &$parameters, &$dependencies)

View File

@@ -3,10 +3,12 @@
namespace Illuminate\Container;
use Closure;
use Exception;
use ArrayAccess;
use LogicException;
use ReflectionClass;
use ReflectionParameter;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Container\Container as ContainerContract;
@@ -22,124 +24,130 @@ class Container implements ArrayAccess, ContainerContract
/**
* An array of the types that have been resolved.
*
* @var array
* @var bool[]
*/
protected $resolved = [];
/**
* The container's bindings.
*
* @var array
* @var array[]
*/
protected $bindings = [];
/**
* The container's method bindings.
*
* @var array
* @var \Closure[]
*/
protected $methodBindings = [];
/**
* The container's shared instances.
*
* @var array
* @var object[]
*/
protected $instances = [];
/**
* The registered type aliases.
*
* @var array
* @var string[]
*/
protected $aliases = [];
/**
* The registered aliases keyed by the abstract name.
*
* @var array
* @var array[]
*/
protected $abstractAliases = [];
/**
* The extension closures for services.
*
* @var array
* @var array[]
*/
protected $extenders = [];
/**
* All of the registered tags.
*
* @var array
* @var array[]
*/
protected $tags = [];
/**
* The stack of concretions currently being built.
*
* @var array
* @var array[]
*/
protected $buildStack = [];
/**
* The parameter override stack.
*
* @var array
* @var array[]
*/
protected $with = [];
/**
* The contextual binding map.
*
* @var array
* @var array[]
*/
public $contextual = [];
/**
* All of the registered rebound callbacks.
*
* @var array
* @var array[]
*/
protected $reboundCallbacks = [];
/**
* All of the global resolving callbacks.
*
* @var array
* @var \Closure[]
*/
protected $globalResolvingCallbacks = [];
/**
* All of the global after resolving callbacks.
*
* @var array
* @var \Closure[]
*/
protected $globalAfterResolvingCallbacks = [];
/**
* All of the resolving callbacks by class type.
*
* @var array
* @var array[]
*/
protected $resolvingCallbacks = [];
/**
* All of the after resolving callbacks by class type.
*
* @var array
* @var array[]
*/
protected $afterResolvingCallbacks = [];
/**
* Define a contextual binding.
*
* @param string $concrete
* @param array|string $concrete
* @return \Illuminate\Contracts\Container\ContextualBindingBuilder
*/
public function when($concrete)
{
return new ContextualBindingBuilder($this, $this->getAlias($concrete));
$aliases = [];
foreach (Arr::wrap($concrete) as $c) {
$aliases[] = $this->getAlias($c);
}
return new ContextualBindingBuilder($this, $aliases);
}
/**
@@ -188,7 +196,7 @@ class Container implements ArrayAccess, ContainerContract
public function isShared($abstract)
{
return isset($this->instances[$abstract]) ||
(isset($this->bindings[$abstract]['shared']) &&
(isset($this->bindings[$abstract]['shared']) &&
$this->bindings[$abstract]['shared'] === true);
}
@@ -213,11 +221,11 @@ class Container implements ArrayAccess, ContainerContract
*/
public function bind($abstract, $concrete = null, $shared = false)
{
$this->dropStaleInstances($abstract);
// If no concrete type was given, we will simply set the concrete type to the
// abstract type. After that, the concrete type to be registered as shared
// without being forced to state their classes in both of the parameters.
$this->dropStaleInstances($abstract);
if (is_null($concrete)) {
$concrete = $abstract;
}
@@ -253,7 +261,9 @@ class Container implements ArrayAccess, ContainerContract
return $container->build($concrete);
}
return $container->make($concrete, $parameters);
return $container->resolve(
$concrete, $parameters, $raiseEvents = false
);
};
}
@@ -447,19 +457,19 @@ class Container implements ArrayAccess, ContainerContract
* Resolve all of the bindings for a given tag.
*
* @param string $tag
* @return array
* @return iterable
*/
public function tagged($tag)
{
$results = [];
if (isset($this->tags[$tag])) {
foreach ($this->tags[$tag] as $abstract) {
$results[] = $this->make($abstract);
}
if (! isset($this->tags[$tag])) {
return [];
}
return $results;
return new RewindableGenerator(function () use ($tag) {
foreach ($this->tags[$tag] as $abstract) {
yield $this->make($abstract);
}
}, count($this->tags[$tag]));
}
/**
@@ -468,9 +478,15 @@ class Container implements ArrayAccess, ContainerContract
* @param string $abstract
* @param string $alias
* @return void
*
* @throws \LogicException
*/
public function alias($abstract, $alias)
{
if ($alias === $abstract) {
throw new LogicException("[{$abstract}] is aliased to itself.");
}
$this->aliases[$alias] = $abstract;
$this->abstractAliases[$abstract][] = $alias;
@@ -530,11 +546,7 @@ class Container implements ArrayAccess, ContainerContract
*/
protected function getReboundCallbacks($abstract)
{
if (isset($this->reboundCallbacks[$abstract])) {
return $this->reboundCallbacks[$abstract];
}
return [];
return $this->reboundCallbacks[$abstract] ?? [];
}
/**
@@ -595,6 +607,8 @@ class Container implements ArrayAccess, ContainerContract
* @param string $abstract
* @param array $parameters
* @return mixed
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function make($abstract, array $parameters = [])
{
@@ -606,11 +620,15 @@ class Container implements ArrayAccess, ContainerContract
*/
public function get($id)
{
if ($this->has($id)) {
try {
return $this->resolve($id);
}
} catch (Exception $e) {
if ($this->has($id)) {
throw $e;
}
throw new EntryNotFoundException;
throw new EntryNotFoundException($id);
}
}
/**
@@ -618,9 +636,12 @@ class Container implements ArrayAccess, ContainerContract
*
* @param string $abstract
* @param array $parameters
* @param bool $raiseEvents
* @return mixed
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
protected function resolve($abstract, $parameters = [])
protected function resolve($abstract, $parameters = [], $raiseEvents = true)
{
$abstract = $this->getAlias($abstract);
@@ -662,7 +683,9 @@ class Container implements ArrayAccess, ContainerContract
$this->instances[$abstract] = $object;
}
$this->fireResolvingCallbacks($abstract, $object);
if ($raiseEvents) {
$this->fireResolvingCallbacks($abstract, $object);
}
// Before returning, we will also set the resolved flag to "true" and pop off
// the parameter overrides for this build. After those two things are done
@@ -700,7 +723,7 @@ class Container implements ArrayAccess, ContainerContract
* Get the contextual concrete binding for the given abstract.
*
* @param string $abstract
* @return string|null
* @return \Closure|string|null
*/
protected function getContextualConcrete($abstract)
{
@@ -726,13 +749,11 @@ class Container implements ArrayAccess, ContainerContract
* Find the concrete binding for the given abstract in the contextual binding array.
*
* @param string $abstract
* @return string|null
* @return \Closure|string|null
*/
protected function findInContextualBindings($abstract)
{
if (isset($this->contextual[end($this->buildStack)][$abstract])) {
return $this->contextual[end($this->buildStack)][$abstract];
}
return $this->contextual[end($this->buildStack)][$abstract] ?? null;
}
/**
@@ -767,7 +788,7 @@ class Container implements ArrayAccess, ContainerContract
$reflector = new ReflectionClass($concrete);
// If the type is not instantiable, the developer is attempting to resolve
// an abstract type such as an Interface of Abstract Class and there is
// an abstract type such as an Interface or Abstract Class and there is
// no binding registered for the abstractions so we need to bail out.
if (! $reflector->isInstantiable()) {
return $this->notInstantiable($concrete);
@@ -791,9 +812,13 @@ class Container implements ArrayAccess, ContainerContract
// Once we have all the constructor's parameters we can create each of the
// dependency instances and then use the reflection instances to make a
// new instance of this class, injecting the created dependencies in.
$instances = $this->resolveDependencies(
$dependencies
);
try {
$instances = $this->resolveDependencies($dependencies);
} catch (BindingResolutionException $e) {
array_pop($this->buildStack);
throw $e;
}
array_pop($this->buildStack);
@@ -805,6 +830,8 @@ class Container implements ArrayAccess, ContainerContract
*
* @param array $dependencies
* @return array
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
protected function resolveDependencies(array $dependencies)
{
@@ -1073,8 +1100,6 @@ class Container implements ArrayAccess, ContainerContract
*
* @param string $abstract
* @return string
*
* @throws \LogicException
*/
public function getAlias($abstract)
{
@@ -1082,10 +1107,6 @@ class Container implements ArrayAccess, ContainerContract
return $abstract;
}
if ($this->aliases[$abstract] === $abstract) {
throw new LogicException("[{$abstract}] is aliased to itself.");
}
return $this->getAlias($this->aliases[$abstract]);
}
@@ -1099,11 +1120,7 @@ class Container implements ArrayAccess, ContainerContract
{
$abstract = $this->getAlias($abstract);
if (isset($this->extenders[$abstract])) {
return $this->extenders[$abstract];
}
return [];
return $this->extenders[$abstract] ?? [];
}
/**
@@ -1164,7 +1181,7 @@ class Container implements ArrayAccess, ContainerContract
}
/**
* Set the globally available instance of the container.
* Get the globally available instance of the container.
*
* @return static
*/

View File

@@ -2,6 +2,8 @@
namespace Illuminate\Container;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Container\ContextualBindingBuilder as ContextualBindingBuilderContract;
class ContextualBindingBuilder implements ContextualBindingBuilderContract
@@ -9,14 +11,14 @@ class ContextualBindingBuilder implements ContextualBindingBuilderContract
/**
* The underlying container instance.
*
* @var \Illuminate\Container\Container
* @var \Illuminate\Contracts\Container\Container
*/
protected $container;
/**
* The concrete instance.
*
* @var string
* @var string|array
*/
protected $concrete;
@@ -30,8 +32,8 @@ class ContextualBindingBuilder implements ContextualBindingBuilderContract
/**
* Create a new contextual binding builder.
*
* @param \Illuminate\Container\Container $container
* @param string $concrete
* @param \Illuminate\Contracts\Container\Container $container
* @param string|array $concrete
* @return void
*/
public function __construct(Container $container, $concrete)
@@ -61,8 +63,8 @@ class ContextualBindingBuilder implements ContextualBindingBuilderContract
*/
public function give($implementation)
{
$this->container->addContextualBinding(
$this->concrete, $this->needs, $implementation
);
foreach (Arr::wrap($this->concrete) as $concrete) {
$this->container->addContextualBinding($concrete, $this->needs, $implementation);
}
}
}

View File

@@ -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.

View File

@@ -0,0 +1,60 @@
<?php
namespace Illuminate\Container;
use Countable;
use IteratorAggregate;
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
* @return void
*/
public function __construct(callable $generator, $count)
{
$this->count = $count;
$this->generator = $generator;
}
/**
* Get an iterator from the generator.
*
* @return mixed
*/
public function getIterator()
{
return ($this->generator)();
}
/**
* Get the total number of tagged services.
*
* @return int
*/
public function count()
{
if (is_callable($count = $this->count)) {
$this->count = $count();
}
return $this->count;
}
}

View File

@@ -15,8 +15,9 @@
],
"require": {
"php": "^7.1.3",
"illuminate/contracts": "5.6.*",
"psr/container": "~1.0"
"illuminate/contracts": "5.8.*",
"illuminate/support": "5.8.*",
"psr/container": "^1.0"
},
"autoload": {
"psr-4": {
@@ -25,7 +26,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.6-dev"
"dev-master": "5.8-dev"
}
},
"config": {