Skip to content

Commit

Permalink
update closure method
Browse files Browse the repository at this point in the history
  • Loading branch information
BMTmohammedtaha committed Jul 24, 2023
1 parent cf82a83 commit 5fc8749
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 5fc8749

Please sign in to comment.