Skip to content

Commit

Permalink
ContainerBuilder: added check that accessor have no setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 28, 2018
1 parent 2e2f5cd commit 98eb0e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/DI/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ private function resolveImplement(ServiceDefinition $def, $name): void
if ($rc->hasMethod('get')) {
if ($method->getParameters()) {
throw new ServiceCreationException("Method $methodName used in service '$name' must have no arguments.");
} elseif ($def->getSetup()) {
throw new ServiceCreationException("Service accessor '$name' must have no setup.");
}
if (!$def->getEntity()) {
$def->setFactory('@\\' . ltrim($def->getType(), '\\'));
Expand Down
14 changes: 14 additions & 0 deletions tests/DI/Compiler.generatedFactory.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,17 @@ Assert::exception(function () {
$builder->addDefinition('one')->setImplement('Bad6')->setFactory('Bad5');
$builder->complete();
}, Nette\InvalidStateException::class, 'Unused parameter $baz when implementing method Bad6::create().');



interface Bad7
{
public function get();
}

Assert::exception(function () {
$builder = new DI\ContainerBuilder;
$builder->addDefinition('stdClass')->setFactory('stdClass');
$builder->addDefinition('one')->setImplement('Bad7')->setClass('stdClass')->addSetup('method');
$builder->complete();
}, Nette\InvalidStateException::class, "Service accessor 'one' must have no setup.");

0 comments on commit 98eb0e6

Please sign in to comment.