This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
generated from spaceonfire/skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from spaceonfire/develop
Split container responsibility
- Loading branch information
Showing
19 changed files
with
711 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
run: | ||
start: | ||
docker-compose up -d | ||
docker-compose exec app bash | ||
|
||
stop: | ||
docker-compose down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spaceonfire\Container\Argument; | ||
|
||
use ReflectionFunctionAbstract; | ||
use ReflectionMethod; | ||
use spaceonfire\Container\ContainerAwareTrait; | ||
use spaceonfire\Container\ContainerInterface; | ||
use spaceonfire\Container\Exception\ContainerException; | ||
use Throwable; | ||
|
||
final class ArgumentResolver implements ResolverInterface | ||
{ | ||
use ContainerAwareTrait; | ||
|
||
/** | ||
* ArgumentResolver constructor. | ||
* @param ContainerInterface $container | ||
*/ | ||
public function __construct(ContainerInterface $container) | ||
{ | ||
$this->setContainer($container); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function resolveArguments(ReflectionFunctionAbstract $reflection, array $arguments = []): array | ||
{ | ||
$result = []; | ||
|
||
foreach ($reflection->getParameters() as $parameter) { | ||
try { | ||
$name = $parameter->getName(); | ||
|
||
if (array_key_exists($name, $arguments)) { | ||
$v = $arguments[$name]; | ||
if ($v instanceof Argument) { | ||
$v = $v->resolve($this->getContainer()); | ||
} | ||
$result[$name] = $v; | ||
continue; | ||
} | ||
|
||
$class = $parameter->getClass(); | ||
$defaultValue = $parameter->isDefaultValueAvailable() | ||
? new ArgumentValue($parameter->getDefaultValue()) | ||
: null; | ||
|
||
$argument = new Argument($name, $class === null ? null : $class->getName(), $defaultValue); | ||
|
||
$result[$name] = $argument->resolve($this->getContainer()); | ||
} catch (Throwable $e) { | ||
$location = $reflection->getName(); | ||
|
||
if ($reflection instanceof ReflectionMethod) { | ||
$location = $reflection->getDeclaringClass()->getName() . '::' . $location; | ||
} | ||
|
||
throw new ContainerException( | ||
sprintf('Unable to resolve `%s` in {%s}: %s', $parameter->getName(), $location, $e->getMessage()), | ||
$e->getCode(), | ||
$e | ||
); | ||
} | ||
} | ||
|
||
return array_values($result); | ||
} | ||
} |
Oops, something went wrong.