diff --git a/src/Callback.php b/src/Callback.php index 57b499f..3dcf73e 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -87,25 +87,30 @@ public function closure(array $action): callable if ($this->isUseContainer) { $reflection = new \ReflectionClass($class); $constructor = $reflection->getConstructor(); - // Get the parameters of the constructor - $parameters = $constructor->getParameters(); - $dependencies = []; - foreach ($parameters as $parameter) { - $parameterType = $parameter->getType(); - - // Check if the parameter has a type - if ($parameterType !== null) { - // Get the name of the dependency class - $dependencyClass = $parameterType->getName(); - - // Resolve the dependency instance from the container - $dependencyInstance = $this->container->get($dependencyClass); - - // Add the dependency instance to the array - $dependencies[] = $dependencyInstance; + if ($constructor) { + // Get the parameters of the constructor + $parameters = $constructor->getParameters(); + $dependencies = []; + foreach ($parameters as $parameter) { + $parameterType = $parameter->getType(); + + // Check if the parameter has a type + if ($parameterType !== null) { + // Get the name of the dependency class + $dependencyClass = $parameterType->getName(); + + // Resolve the dependency instance from the container + $dependencyInstance = $this->container->get($dependencyClass); + + // Add the dependency instance to the array + $dependencies[] = $dependencyInstance; + } } + $classInstance = new $class(...$dependencies); + } + else { + $classInstance = new $class(); } - $classInstance = new $class($dependencies); } else { $classInstance = new $class(); }