Skip to content

Commit

Permalink
Merge pull request #17 from lucidarch/feature/resolve-units-using-ser…
Browse files Browse the repository at this point in the history
…vice-container

Resolve units using Service Container
  • Loading branch information
Mulkave authored Feb 8, 2021
2 parents 1b54f6e + 3af842e commit 58e1ba0
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Bus/Marshal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Exception;
use ArrayAccess;
use ReflectionClass;
use ReflectionParameter;

trait Marshal
Expand All @@ -20,17 +19,15 @@ trait Marshal
*/
protected function marshal($command, ArrayAccess $source, array $extras = [])
{
$injected = [];

$reflection = new ReflectionClass($command);

if ($constructor = $reflection->getConstructor()) {
$injected = array_map(function ($parameter) use ($command, $source, $extras) {
return $this->getParameterValueForCommand($command, $source, $parameter, $extras);
}, $constructor->getParameters());
$parameters = [];

foreach ($source as $name => $parameter) {
$parameters[$name] = $parameter;
}

return $reflection->newInstanceArgs($injected);
$parameters = array_merge($parameters, $extras);

return app($command, $parameters);
}

/**
Expand Down

0 comments on commit 58e1ba0

Please sign in to comment.