Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit329b181

Browse files
committed
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-------4da8884 [DI] Throw on "configured-keys <> getSubscribedServices()" mismatch
2 parents05d15cf +4da8884 commit329b181

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ protected function processValue($value, $isRoot = false)
9292
}
9393

9494
if ($serviceMap =array_keys($serviceMap)) {
95-
$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));
95+
$message =sprintf(1 <count($serviceMap) ?'keys "%s" do' :'key "%s" does',str_replace('%','%%',implode('", "',$serviceMap)));
96+
thrownewInvalidArgumentException(sprintf('Service %s not exist in the map returned by %s::getSubscribedServices() for service "%s".',$message,$class,$this->currentId));
9697
}
9798

9899
$serviceLocator =$this->serviceLocator;

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,23 @@ public function testWithAttributes()
115115

116116
$this->assertEquals($expected,$locator->getArgument(0));
117117
}
118+
119+
/**
120+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
121+
* @expectedExceptionMessage Service key "test" does not exist in the map returned by TestServiceSubscriber::getSubscribedServices() for service "foo_service".
122+
*/
123+
publicfunctiontestExtraServiceSubscriber()
124+
{
125+
$container =newContainerBuilder();
126+
$container->register('foo_service','TestServiceSubscriber')
127+
->setAutowired(true)
128+
->addArgument(newReference('container'))
129+
->addTag('container.service_subscriber',array(
130+
'key' =>'test',
131+
'id' =>'TestServiceSubscriber',
132+
))
133+
;
134+
$container->register('TestServiceSubscriber','TestServiceSubscriber');
135+
$container->compile();
136+
}
118137
}

‎src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ public function testServiceSubscriber()
561561
->setAutowired(true)
562562
->addArgument(newReference('container'))
563563
->addTag('container.service_subscriber',array(
564-
'key' =>'test',
564+
'key' =>'bar',
565565
'id' =>'TestServiceSubscriber',
566566
))
567567
;

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected function getFooServiceService()
102102
},'stdClass' =>function () {
103103
$f =function (\stdClass$v =null) {return$v; };return$f(${($_ =isset($this->services['autowired.stdClass']) ?$this->services['autowired.stdClass'] :$this->getAutowired_StdClassService()) &&false ?:'_'});
104104
},'bar' =>function () {
105-
$f =function (\stdClass$v) {return$v; };return$f(${($_ =isset($this->services['autowired.stdClass']) ?$this->services['autowired.stdClass'] :$this->getAutowired_StdClassService()) &&false ?:'_'});
105+
$f =function (\stdClass$v) {return$v; };return$f(${($_ =isset($this->services['TestServiceSubscriber']) ?$this->services['TestServiceSubscriber'] :$this->get('TestServiceSubscriber')) &&false ?:'_'});
106106
},'baz' =>function () {
107107
$f =function (\stdClass$v =null) {return$v; };return$f(${($_ =isset($this->services['autowired.stdClass']) ?$this->services['autowired.stdClass'] :$this->getAutowired_StdClassService()) &&false ?:'_'});
108108
})));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp