Skip to content

Commit 60bda50

Browse files
Merge branch '3.2' into 3.3
* 3.2: [Yaml] Add missing deprecation annotation [DI] Check for privates before shared services
2 parents 7f34aa2 + fb2a0f2 commit 60bda50

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

Container.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,16 @@ public function has($id)
231231
if ('service_container' === $id) {
232232
return true;
233233
}
234+
if (isset($this->privates[$id])) {
235+
@trigger_error(sprintf('Checking for the existence of the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
236+
}
234237
if (isset($this->aliases[$id])) {
235238
$id = $this->aliases[$id];
236239
}
237240
if (isset($this->services[$id])) {
238241
return true;
239242
}
240243

241-
if (isset($this->privates[$id])) {
242-
@trigger_error(sprintf('Checking for the existence of the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
243-
}
244-
245244
if (isset($this->methodMap[$id])) {
246245
return true;
247246
}
@@ -293,6 +292,10 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
293292
if (isset($this->aliases[$id])) {
294293
$id = $this->aliases[$id];
295294
}
295+
if (isset($this->privates[$id])) {
296+
@trigger_error(sprintf('Requesting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
297+
}
298+
296299
// Re-use shared service instance if it exists.
297300
if (isset($this->services[$id])) {
298301
return $this->services[$id];
@@ -331,9 +334,6 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
331334

332335
return;
333336
}
334-
if (isset($this->privates[$id])) {
335-
@trigger_error(sprintf('Requesting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
336-
}
337337

338338
$this->loading[$id] = true;
339339

ContainerBuilder.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,6 @@ public function compile(/*$resolveEnvPlaceholders = false*/)
736736
$compiler->compile($this);
737737

738738
foreach ($this->definitions as $id => $definition) {
739-
if (!$definition->isPublic()) {
740-
$this->privates[$id] = true;
741-
}
742739
if ($this->trackResources && $definition->isLazy()) {
743740
$this->getReflectionClass($definition->getClass());
744741
}

Tests/ContainerTest.php

Lines changed: 17 additions & 4 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
/**
@@ -453,7 +453,8 @@ public function testUnsetInternalPrivateServiceIsDeprecated()
453453
public function testChangeInternalPrivateServiceIsDeprecated()
454454
{
455455
$c = new ProjectServiceContainer();
456-
$c->set('internal', new \stdClass());
456+
$c->set('internal', $internal = new \stdClass());
457+
$this->assertSame($c->get('internal'), $internal);
457458
}
458459

459460
/**
@@ -463,7 +464,8 @@ public function testChangeInternalPrivateServiceIsDeprecated()
463464
public function testCheckExistenceOfAnInternalPrivateServiceIsDeprecated()
464465
{
465466
$c = new ProjectServiceContainer();
466-
$c->has('internal');
467+
$c->get('internal_dependency');
468+
$this->assertTrue($c->has('internal'));
467469
}
468470

469471
/**
@@ -473,6 +475,7 @@ public function testCheckExistenceOfAnInternalPrivateServiceIsDeprecated()
473475
public function testRequestAnInternalSharedPrivateServiceIsDeprecated()
474476
{
475477
$c = new ProjectServiceContainer();
478+
$c->get('internal_dependency');
476479
$c->get('internal');
477480
}
478481

@@ -504,6 +507,7 @@ class ProjectServiceContainer extends Container
504507
'circular' => 'getCircularService',
505508
'throw_exception' => 'getThrowExceptionService',
506509
'throws_exception_on_service_configuration' => 'getThrowsExceptionOnServiceConfigurationService',
510+
'internal_dependency' => 'getInternalDependencyService',
507511
);
508512

509513
public function __construct()
@@ -520,7 +524,7 @@ public function __construct()
520524

521525
protected function getInternalService()
522526
{
523-
return $this->__internal;
527+
return $this->services['internal'] = $this->__internal;
524528
}
525529

526530
protected function getBarService()
@@ -554,6 +558,15 @@ protected function getThrowsExceptionOnServiceConfigurationService()
554558

555559
throw new \Exception('Something was terribly wrong while trying to configure the service!');
556560
}
561+
562+
protected function getInternalDependencyService()
563+
{
564+
$this->services['internal_dependency'] = $instance = new \stdClass();
565+
566+
$instance->internal = isset($this->services['internal']) ? $this->services['internal'] : $this->getInternalService();
567+
568+
return $instance;
569+
}
557570
}
558571

559572
class LegacyProjectServiceContainer extends Container

0 commit comments

Comments
 (0)