diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index 7e54581..0000000
--- a/.gitattributes
+++ /dev/null
@@ -1,2 +0,0 @@
-/.github export-ignore
-.gitattributes export-ignore
diff --git a/.github/workflows/close-pull-request.yml b/.github/workflows/close-pull-request.yml
deleted file mode 100644
index 6cbfcf0..0000000
--- a/.github/workflows/close-pull-request.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-name: Close Pull Request
-
-on:
- pull_request_target:
- types: [opened]
-
-jobs:
- run:
- runs-on: ubuntu-24.04
- steps:
- - uses: superbrothers/close-pull-request@v3
- with:
- comment: "Thank you for your pull request. However, you have submitted this PR on the Illuminate organization which is a read-only sub split of `laravel/framework`. Please submit your PR on the https://github.com/laravel/framework repository.
Thanks!"
diff --git a/Attributes/Auth.php b/Attributes/Auth.php
deleted file mode 100644
index 4cf0c1a..0000000
--- a/Attributes/Auth.php
+++ /dev/null
@@ -1,30 +0,0 @@
-make('auth')->guard($attribute->guard);
- }
-}
diff --git a/Attributes/Authenticated.php b/Attributes/Authenticated.php
deleted file mode 100644
index ffbba45..0000000
--- a/Attributes/Authenticated.php
+++ /dev/null
@@ -1,30 +0,0 @@
-make('auth')->userResolver(), $attribute->guard);
- }
-}
diff --git a/Attributes/Bind.php b/Attributes/Bind.php
deleted file mode 100644
index 3e74b94..0000000
--- a/Attributes/Bind.php
+++ /dev/null
@@ -1,53 +0,0 @@
-
- */
- public array $environments = [];
-
- /**
- * Create a new attribute instance.
- *
- * @param class-string $concrete
- * @param non-empty-array|non-empty-string|\UnitEnum $environments
- *
- * @throws \InvalidArgumentException
- */
- public function __construct(
- string $concrete,
- string|array|UnitEnum $environments = ['*'],
- ) {
- $environments = array_filter(is_array($environments) ? $environments : [$environments]);
-
- if ($environments === []) {
- throw new InvalidArgumentException('The environment property must be set and cannot be empty.');
- }
-
- $this->concrete = $concrete;
-
- $this->environments = array_map(
- fn ($environment) => enum_value($environment),
- $environments,
- );
- }
-}
diff --git a/Attributes/Cache.php b/Attributes/Cache.php
deleted file mode 100644
index 2b7b1f7..0000000
--- a/Attributes/Cache.php
+++ /dev/null
@@ -1,30 +0,0 @@
-make('cache')->store($attribute->store);
- }
-}
diff --git a/Attributes/Config.php b/Attributes/Config.php
deleted file mode 100644
index 0133708..0000000
--- a/Attributes/Config.php
+++ /dev/null
@@ -1,30 +0,0 @@
-make('config')->get($attribute->key, $attribute->default);
- }
-}
diff --git a/Attributes/Context.php b/Attributes/Context.php
deleted file mode 100644
index 1c85807..0000000
--- a/Attributes/Context.php
+++ /dev/null
@@ -1,36 +0,0 @@
-make(Repository::class);
-
- return match ($attribute->hidden) {
- true => $repository->getHidden($attribute->key, $attribute->default),
- false => $repository->get($attribute->key, $attribute->default),
- };
- }
-}
diff --git a/Attributes/CurrentUser.php b/Attributes/CurrentUser.php
deleted file mode 100644
index 7c13b4e..0000000
--- a/Attributes/CurrentUser.php
+++ /dev/null
@@ -1,11 +0,0 @@
-make('db')->connection($attribute->connection);
- }
-}
diff --git a/Attributes/Give.php b/Attributes/Give.php
deleted file mode 100644
index 35891a2..0000000
--- a/Attributes/Give.php
+++ /dev/null
@@ -1,35 +0,0 @@
-make($attribute->class, $attribute->params);
- }
-}
diff --git a/Attributes/Log.php b/Attributes/Log.php
deleted file mode 100644
index 07673e7..0000000
--- a/Attributes/Log.php
+++ /dev/null
@@ -1,30 +0,0 @@
-make('log')->channel($attribute->channel);
- }
-}
diff --git a/Attributes/RouteParameter.php b/Attributes/RouteParameter.php
deleted file mode 100644
index 32afced..0000000
--- a/Attributes/RouteParameter.php
+++ /dev/null
@@ -1,30 +0,0 @@
-make('request')->route($attribute->parameter);
- }
-}
diff --git a/Attributes/Scoped.php b/Attributes/Scoped.php
deleted file mode 100644
index 1cf04e0..0000000
--- a/Attributes/Scoped.php
+++ /dev/null
@@ -1,10 +0,0 @@
-make('filesystem')->disk($attribute->disk);
- }
-}
diff --git a/Attributes/Tag.php b/Attributes/Tag.php
deleted file mode 100644
index 944fcd9..0000000
--- a/Attributes/Tag.php
+++ /dev/null
@@ -1,30 +0,0 @@
-tagged($attribute->tag);
- }
-}
diff --git a/BoundMethod.php b/BoundMethod.php
index 6bedef0..0dfd6fd 100644
--- a/BoundMethod.php
+++ b/BoundMethod.php
@@ -3,10 +3,9 @@
namespace Illuminate\Container;
use Closure;
-use Illuminate\Contracts\Container\BindingResolutionException;
-use InvalidArgumentException;
-use ReflectionFunction;
use ReflectionMethod;
+use ReflectionFunction;
+use InvalidArgumentException;
class BoundMethod
{
@@ -18,22 +17,17 @@ 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)
{
- 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)));
+ return call_user_func_array(
+ $callback, static::getMethodDependencies($container, $callback, $parameters)
+ );
});
}
@@ -55,18 +49,15 @@ protected static function callClass($container, $target, array $parameters = [],
// 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;
+ $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
+ $container, [$container->make($segments[0]), $method], $parameters
);
}
@@ -81,7 +72,7 @@ protected static function callClass($container, $target, array $parameters = [],
protected static function callBoundMethod($container, $callback, $default)
{
if (! is_array($callback)) {
- return Util::unwrapIfClosure($default);
+ return $default instanceof Closure ? $default() : $default;
}
// Here we need to turn the array callable into a Class@method string we can use to
@@ -93,7 +84,7 @@ protected static function callBoundMethod($container, $callback, $default)
return $container->callMethodBinding($method, $callback[0]);
}
- return Util::unwrapIfClosure($default);
+ return $default instanceof Closure ? $default() : $default;
}
/**
@@ -116,8 +107,6 @@ protected static function normalizeMethod($callback)
* @param callable|string $callback
* @param array $parameters
* @return array
- *
- * @throws \ReflectionException
*/
protected static function getMethodDependencies($container, $callback, array $parameters = [])
{
@@ -127,7 +116,7 @@ protected static function getMethodDependencies($container, $callback, array $pa
static::addDependencyForCallParameter($container, $parameter, $parameters, $dependencies);
}
- return array_merge($dependencies, array_values($parameters));
+ return array_merge($dependencies, $parameters);
}
/**
@@ -135,20 +124,16 @@ protected static function getMethodDependencies($container, $callback, array $pa
*
* @param callable|string $callback
* @return \ReflectionFunctionAbstract
- *
- * @throws \ReflectionException
*/
protected static function getCallReflector($callback)
{
- if (is_string($callback) && str_contains($callback, '::')) {
+ if (is_string($callback) && strpos($callback, '::') !== false) {
$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);
+ ? new ReflectionMethod($callback[0], $callback[1])
+ : new ReflectionFunction($callback);
}
/**
@@ -158,53 +143,20 @@ protected static function getCallReflector($callback)
* @param \ReflectionParameter $parameter
* @param array $parameters
* @param array $dependencies
- * @return void
- *
- * @throws \Illuminate\Contracts\Container\BindingResolutionException
+ * @return mixed
*/
- 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]);
- } elseif ($parameter->isDefaultValueAvailable() && ! $container->bound($className)) {
- $pendingDependencies[] = $parameter->getDefaultValue();
- } 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);
- }
+ protected static function addDependencyForCallParameter($container, $parameter,
+ array &$parameters, &$dependencies)
+ {
+ if (array_key_exists($parameter->name, $parameters)) {
+ $dependencies[] = $parameters[$parameter->name];
- foreach ($pendingDependencies as $dependency) {
- $container->fireAfterResolvingAttributeCallbacks($parameter->getAttributes(), $dependency);
+ unset($parameters[$parameter->name]);
+ } elseif ($parameter->getClass()) {
+ $dependencies[] = $container->make($parameter->getClass()->name);
+ } elseif ($parameter->isDefaultValueAvailable()) {
+ $dependencies[] = $parameter->getDefaultValue();
}
-
- $dependencies = array_merge($dependencies, $pendingDependencies);
}
/**
@@ -215,6 +167,6 @@ protected static function addDependencyForCallParameter(
*/
protected static function isCallableWithAtSign($callback)
{
- return is_string($callback) && str_contains($callback, '@');
+ return is_string($callback) && strpos($callback, '@') !== false;
}
}
diff --git a/Container.php b/Container.php
index 0134178..a4b479a 100755
--- a/Container.php
+++ b/Container.php
@@ -2,30 +2,16 @@
namespace Illuminate\Container;
-use ArrayAccess;
use Closure;
-use Exception;
-use Illuminate\Container\Attributes\Bind;
-use Illuminate\Container\Attributes\Scoped;
-use Illuminate\Container\Attributes\Singleton;
-use Illuminate\Contracts\Container\BindingResolutionException;
-use Illuminate\Contracts\Container\CircularDependencyException;
-use Illuminate\Contracts\Container\Container as ContainerContract;
-use Illuminate\Contracts\Container\ContextualAttribute;
-use Illuminate\Contracts\Container\SelfBuilding;
-use Illuminate\Support\Traits\ReflectsClosures;
+use ArrayAccess;
use LogicException;
-use ReflectionAttribute;
use ReflectionClass;
-use ReflectionException;
-use ReflectionFunction;
use ReflectionParameter;
-use TypeError;
+use Illuminate\Contracts\Container\BindingResolutionException;
+use Illuminate\Contracts\Container\Container as ContainerContract;
class Container implements ArrayAccess, ContainerContract
{
- use ReflectsClosures;
-
/**
* The current globally available container (if any).
*
@@ -36,196 +22,124 @@ class Container implements ArrayAccess, ContainerContract
/**
* An array of the types that have been resolved.
*
- * @var bool[]
+ * @var array
*/
protected $resolved = [];
/**
* The container's bindings.
*
- * @var array[]
+ * @var array
*/
protected $bindings = [];
/**
* The container's method bindings.
*
- * @var \Closure[]
+ * @var array
*/
protected $methodBindings = [];
/**
* The container's shared instances.
*
- * @var object[]
- */
- protected $instances = [];
-
- /**
- * The container's scoped instances.
- *
* @var array
*/
- protected $scopedInstances = [];
+ protected $instances = [];
/**
* The registered type aliases.
*
- * @var string[]
+ * @var array
*/
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 = [];
- /**
- * The contextual attribute handlers.
- *
- * @var array[]
- */
- public $contextualAttributes = [];
-
- /**
- * Whether an abstract class has already had its attributes checked for bindings.
- *
- * @var array
- */
- protected $checkedForAttributeBindings = [];
-
- /**
- * Whether a class has already been checked for Singleton or Scoped attributes.
- *
- * @var array
- */
- protected $checkedForSingletonOrScopedAttributes = [];
-
/**
* All of the registered rebound callbacks.
*
- * @var array[]
+ * @var array
*/
protected $reboundCallbacks = [];
- /**
- * All of the global before resolving callbacks.
- *
- * @var \Closure[]
- */
- protected $globalBeforeResolvingCallbacks = [];
-
/**
* All of the global resolving callbacks.
*
- * @var \Closure[]
+ * @var array
*/
protected $globalResolvingCallbacks = [];
/**
* All of the global after resolving callbacks.
*
- * @var \Closure[]
+ * @var array
*/
protected $globalAfterResolvingCallbacks = [];
- /**
- * All of the before resolving callbacks by class type.
- *
- * @var array[]
- */
- protected $beforeResolvingCallbacks = [];
-
/**
* 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 = [];
- /**
- * All of the after resolving attribute callbacks by class type.
- *
- * @var array[]
- */
- protected $afterResolvingAttributeCallbacks = [];
-
- /**
- * The callback used to determine the container's environment.
- *
- * @var (callable(array|string): bool|string)|null
- */
- protected $environmentResolver = null;
-
/**
* Define a contextual binding.
*
- * @param array|string $concrete
+ * @param string $concrete
* @return \Illuminate\Contracts\Container\ContextualBindingBuilder
*/
public function when($concrete)
{
- $aliases = [];
-
- foreach (Util::arrayWrap($concrete) as $c) {
- $aliases[] = $this->getAlias($c);
- }
-
- return new ContextualBindingBuilder($this, $aliases);
- }
-
- /**
- * Define a contextual binding based on an attribute.
- *
- * @return void
- */
- public function whenHasAttribute(string $attribute, Closure $handler)
- {
- $this->contextualAttributes[$attribute] = $handler;
+ return new ContextualBindingBuilder($this, $this->getAlias($concrete));
}
/**
@@ -242,9 +156,9 @@ public function bound($abstract)
}
/**
- * {@inheritdoc}
+ * {@inheritdoc}
*/
- public function has(string $id): bool
+ public function has($id)
{
return $this->bound($id);
}
@@ -273,64 +187,9 @@ public function resolved($abstract)
*/
public function isShared($abstract)
{
- if (isset($this->instances[$abstract])) {
- return true;
- }
-
- if (isset($this->bindings[$abstract]['shared']) && $this->bindings[$abstract]['shared'] === true) {
- return true;
- }
-
- if (! class_exists($abstract)) {
- return false;
- }
-
- if (($scopedType = $this->getScopedTyped($abstract)) === null) {
- return false;
- }
-
- if ($scopedType === 'scoped') {
- if (! in_array($abstract, $this->scopedInstances, true)) {
- $this->scopedInstances[] = $abstract;
- }
- }
-
- return true;
- }
-
- /**
- * Determine if a ReflectionClass has scoping attributes applied.
- *
- * @param ReflectionClass