Skip to content

Commit

Permalink
Revert "LocatorDefinition: deprecated support for create($name) metho…
Browse files Browse the repository at this point in the history
…d (BC break)"

This reverts commit 8140289.
  • Loading branch information
dg committed May 3, 2024
1 parent 468b495 commit 0ce3555
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/DI/Definitions/LocatorDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function setImplement(string $interface): static
|| (preg_match('#^(get|create)[A-Z]#', $method->name) && $method->getNumberOfParameters() === 0)
)) {
throw new Nette\InvalidArgumentException(sprintf(
"Service '%s': Method %s::%s() does not meet the requirements: is create*(), get*() or get(\$name) and is non-static.",
"Service '%s': Method %s::%s() does not meet the requirements: is create(\$name), get(\$name), create*() or get*() and is non-static.",
$this->getName(),
$interface,
$method->name,
Expand All @@ -52,8 +52,6 @@ public function setImplement(string $interface): static
"return type of $interface::$method->name()",
allowNullable: true,
);
} elseif (str_starts_with($method->name, 'create')) {
trigger_error(sprintf("Service '%s': Method %s::create(\$name) is deprecated, use createFoo().", $this->getName(), $interface), E_USER_DEPRECATED);
}
}

Expand Down
3 changes: 1 addition & 2 deletions tests/DI/Compiler.generatedLocator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ interface LocatorFactoryN
}


// create($name) is deprecated
$container = @createContainer(new DI\Compiler, '
$container = createContainer(new DI\Compiler, '
services:
- LoremChild
Expand Down
12 changes: 6 additions & 6 deletions tests/DI/Definitions.LocatorDefinition.api.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,31 @@ Assert::exception(function () {
Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(Bad2::class);
}, Nette\InvalidArgumentException::class, "Service '': Method Bad2::create() does not meet the requirements: is create*(), get*() or get(\$name) and is non-static.");
}, Nette\InvalidArgumentException::class, "Service '': Method Bad2::create() does not meet the requirements: is create(\$name), get(\$name), create*() or get*() and is non-static.");


Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(Bad3::class);
}, Nette\InvalidArgumentException::class, "Service '': Method Bad3::get() does not meet the requirements: is create*(), get*() or get(\$name) and is non-static.");
}, Nette\InvalidArgumentException::class, "Service '': Method Bad3::get() does not meet the requirements: is create(\$name), get(\$name), create*() or get*() and is non-static.");


Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(Bad4::class);
}, Nette\InvalidArgumentException::class, "Service '': Method Bad4::foo() does not meet the requirements: is create*(), get*() or get(\$name) and is non-static.");
}, Nette\InvalidArgumentException::class, "Service '': Method Bad4::foo() does not meet the requirements: is create(\$name), get(\$name), create*() or get*() and is non-static.");


Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(Bad5::class);
}, Nette\InvalidArgumentException::class, "Service '': Method Bad5::get() does not meet the requirements: is create*(), get*() or get(\$name) and is non-static.");
}, Nette\InvalidArgumentException::class, "Service '': Method Bad5::get() does not meet the requirements: is create(\$name), get(\$name), create*() or get*() and is non-static.");


Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(Bad6::class);
}, Nette\InvalidArgumentException::class, "Service '': Method Bad6::get() does not meet the requirements: is create*(), get*() or get(\$name) and is non-static.");
}, Nette\InvalidArgumentException::class, "Service '': Method Bad6::get() does not meet the requirements: is create(\$name), get(\$name), create*() or get*() and is non-static.");


Assert::noError(function () {
Expand All @@ -121,7 +121,7 @@ Assert::noError(function () {

Assert::noError(function () {
$def = new LocatorDefinition;
@$def->setImplement(Good2::class); // create($name) is deprecated
$def->setImplement(Good2::class);
Assert::same(Good2::class, $def->getImplement());
Assert::same(Good2::class, $def->getType());
});
Expand Down
2 changes: 1 addition & 1 deletion tests/DI/Definitions.LocatorDefinition.render.create.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface Good
test('', function () {
$def = new LocatorDefinition;
$def->setName('abc');
@$def->setImplement(Good::class); // create($name) is deprecated
$def->setImplement(Good::class);
$def->setReferences(['first' => '@a', 'second' => 'stdClass']);

$builder = new Nette\DI\ContainerBuilder;
Expand Down

0 comments on commit 0ce3555

Please sign in to comment.