diff --git a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php index fec62f14e9ca6..6153166e79b8b 100644 --- a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php +++ b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php @@ -49,9 +49,6 @@ protected function resetService($name) } $manager->setProxyInitializer(\Closure::bind( function (&$wrappedInstance, LazyLoadingInterface $manager) use ($name) { - if (isset($this->normalizedIds[$normalizedId = strtolower($name)])) { - $name = $this->normalizedIds[$normalizedId]; - } if (isset($this->aliases[$name])) { $name = $this->aliases[$name]; } diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index f0887c29f099b..7c01c34021d7e 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG * removed `Container::isFrozen` * removed support for dumping an ucompiled container in `PhpDumper` * removed support for generating a dumped `Container` without populating the method map + * removed support for case insensitive service identifiers 3.4.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 3df05883dfab5..fc5dfe9d25a15 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -26,26 +26,7 @@ * * Services and parameters are simple key/pair stores. * - * Parameter and service keys are case insensitive. - * - * A service id can contain lowercased letters, digits, underscores, and dots. - * Underscores are used to separate words, and dots to group services - * under namespaces: - * - * - * - * A service can also be defined by creating a method named - * getXXXService(), where XXX is the camelized version of the id: - * - * + * Parameter keys are case insensitive. * * The container can have three possible behaviors when a service does not exist: * @@ -70,11 +51,6 @@ class Container implements ResettableContainerInterface protected $aliases = array(); protected $loading = array(); - /** - * @internal - */ - protected $normalizedIds = array(); - private $envCache = array(); private $compiled = false; @@ -171,8 +147,6 @@ public function setParameter($name, $value) */ public function set($id, $service) { - $id = $this->normalizeId($id); - if ('service_container' === $id) { throw new InvalidArgumentException('You cannot set service "service_container".'); } @@ -212,31 +186,24 @@ public function set($id, $service) */ public function has($id) { - for ($i = 2;;) { - if (isset($this->privates[$id])) { - @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); - } - if ('service_container' === $id) { - return true; - } - if (isset($this->aliases[$id])) { - $id = $this->aliases[$id]; - } - if (isset($this->services[$id])) { - return true; - } - - if (isset($this->methodMap[$id])) { - return true; - } - - if (--$i && $id !== $normalizedId = $this->normalizeId($id)) { - $id = $normalizedId; - continue; - } + if (isset($this->privates[$id])) { + @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); + } + if ('service_container' === $id) { + return true; + } + if (isset($this->aliases[$id])) { + $id = $this->aliases[$id]; + } + if (isset($this->services[$id])) { + return true; + } - return false; + if (isset($this->methodMap[$id])) { + return true; } + + return false; } /** @@ -258,69 +225,60 @@ public function has($id) */ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) { - // Attempt to retrieve the service by checking first aliases then - // available services. Service IDs are case insensitive, however since - // this method can be called thousands of times during a request, avoid - // calling $this->normalizeId($id) unless necessary. - for ($i = 2;;) { - if (isset($this->privates[$id])) { - @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); - } - if ('service_container' === $id) { - return $this; - } - if (isset($this->aliases[$id])) { - $id = $this->aliases[$id]; - } + if (isset($this->privates[$id])) { + @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); + } + if ('service_container' === $id) { + return $this; + } + if (isset($this->aliases[$id])) { + $id = $this->aliases[$id]; + } - // Re-use shared service instance if it exists. - if (isset($this->services[$id])) { - return $this->services[$id]; - } + // Re-use shared service instance if it exists. + if (isset($this->services[$id])) { + return $this->services[$id]; + } - if (isset($this->loading[$id])) { - throw new ServiceCircularReferenceException($id, array_keys($this->loading)); - } + if (isset($this->loading[$id])) { + throw new ServiceCircularReferenceException($id, array_keys($this->loading)); + } - if (isset($this->methodMap[$id])) { - $method = $this->methodMap[$id]; - } elseif (--$i && $id !== $normalizedId = $this->normalizeId($id)) { - $id = $normalizedId; - continue; - } else { - if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) { - if (!$id) { - throw new ServiceNotFoundException($id); - } + if (isset($this->methodMap[$id])) { + $method = $this->methodMap[$id]; + } else { + if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) { + if (!$id) { + throw new ServiceNotFoundException($id); + } - $alternatives = array(); - foreach ($this->getServiceIds() as $knownId) { - $lev = levenshtein($id, $knownId); - if ($lev <= strlen($id) / 3 || false !== strpos($knownId, $id)) { - $alternatives[] = $knownId; - } + $alternatives = array(); + foreach ($this->getServiceIds() as $knownId) { + $lev = levenshtein($id, $knownId); + if ($lev <= strlen($id) / 3 || false !== strpos($knownId, $id)) { + $alternatives[] = $knownId; } - - throw new ServiceNotFoundException($id, null, null, $alternatives); } - return; + throw new ServiceNotFoundException($id, null, null, $alternatives); } - $this->loading[$id] = true; + return; + } - try { - $service = $this->$method(); - } catch (\Exception $e) { - unset($this->services[$id]); + $this->loading[$id] = true; - throw $e; - } finally { - unset($this->loading[$id]); - } + try { + $service = $this->$method(); + } catch (\Exception $e) { + unset($this->services[$id]); - return $service; + throw $e; + } finally { + unset($this->loading[$id]); } + + return $service; } /** @@ -332,8 +290,6 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE */ public function initialized($id) { - $id = $this->normalizeId($id); - if ('service_container' === $id) { return false; } @@ -418,32 +374,6 @@ protected function getEnv($name) return $this->envCache[$name] = $this->getParameter("env($name)"); } - /** - * Returns the case sensitive id used at registration time. - * - * @param string $id - * - * @return string - * - * @internal - */ - public function normalizeId($id) - { - if (!is_string($id)) { - $id = (string) $id; - } - if (isset($this->normalizedIds[$normalizedId = strtolower($id)])) { - $normalizedId = $this->normalizedIds[$normalizedId]; - if ($id !== $normalizedId) { - @trigger_error(sprintf('Service identifiers will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.3.', $id, $normalizedId), E_USER_DEPRECATED); - } - } else { - $normalizedId = $this->normalizedIds[$normalizedId] = $id; - } - - return $normalizedId; - } - private function __clone() { } diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 7e63452126bf0..a14c29d55d206 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -485,8 +485,6 @@ public function getCompiler() */ public function set($id, $service) { - $id = $this->normalizeId($id); - if ($this->isCompiled() && (isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic())) { // setting a synthetic service on a compiled container is alright throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id)); @@ -504,7 +502,7 @@ public function set($id, $service) */ public function removeDefinition($id) { - unset($this->definitions[$this->normalizeId($id)]); + unset($this->definitions[$id]); } /** @@ -516,8 +514,6 @@ public function removeDefinition($id) */ public function has($id) { - $id = $this->normalizeId($id); - return isset($this->definitions[$id]) || isset($this->aliasDefinitions[$id]) || parent::has($id); } @@ -538,8 +534,6 @@ public function has($id) */ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { - $id = $this->normalizeId($id); - if ($service = parent::get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)) { return $service; } @@ -762,10 +756,8 @@ public function setAliases(array $aliases) */ public function setAlias($alias, $id) { - $alias = $this->normalizeId($alias); - if (is_string($id)) { - $id = new Alias($this->normalizeId($id)); + $id = new Alias($id); } elseif (!$id instanceof Alias) { throw new InvalidArgumentException('$id must be a string, or an Alias object.'); } @@ -786,7 +778,7 @@ public function setAlias($alias, $id) */ public function removeAlias($alias) { - unset($this->aliasDefinitions[$this->normalizeId($alias)]); + unset($this->aliasDefinitions[$alias]); } /** @@ -798,7 +790,7 @@ public function removeAlias($alias) */ public function hasAlias($id) { - return isset($this->aliasDefinitions[$this->normalizeId($id)]); + return isset($this->aliasDefinitions[$id]); } /** @@ -822,8 +814,6 @@ public function getAliases() */ public function getAlias($id) { - $id = $this->normalizeId($id); - if (!isset($this->aliasDefinitions[$id])) { throw new InvalidArgumentException(sprintf('The service alias "%s" does not exist.', $id)); } @@ -912,8 +902,6 @@ public function setDefinition($id, Definition $definition) throw new BadMethodCallException('Adding definition to a compiled container is not allowed'); } - $id = $this->normalizeId($id); - unset($this->aliasDefinitions[$id]); return $this->definitions[$id] = $definition; @@ -928,7 +916,7 @@ public function setDefinition($id, Definition $definition) */ public function hasDefinition($id) { - return isset($this->definitions[$this->normalizeId($id)]); + return isset($this->definitions[$id]); } /** @@ -942,8 +930,6 @@ public function hasDefinition($id) */ public function getDefinition($id) { - $id = $this->normalizeId($id); - if (!isset($this->definitions[$id])) { throw new ServiceNotFoundException($id); } @@ -964,8 +950,6 @@ public function getDefinition($id) */ public function findDefinition($id) { - $id = $this->normalizeId($id); - while (isset($this->aliasDefinitions[$id])) { $id = (string) $this->aliasDefinitions[$id]; } @@ -1311,22 +1295,6 @@ public function getEnvCounters() return $this->envCounters; } - /** - * @internal - */ - public function getNormalizedIds() - { - $normalizedIds = array(); - - foreach ($this->normalizedIds as $k => $v) { - if ($v !== (string) $k) { - $normalizedIds[$k] = $v; - } - } - - return $normalizedIds; - } - /** * @final */ @@ -1394,7 +1362,7 @@ private function callMethod($service, $call) private function shareService(Definition $definition, $service, $id) { if (null !== $id && $definition->isShared()) { - $this->services[$this->normalizeId($id)] = $service; + $this->services[$id] = $service; } } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php index 25ab3078c9a2a..57a6e5c100b9a 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php @@ -281,7 +281,7 @@ private function addOptions(array $options) */ private function dotize($id) { - return strtolower(preg_replace('/\W/i', '_', $id)); + return preg_replace('/\W/i', '_', $id); } /** diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index d77733ed884ee..61718c680d6d1 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -826,7 +826,6 @@ public function __construct() } $code .= "\n \$this->services = array();\n"; - $code .= $this->addNormalizedIds(); $code .= $this->addMethodMap(); $code .= $this->addPrivateServices(); $code .= $this->addAliases(); @@ -879,25 +878,6 @@ public function isCompiled() EOF; } - /** - * Adds the normalizedIds property definition. - * - * @return string - */ - private function addNormalizedIds() - { - $code = ''; - $normalizedIds = $this->container->getNormalizedIds(); - ksort($normalizedIds); - foreach ($normalizedIds as $id => $normalizedId) { - if ($this->container->has($normalizedId)) { - $code .= ' '.$this->export($id).' => '.$this->export($normalizedId).",\n"; - } - } - - return $code ? " \$this->normalizedIds = array(\n".$code." );\n" : ''; - } - /** * Adds the methodMap property definition. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 51f7001491a19..a8b7f88313a6e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -1082,6 +1082,21 @@ public function testRegisterForAutoconfiguration() // when called multiple times, the same instance is returned $this->assertSame($childDefA, $container->registerForAutoconfiguration('AInterface')); } + + public function testCaseSensitivity() + { + $container = new ContainerBuilder(); + $container->register('foo', 'stdClass'); + $container->register('Foo', 'stdClass')->setProperty('foo', new Reference('foo'))->setPublic(false); + $container->register('fOO', 'stdClass')->setProperty('Foo', new Reference('Foo')); + + $this->assertSame(array('service_container', 'foo', 'Foo', 'fOO', 'Psr\Container\ContainerInterface', 'Symfony\Component\DependencyInjection\ContainerInterface'), $container->getServiceIds()); + + $container->compile(); + + $this->assertNotSame($container->get('foo'), $container->get('fOO'), '->get() returns the service for the given id, case sensitively'); + $this->assertSame($container->get('fOO')->Foo->foo, $container->get('foo'), '->get() returns the service for the given id, case sensitively'); + } } class FooClass diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index 3cc9f384ed5c7..9b3db8af6d095 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -193,26 +193,15 @@ public function testGet() $this->assertNull($sc->get('', ContainerInterface::NULL_ON_INVALID_REFERENCE), '->get() returns null if the service is empty'); } - /** - * @group legacy - * @expectedDeprecation Service identifiers will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since version 3.3. - */ - public function testGetInsensitivity() + public function testCaseSensitivity() { - $sc = new ProjectServiceContainer(); - $sc->set('foo', $foo = new \stdClass()); - $this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase'); - } + $sc = new Container(); + $sc->set('foo', $foo1 = new \stdClass()); + $sc->set('Foo', $foo2 = new \stdClass()); - /** - * @group legacy - * @expectedDeprecation Service identifiers will be made case sensitive in Symfony 4.0. Using "foo" instead of "Foo" is deprecated since version 3.3. - */ - public function testNormalizeIdKeepsCase() - { - $sc = new ProjectServiceContainer(); - $sc->normalizeId('Foo', true); - $this->assertSame('Foo', $sc->normalizeId('foo')); + $this->assertSame(array('service_container', 'foo', 'Foo'), $sc->getServiceIds()); + $this->assertSame($foo1, $sc->get('foo'), '->get() returns the service for the given id, case sensitively'); + $this->assertSame($foo2, $sc->get('Foo'), '->get() returns the service for the given id, case sensitively'); } public function testGetThrowServiceNotFoundException() diff --git a/src/Symfony/Component/DependencyInjection/Tests/CrossCheckTest.php b/src/Symfony/Component/DependencyInjection/Tests/CrossCheckTest.php index bcfe88acc0ce4..dbdbb79542316 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/CrossCheckTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/CrossCheckTest.php @@ -55,12 +55,6 @@ public function testCrossCheck($fixture, $type) $this->assertEquals($container2->getAliases(), $container1->getAliases(), 'loading a dump from a previously loaded container returns the same container'); $this->assertEquals($container2->getDefinitions(), $container1->getDefinitions(), 'loading a dump from a previously loaded container returns the same container'); $this->assertEquals($container2->getParameterBag()->all(), $container1->getParameterBag()->all(), '->getParameterBag() returns the same value for both containers'); - - $r = new \ReflectionProperty(ContainerBuilder::class, 'normalizedIds'); - $r->setAccessible(true); - $r->setValue($container2, array()); - $r->setValue($container1, array()); - $this->assertEquals(serialize($container2), serialize($container1), 'loading a dump from a previously loaded container returns the same container'); $services1 = array(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php index 13b45fda07a70..472a211537160 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php @@ -139,5 +139,11 @@ ->register('lazy_context_ignore_invalid_ref', 'LazyContext') ->setArguments(array(new IteratorArgument(array(new Reference('foo.baz'), new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))), new IteratorArgument(array()))) ; +$container + ->register('BAR', 'stdClass') + ->setProperty('bar', new Reference('bar')) +; +$container->register('bar2', 'stdClass'); +$container->register('BAR2', 'stdClass'); return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot index b316b93c1576b..e6b4de7d85e83 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot @@ -29,6 +29,9 @@ digraph sc { node_factory_service_simple [label="factory_service_simple\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_lazy_context [label="lazy_context\nLazyContext\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_lazy_context_ignore_invalid_ref [label="lazy_context_ignore_invalid_ref\nLazyContext\n", shape=record, fillcolor="#eeeeee", style="filled"]; + node_BAR [label="BAR\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; + node_bar2 [label="bar2\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; + node_BAR2 [label="BAR2\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"]; node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"]; node_foobaz [label="foobaz\n\n", shape=record, fillcolor="#ff9999", style="filled"]; @@ -50,4 +53,5 @@ digraph sc { node_lazy_context -> node_service_container [label="" style="filled" color="#9999ff"]; node_lazy_context_ignore_invalid_ref -> node_foo_baz [label="" style="filled" color="#9999ff"]; node_lazy_context_ignore_invalid_ref -> node_invalid [label="" style="filled" color="#9999ff"]; + node_BAR -> node_bar [label="" style="dashed"]; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php index 76787db068b24..3c3ac43244249 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php @@ -27,9 +27,6 @@ class ProjectServiceContainer extends Container public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'symfony\\component\\dependencyinjection\\tests\\fixtures\\container33\\foo' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\Container33\\Foo', - ); $this->methodMap = array( 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\Container33\\Foo' => 'getSymfony_Component_DependencyInjection_Tests_Fixtures_Container33_FooService', ); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index 5b6c16919c003..b8118504bea82 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -27,12 +27,11 @@ class ProjectServiceContainer extends Container public function __construct() { parent::__construct(new ParameterBag($this->getDefaultParameters())); - $this->normalizedIds = array( - 'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface', - 'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface', - ); $this->methodMap = array( - 'bar' => 'getBarService', + 'BAR' => 'getBARService', + 'BAR2' => 'getBAR2Service', + 'bar' => 'getBar3Service', + 'bar2' => 'getBar22Service', 'baz' => 'getBazService', 'configurator_service' => 'getConfiguratorServiceService', 'configurator_service_simple' => 'getConfiguratorServiceSimpleService', @@ -72,6 +71,36 @@ public function __construct() ); } + /** + * Gets the 'BAR' service. + * + * This service is shared. + * This method always returns the same instance of the service. + * + * @return \stdClass A stdClass instance + */ + protected function getBARService() + { + $this->services['BAR'] = $instance = new \stdClass(); + + $instance->bar = ($this->services['bar'] ?? $this->get('bar')); + + return $instance; + } + + /** + * Gets the 'BAR2' service. + * + * This service is shared. + * This method always returns the same instance of the service. + * + * @return \stdClass A stdClass instance + */ + protected function getBAR2Service() + { + return $this->services['BAR2'] = new \stdClass(); + } + /** * Gets the 'bar' service. * @@ -80,7 +109,7 @@ public function __construct() * * @return \Bar\FooClass A Bar\FooClass instance */ - protected function getBarService() + protected function getBar3Service() { $a = ($this->services['foo.baz'] ?? $this->get('foo.baz')); @@ -91,6 +120,19 @@ protected function getBarService() return $instance; } + /** + * Gets the 'bar2' service. + * + * This service is shared. + * This method always returns the same instance of the service. + * + * @return \stdClass A stdClass instance + */ + protected function getBar22Service() + { + return $this->services['bar2'] = new \stdClass(); + } + /** * Gets the 'baz' service. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index ac46b06a8cca9..8fb33d8cbd44c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -30,7 +30,10 @@ public function __construct() $this->services = array(); $this->methodMap = array( - 'bar' => 'getBarService', + 'BAR' => 'getBARService', + 'BAR2' => 'getBAR2Service', + 'bar' => 'getBar3Service', + 'bar2' => 'getBar22Service', 'baz' => 'getBazService', 'configured_service' => 'getConfiguredServiceService', 'configured_service_simple' => 'getConfiguredServiceSimpleService', @@ -72,6 +75,36 @@ public function isCompiled() return true; } + /** + * Gets the 'BAR' service. + * + * This service is shared. + * This method always returns the same instance of the service. + * + * @return \stdClass A stdClass instance + */ + protected function getBARService() + { + $this->services['BAR'] = $instance = new \stdClass(); + + $instance->bar = ($this->services['bar'] ?? $this->get('bar')); + + return $instance; + } + + /** + * Gets the 'BAR2' service. + * + * This service is shared. + * This method always returns the same instance of the service. + * + * @return \stdClass A stdClass instance + */ + protected function getBAR2Service() + { + return $this->services['BAR2'] = new \stdClass(); + } + /** * Gets the 'bar' service. * @@ -80,7 +113,7 @@ public function isCompiled() * * @return \Bar\FooClass A Bar\FooClass instance */ - protected function getBarService() + protected function getBar3Service() { $a = ($this->services['foo.baz'] ?? $this->get('foo.baz')); @@ -91,6 +124,19 @@ protected function getBarService() return $instance; } + /** + * Gets the 'bar2' service. + * + * This service is shared. + * This method always returns the same instance of the service. + * + * @return \stdClass A stdClass instance + */ + protected function getBar22Service() + { + return $this->services['bar2'] = new \stdClass(); + } + /** * Gets the 'baz' service. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php index 81506dae44a0d..1d852fab35a58 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php @@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container public function __construct() { $this->services = array(); - $this->normalizedIds = array( - 'autowired.symfony\\component\\dependencyinjection\\tests\\fixtures\\customdefinition' => 'autowired.Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', - 'symfony\\component\\dependencyinjection\\tests\\fixtures\\testservicesubscriber' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber', - ); $this->methodMap = array( 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => 'getSymfony_Component_DependencyInjection_Tests_Fixtures_TestServiceSubscriberService', 'autowired.Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => 'getAutowired_Symfony_Component_DependencyInjection_Tests_Fixtures_CustomDefinitionService', diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml index 100a23a9c5b7e..5f46821a0f90e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml @@ -130,6 +130,11 @@ + + + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_case.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_case.xml new file mode 100644 index 0000000000000..31fea2eb260ad --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_case.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml index a7a9cc28fd61b..e91fbb208c1ae 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml @@ -116,6 +116,13 @@ services: lazy_context_ignore_invalid_ref: class: LazyContext arguments: [!iterator ['@foo.baz', '@?invalid'], !iterator []] + BAR: + class: stdClass + properties: { bar: '@bar' } + bar2: + class: stdClass + BAR2: + class: stdClass alias_for_foo: '@foo' alias_for_alias: '@foo' Psr\Container\ContainerInterface: diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_case.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_case.yml new file mode 100644 index 0000000000000..cbf158659cfd7 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_case.yml @@ -0,0 +1,10 @@ +services: + bar: + class: stdClass + Bar: + class: stdClass + properties: { bar: '@bar' } + BAR: + class: Bar\FooClass + arguments: ['@Bar'] + calls: [[setBar, ['@bar']]] diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php index a242898526537..e2ebd090ebefe 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -756,6 +756,21 @@ public function testAutoConfigureInstanceof() $this->assertTrue($container->getDefinition('use_defaults_settings')->isAutoconfigured()); $this->assertFalse($container->getDefinition('override_defaults_settings_to_false')->isAutoconfigured()); } + + public function testCaseSensitivity() + { + $container = new ContainerBuilder(); + $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); + $loader->load('services_case.xml'); + $container->compile(); + + $this->assertTrue($container->has('bar')); + $this->assertTrue($container->has('BAR')); + $this->assertFalse($container->has('baR')); + $this->assertNotSame($container->get('BAR'), $container->get('bar')); + $this->assertSame($container->get('BAR')->arguments->bar, $container->get('bar')); + $this->assertSame($container->get('BAR')->bar, $container->get('bar')); + } } interface BarInterface diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 622bacf6944db..98382e84dec4f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -624,6 +624,21 @@ public function testUnsupportedKeywordInServiceAliasThrowsException() $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('bad_alias.yml'); } + + public function testCaseSensitivity() + { + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('services_case.yml'); + $container->compile(); + + $this->assertTrue($container->has('bar')); + $this->assertTrue($container->has('BAR')); + $this->assertFalse($container->has('baR')); + $this->assertNotSame($container->get('BAR'), $container->get('bar')); + $this->assertSame($container->get('BAR')->arguments->bar, $container->get('bar')); + $this->assertSame($container->get('BAR')->bar, $container->get('bar')); + } } interface FooInterface