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

Commite282307

Browse files
[DI] Dont use Container::get() when fetching private services internally
1 parent703db1e commite282307

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

‎src/Symfony/Component/DependencyInjection/Container.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public function set($id, $service)
181181
if (isset($this->privates[$id])) {
182182
if (null ===$service) {
183183
@trigger_error(sprintf('Unsetting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.',$id),E_USER_DEPRECATED);
184+
unset($this->privates[$id]);
184185
}else {
185186
@trigger_error(sprintf('Setting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0. A new public service will be created instead.',$id),E_USER_DEPRECATED);
186187
}

‎src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,9 @@ private function getServiceCall($id, Reference $reference = null)
13761376
return'$this';
13771377
}
13781378

1379+
if ($this->container->hasDefinition($id) && !$this->container->getDefinition($id)->isPublic()) {
1380+
return"\$this->services[(isset(\$this->services['$id']) ||\$this->services['$id'] =\$this->{$this->generateMethodName($id)}()) && false ?: '$id']";
1381+
}
13791382
if (null !==$reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !==$reference->getInvalidBehavior()) {
13801383
returnsprintf('$this->get(\'%s\', ContainerInterface::NULL_ON_INVALID_REFERENCE)',$id);
13811384
}else {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function getConfiguredServiceService()
110110
{
111111
$this->services['configured_service'] =$instance =new \stdClass();
112112

113-
$this->get('configurator_service')->configureStdClass($instance);
113+
$this->services[(isset($this->services['configurator_service']) ||$this->services['configurator_service'] =$this->getConfiguratorServiceService()) &&false ?:'configurator_service']->configureStdClass($instance);
114114

115115
return$instance;
116116
}
@@ -127,7 +127,7 @@ protected function getConfiguredServiceSimpleService()
127127
{
128128
$this->services['configured_service_simple'] =$instance =new \stdClass();
129129

130-
$this->get('configurator_service_simple')->configureStdClass($instance);
130+
$this->services[(isset($this->services['configurator_service_simple']) ||$this->services['configurator_service_simple'] =$this->getConfiguratorServiceSimpleService()) &&false ?:'configurator_service_simple']->configureStdClass($instance);
131131

132132
return$instance;
133133
}
@@ -211,7 +211,7 @@ protected function getFactoryServiceService()
211211
*/
212212
protectedfunctiongetFactoryServiceSimpleService()
213213
{
214-
return$this->services['factory_service_simple'] =$this->get('factory_simple')->getInstance();
214+
return$this->services['factory_service_simple'] =$this->services[(isset($this->services['factory_simple']) ||$this->services['factory_simple'] =$this->getFactorySimpleService()) &&false ?:'factory_simple']->getInstance();
215215
}
216216

217217
/**
@@ -279,7 +279,7 @@ protected function getFooWithInlineService()
279279
{
280280
$this->services['foo_with_inline'] =$instance =new \Foo();
281281

282-
$instance->setBar($this->get('inlined'));
282+
$instance->setBar($this->services[(isset($this->services['inlined']) ||$this->services['inlined'] =$this->getInlinedService()) &&false ?:'inlined']);
283283

284284
return$instance;
285285
}
@@ -321,7 +321,7 @@ protected function getMethodCall1Service()
321321
*/
322322
protectedfunctiongetNewFactoryServiceService()
323323
{
324-
$this->services['new_factory_service'] =$instance =$this->get('new_factory')->getInstance();
324+
$this->services['new_factory_service'] =$instance =$this->services[(isset($this->services['new_factory']) ||$this->services['new_factory'] =$this->getNewFactoryService()) &&false ?:'new_factory']->getInstance();
325325

326326
$instance->foo ='bar';
327327

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp