Skip to content

Commit ff34631

Browse files
committed
Ensure a string is returned if defined and happens to be a non existent class name
1 parent 56f6f3f commit ff34631

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/Definition/Definition.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class Definition implements ArgumentResolverInterface, DefinitionInterface
5757
protected $resolved;
5858

5959
/**
60-
* @var bool
60+
* @var array
6161
*/
62-
protected $isAlreadySearched = false;
62+
protected $recursiveCheck = [];
6363

6464
/**
6565
* @param string $id
@@ -192,16 +192,15 @@ public function resolveNew()
192192
}
193193

194194
// stop recursive resolving
195-
if ($this->isAlreadySearched) {
196-
throw new NotFoundException(
197-
sprintf('Alias or class "%s" did not found.', $concrete)
198-
);
195+
if (is_string($concrete) && in_array($concrete, $this->recursiveCheck)) {
196+
$this->resolved = $concrete;
197+
return $concrete;
199198
}
200199

201200
// if we still have a string, try to pull it from the container
202201
// this allows for `alias -> alias -> ... -> concrete
203202
if (is_string($concrete) && $container instanceof ContainerInterface && $container->has($concrete)) {
204-
$this->isAlreadySearched = true;
203+
$this->recursiveCheck[] = $concrete;
205204
$concrete = $container->get($concrete);
206205
}
207206

tests/ContainerTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ public function testNonExistentClassCausesException(): void
228228
$container->add(NonExistent::class);
229229

230230
self::assertTrue($container->has(NonExistent::class));
231-
232-
$this->expectException(NotFoundException::class);
233-
$container->get(NonExistent::class);
231+
self::assertSame(NonExistent::class, $container->get(NonExistent::class));
234232
}
235233
}

0 commit comments

Comments
 (0)