Skip to content

Commit 5370a02

Browse files
feature #22809 [DI] Remove deprecated generating a dumped container without populating the method map (ro0NL)
This PR was merged into the 4.0-dev branch. Discussion ---------- [DI] Remove deprecated generating a dumped container without populating the method map | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> See #20113 Commits ------- fdb8c58 [DI] Remove deprecated generating a dumped container without populating the method map
2 parents 063da35 + fdb8c58 commit 5370a02

File tree

3 files changed

+2
-150
lines changed

3 files changed

+2
-150
lines changed

src/Symfony/Component/DependencyInjection/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* removed `Container::isFrozen`
88
* removed support for dumping an ucompiled container in `PhpDumper`
9+
* removed support for generating a dumped `Container` without populating the method map
910

1011
3.3.0
1112
-----

src/Symfony/Component/DependencyInjection/Container.php

+1-29
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,6 @@ public function has($id)
237237
continue;
238238
}
239239

240-
// We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder,
241-
// and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper)
242-
if (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class && method_exists($this, 'get'.strtr($id, $this->underscoreMap).'Service')) {
243-
@trigger_error('Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', E_USER_DEPRECATED);
244-
245-
return true;
246-
}
247-
248240
return false;
249241
}
250242
}
@@ -293,11 +285,6 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
293285
} elseif (--$i && $id !== $normalizedId = $this->normalizeId($id)) {
294286
$id = $normalizedId;
295287
continue;
296-
} elseif (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class && method_exists($this, $method = 'get'.strtr($id, $this->underscoreMap).'Service')) {
297-
// We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder,
298-
// and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper)
299-
@trigger_error('Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', E_USER_DEPRECATED);
300-
// $method is set to the right value, proceed
301288
} else {
302289
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
303290
if (!$id) {
@@ -374,22 +361,7 @@ public function reset()
374361
*/
375362
public function getServiceIds()
376363
{
377-
$ids = array();
378-
379-
if (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class) {
380-
// We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder,
381-
// and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper)
382-
@trigger_error('Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', E_USER_DEPRECATED);
383-
384-
foreach (get_class_methods($this) as $method) {
385-
if (preg_match('/^get(.+)Service$/', $method, $match)) {
386-
$ids[] = self::underscore($match[1]);
387-
}
388-
}
389-
}
390-
$ids[] = 'service_container';
391-
392-
return array_unique(array_merge($ids, array_keys($this->methodMap), array_keys($this->services)));
364+
return array_unique(array_merge(array('service_container'), array_keys($this->methodMap), array_keys($this->services)));
393365
}
394366

395367
/**

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

-121
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,6 @@ public function testGetServiceIds()
137137
$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()');
138138
}
139139

140-
/**
141-
* @group legacy
142-
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
143-
*/
144-
public function testGetLegacyServiceIds()
145-
{
146-
$sc = new LegacyProjectServiceContainer();
147-
$sc->set('foo', $obj = new \stdClass());
148-
149-
$this->assertEquals(array('internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
150-
}
151-
152140
public function testSet()
153141
{
154142
$sc = new Container();
@@ -227,38 +215,6 @@ public function testNormalizeIdKeepsCase()
227215
$this->assertSame('Foo', $sc->normalizeId('foo'));
228216
}
229217

230-
/**
231-
* @group legacy
232-
* @expectedDeprecation Service identifiers will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since version 3.3.
233-
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
234-
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
235-
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
236-
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
237-
*/
238-
public function testLegacyGet()
239-
{
240-
$sc = new LegacyProjectServiceContainer();
241-
$sc->set('foo', $foo = new \stdClass());
242-
243-
$this->assertSame($foo, $sc->get('foo'), '->get() returns the service for the given id');
244-
$this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
245-
$this->assertSame($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
246-
$this->assertSame($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
247-
$this->assertSame($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
248-
$this->assertSame($sc->__foo_baz, $sc->get('foo\\baz'), '->get() returns the service if a get*Method() is defined');
249-
250-
$sc->set('bar', $bar = new \stdClass());
251-
$this->assertSame($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
252-
253-
try {
254-
$sc->get('');
255-
$this->fail('->get() throws a \InvalidArgumentException exception if the service is empty');
256-
} catch (\Exception $e) {
257-
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e, '->get() throws a ServiceNotFoundException exception if the service is empty');
258-
}
259-
$this->assertNull($sc->get('', ContainerInterface::NULL_ON_INVALID_REFERENCE), '->get() returns null if the service is empty');
260-
}
261-
262218
public function testGetThrowServiceNotFoundException()
263219
{
264220
$sc = new ProjectServiceContainer();
@@ -317,26 +273,6 @@ public function testHas()
317273
$this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
318274
}
319275

320-
/**
321-
* @group legacy
322-
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
323-
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
324-
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
325-
* @expectedDeprecation Generating a dumped container without populating the method map is deprecated since 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.
326-
*/
327-
public function testLegacyHas()
328-
{
329-
$sc = new LegacyProjectServiceContainer();
330-
$sc->set('foo', new \stdClass());
331-
332-
$this->assertFalse($sc->has('foo1'), '->has() returns false if the service does not exist');
333-
$this->assertTrue($sc->has('foo'), '->has() returns true if the service exists');
334-
$this->assertTrue($sc->has('bar'), '->has() returns true if a get*Method() is defined');
335-
$this->assertTrue($sc->has('foo_bar'), '->has() returns true if a get*Method() is defined');
336-
$this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
337-
$this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined');
338-
}
339-
340276
public function testInitialized()
341277
{
342278
$sc = new ProjectServiceContainer();
@@ -542,60 +478,3 @@ protected function getThrowsExceptionOnServiceConfigurationService()
542478
throw new \Exception('Something was terribly wrong while trying to configure the service!');
543479
}
544480
}
545-
546-
class LegacyProjectServiceContainer extends Container
547-
{
548-
public $__bar;
549-
public $__foo_bar;
550-
public $__foo_baz;
551-
public $__internal;
552-
553-
public function __construct()
554-
{
555-
parent::__construct();
556-
557-
$this->__bar = new \stdClass();
558-
$this->__foo_bar = new \stdClass();
559-
$this->__foo_baz = new \stdClass();
560-
$this->__internal = new \stdClass();
561-
$this->privates = array('internal' => true);
562-
$this->aliases = array('alias' => 'bar');
563-
}
564-
565-
protected function getInternalService()
566-
{
567-
return $this->__internal;
568-
}
569-
570-
protected function getBarService()
571-
{
572-
return $this->__bar;
573-
}
574-
575-
protected function getFooBarService()
576-
{
577-
return $this->__foo_bar;
578-
}
579-
580-
protected function getFoo_BazService()
581-
{
582-
return $this->__foo_baz;
583-
}
584-
585-
protected function getCircularService()
586-
{
587-
return $this->get('circular');
588-
}
589-
590-
protected function getThrowExceptionService()
591-
{
592-
throw new \Exception('Something went terribly wrong!');
593-
}
594-
595-
protected function getThrowsExceptionOnServiceConfigurationService()
596-
{
597-
$this->services['throws_exception_on_service_configuration'] = $instance = new \stdClass();
598-
599-
throw new \Exception('Something was terribly wrong while trying to configure the service!');
600-
}
601-
}

0 commit comments

Comments
 (0)