minor #22186 [DI] Throw on "configured-keys <> getSubscribedServices()" mismatch (nicolas-grekas)
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Throw on "configured-keys <> getSubscribedServices()" mismatch
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
As reported on Slack, this creates DX issues, and provides no practical benefit. Let's throw instead of logging.
Commits
-------
4da8884ca4
[DI] Throw on "configured-keys <> getSubscribedServices()" mismatch
This commit is contained in:
commit
329b1819f1
@ -92,7 +92,8 @@ class RegisterServiceSubscribersPass extends AbstractRecursivePass
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($serviceMap = array_keys($serviceMap)) {
|
if ($serviceMap = array_keys($serviceMap)) {
|
||||||
$this->container->log($this, sprintf('Service keys "%s" do not exist in the map returned by %s::getSubscribedServices() for service "%s".', implode('", "', $serviceMap), $class, $this->currentId));
|
$message = sprintf(1 < count($serviceMap) ? 'keys "%s" do' : 'key "%s" does', str_replace('%', '%%', implode('", "', $serviceMap)));
|
||||||
|
throw new InvalidArgumentException(sprintf('Service %s not exist in the map returned by %s::getSubscribedServices() for service "%s".', $message, $class, $this->currentId));
|
||||||
}
|
}
|
||||||
|
|
||||||
$serviceLocator = $this->serviceLocator;
|
$serviceLocator = $this->serviceLocator;
|
||||||
|
@ -115,4 +115,23 @@ class RegisterServiceSubscribersPassTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals($expected, $locator->getArgument(0));
|
$this->assertEquals($expected, $locator->getArgument(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||||
|
* @expectedExceptionMessage Service key "test" does not exist in the map returned by TestServiceSubscriber::getSubscribedServices() for service "foo_service".
|
||||||
|
*/
|
||||||
|
public function testExtraServiceSubscriber()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$container->register('foo_service', 'TestServiceSubscriber')
|
||||||
|
->setAutowired(true)
|
||||||
|
->addArgument(new Reference('container'))
|
||||||
|
->addTag('container.service_subscriber', array(
|
||||||
|
'key' => 'test',
|
||||||
|
'id' => 'TestServiceSubscriber',
|
||||||
|
))
|
||||||
|
;
|
||||||
|
$container->register('TestServiceSubscriber', 'TestServiceSubscriber');
|
||||||
|
$container->compile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -561,7 +561,7 @@ class PhpDumperTest extends TestCase
|
|||||||
->setAutowired(true)
|
->setAutowired(true)
|
||||||
->addArgument(new Reference('container'))
|
->addArgument(new Reference('container'))
|
||||||
->addTag('container.service_subscriber', array(
|
->addTag('container.service_subscriber', array(
|
||||||
'key' => 'test',
|
'key' => 'bar',
|
||||||
'id' => 'TestServiceSubscriber',
|
'id' => 'TestServiceSubscriber',
|
||||||
))
|
))
|
||||||
;
|
;
|
||||||
|
@ -102,7 +102,7 @@ class ProjectServiceContainer extends Container
|
|||||||
}, 'stdClass' => function () {
|
}, 'stdClass' => function () {
|
||||||
$f = function (\stdClass $v = null) { return $v; }; return $f(${($_ = isset($this->services['autowired.stdClass']) ? $this->services['autowired.stdClass'] : $this->getAutowired_StdClassService()) && false ?: '_'});
|
$f = function (\stdClass $v = null) { return $v; }; return $f(${($_ = isset($this->services['autowired.stdClass']) ? $this->services['autowired.stdClass'] : $this->getAutowired_StdClassService()) && false ?: '_'});
|
||||||
}, 'bar' => function () {
|
}, 'bar' => function () {
|
||||||
$f = function (\stdClass $v) { return $v; }; return $f(${($_ = isset($this->services['autowired.stdClass']) ? $this->services['autowired.stdClass'] : $this->getAutowired_StdClassService()) && false ?: '_'});
|
$f = function (\stdClass $v) { return $v; }; return $f(${($_ = isset($this->services['TestServiceSubscriber']) ? $this->services['TestServiceSubscriber'] : $this->get('TestServiceSubscriber')) && false ?: '_'});
|
||||||
}, 'baz' => function () {
|
}, 'baz' => function () {
|
||||||
$f = function (\stdClass $v = null) { return $v; }; return $f(${($_ = isset($this->services['autowired.stdClass']) ? $this->services['autowired.stdClass'] : $this->getAutowired_StdClassService()) && false ?: '_'});
|
$f = function (\stdClass $v = null) { return $v; }; return $f(${($_ = isset($this->services['autowired.stdClass']) ? $this->services['autowired.stdClass'] : $this->getAutowired_StdClassService()) && false ?: '_'});
|
||||||
})));
|
})));
|
||||||
|
Reference in New Issue
Block a user