Merge branch '3.4'

* 3.4:
  [DI] Deprecate Container::initialized() for privates
This commit is contained in:
Nicolas Grekas 2017-05-22 13:40:59 +02:00
commit d6bdd23e3d
3 changed files with 32 additions and 2 deletions

View File

@ -9,6 +9,11 @@ CHANGELOG
* removed support for dumping an ucompiled container in `PhpDumper`
* removed support for generating a dumped `Container` without populating the method map
3.4.0
-----
* deprecated the ability to check for the initialization of a private service with the `Container::initialized()` method
3.3.0
-----

View File

@ -343,6 +343,10 @@ class Container implements ResettableContainerInterface
$id = $this->aliases[$id];
}
if (isset($this->privates[$id])) {
@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);
}
return isset($this->services[$id]);
}

View File

@ -134,7 +134,7 @@ class ContainerTest extends TestCase
$sc = new ProjectServiceContainer();
$sc->set('foo', $obj = new \stdClass());
$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()');
$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()');
}
public function testSet()
@ -286,6 +286,17 @@ class ContainerTest extends TestCase
$this->assertTrue($sc->initialized('alias'), '->initialized() returns true for alias if aliased service is initialized');
}
/**
* @group legacy
* @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.
*/
public function testInitializedWithPrivateService()
{
$sc = new ProjectServiceContainer();
$sc->get('internal_dependency');
$this->assertTrue($sc->initialized('internal'));
}
public function testReset()
{
$c = new Container();
@ -427,6 +438,7 @@ class ProjectServiceContainer extends Container
'circular' => 'getCircularService',
'throw_exception' => 'getThrowExceptionService',
'throws_exception_on_service_configuration' => 'getThrowsExceptionOnServiceConfigurationService',
'internal_dependency' => 'getInternalDependencyService',
);
public function __construct()
@ -443,7 +455,7 @@ class ProjectServiceContainer extends Container
protected function getInternalService()
{
return $this->__internal;
return $this->services['internal'] = $this->__internal;
}
protected function getBarService()
@ -477,4 +489,13 @@ class ProjectServiceContainer extends Container
throw new \Exception('Something was terribly wrong while trying to configure the service!');
}
protected function getInternalDependencyService()
{
$this->services['internal_dependency'] = $instance = new \stdClass();
$instance->internal = isset($this->services['internal']) ? $this->services['internal'] : $this->getInternalService();
return $instance;
}
}