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

Appearance settings

Commit e0eb247

Browse filesBrowse files
committed
[DI] Deprecate Container::initialized() for privates
1 parent 98a2d3c commit e0eb247
Copy full SHA for e0eb247

File tree

3 files changed

+32
-2
lines changed
Filter options

3 files changed

+32
-2
lines changed

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
3.4.0
5+
-----
6+
7+
* deprecated the ability to check for the initialization of a private service with the `Container::initialized()` method
8+
49
3.3.0
510
-----
611

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Container.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ public function initialized($id)
370370
$id = $this->aliases[$id];
371371
}
372372

373+
if (isset($this->privates[$id])) {
374+
@trigger_error(sprintf('Checking for the initialization of the "%s" private service is deprecated since Symfony 3.4 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
375+
}
376+
373377
return isset($this->services[$id]);
374378
}
375379

‎src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php
+23-2Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function testGetServiceIds()
147147

148148
$sc = new ProjectServiceContainer();
149149
$sc->set('foo', $obj = new \stdClass());
150-
$this->assertEquals(array('service_container', 'internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()');
150+
$this->assertEquals(array('service_container', 'internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'internal_dependency', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()');
151151
}
152152

153153
/**
@@ -363,6 +363,17 @@ public function testInitialized()
363363
$this->assertTrue($sc->initialized('alias'), '->initialized() returns true for alias if aliased service is initialized');
364364
}
365365

366+
/**
367+
* @group legacy
368+
* @expectedDeprecation Checking for the initialization of the "internal" private service is deprecated since Symfony 3.4 and won't be supported anymore in Symfony 4.0.
369+
*/
370+
public function testInitializedWithPrivateService()
371+
{
372+
$sc = new ProjectServiceContainer();
373+
$sc->get('internal_dependency');
374+
$this->assertTrue($sc->initialized('internal'));
375+
}
376+
366377
public function testReset()
367378
{
368379
$c = new Container();
@@ -504,6 +515,7 @@ class ProjectServiceContainer extends Container
504515
'circular' => 'getCircularService',
505516
'throw_exception' => 'getThrowExceptionService',
506517
'throws_exception_on_service_configuration' => 'getThrowsExceptionOnServiceConfigurationService',
518+
'internal_dependency' => 'getInternalDependencyService',
507519
);
508520

509521
public function __construct()
@@ -520,7 +532,7 @@ public function __construct()
520532

521533
protected function getInternalService()
522534
{
523-
return $this->__internal;
535+
return $this->services['internal'] = $this->__internal;
524536
}
525537

526538
protected function getBarService()
@@ -554,6 +566,15 @@ protected function getThrowsExceptionOnServiceConfigurationService()
554566

555567
throw new \Exception('Something was terribly wrong while trying to configure the service!');
556568
}
569+
570+
protected function getInternalDependencyService()
571+
{
572+
$this->services['internal_dependency'] = $instance = new \stdClass();
573+
574+
$instance->internal = isset($this->services['internal']) ? $this->services['internal'] : $this->getInternalService();
575+
576+
return $instance;
577+
}
557578
}
558579

559580
class LegacyProjectServiceContainer extends Container

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.