Skip to content

Commit

Permalink
Processor: names of anonymous services are just numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 6, 2018
1 parent cc7c6f9 commit 859bd80
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/DI/Config/Processor.php
Expand Up @@ -374,10 +374,10 @@ public function applyNamespace(array $services, string $namespace): array
private function createDefinitionName($name, array $config): string
{
if (is_int($name)) {
$factory = $config['factory'] ?? null;
$postfix = $factory instanceof Statement && is_string($factory->getEntity()) ? '.' . $factory->getEntity(
) : (is_scalar($factory) ? ".$factory" : '');
$name = (count($this->builder->getDefinitions()) + 1) . preg_replace('#\W+#', '_', $postfix);
$counter = 1;
do {
$name = (string) $counter++;
} while ($this->builder->hasDefinition($name));
} elseif (preg_match('#^@[\w\\\\]+\z#', $name)) {
$name = $this->builder->getByType(substr($name, 1), true);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/DI/Compiler.missingDefinition.phpt
Expand Up @@ -14,7 +14,7 @@ Assert::throws(function () {
services:
-
');
}, Nette\InvalidStateException::class, "Service '2': Factory and type are missing in definition of service.");
}, Nette\InvalidStateException::class, "Service '1': Factory and type are missing in definition of service.");


Assert::throws(function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/DI/Compiler.unknownDefinitionKey.phpt
Expand Up @@ -22,4 +22,4 @@ Assert::throws(function () {
setups: []
foo: bar
');
}, Nette\InvalidStateException::class, "Service '2_stdClass': Unknown key 'autowire', 'setups', 'foo' in definition of service, did you mean 'autowired', 'setup'?");
}, Nette\InvalidStateException::class, "Service '1': Unknown key 'autowire', 'setups', 'foo' in definition of service, did you mean 'autowired', 'setup'?");

0 comments on commit 859bd80

Please sign in to comment.