Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
carloscarucce committed Jul 1, 2024
2 parents c7b7912 + ea694ad commit d780214
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ServiceContainer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Webdevcave\Yadic;

use Closure;
Expand Down Expand Up @@ -49,14 +51,15 @@ public function __construct(CacheInterface $cache = null)
*
* @template T
*
* @param T $id Identifier of the entry to look for.
* @param T $id Identifier of the entry to look for.
* @param array $arguments Predefined arguments.
*
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
* @throws ContainerExceptionInterface Error while retrieving the entry.
*
* @return T
*/
public function get(string $id): mixed
public function get(string $id, array $arguments = []): mixed
{
if (isset($this->singletons[$id])) {
return $this->singletons[$id];
Expand All @@ -69,10 +72,9 @@ public function get(string $id): mixed
try {
$className = $this->aliases[$id] ?? $id;
$reflectionClass = new ReflectionClass($className);
$arguments = [];

if ($constructor = $reflectionClass->getConstructor()) {
$arguments = $this->createArguments($constructor);
$arguments = $this->createArguments($constructor, $arguments);
}

$instance = $reflectionClass->newInstanceArgs($arguments);
Expand Down

0 comments on commit d780214

Please sign in to comment.