feature #22811 [DI] Remove deprecated case insensitive service ids (ro0NL)

This PR was squashed before being merged into the 4.0-dev branch (closes #22811).

Discussion
----------

[DI] Remove deprecated case insensitive service ids

| 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 #21223

Commits
-------

63e26fc [DI] Remove deprecated case insensitive service ids
This commit is contained in:
Nicolas Grekas 2017-07-11 16:01:01 +02:00
commit a55cbf83c0
21 changed files with 267 additions and 235 deletions

View File

@ -49,9 +49,6 @@ abstract class ManagerRegistry extends AbstractManagerRegistry implements Contai
}
$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];
}

View File

@ -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
-----

View File

@ -26,26 +26,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
*
* 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:
*
* <ul>
* <li>request</li>
* <li>mysql_session_storage</li>
* <li>symfony.mysql_session_storage</li>
* </ul>
*
* A service can also be defined by creating a method named
* getXXXService(), where XXX is the camelized version of the id:
*
* <ul>
* <li>request -> getRequestService()</li>
* <li>mysql_session_storage -> getMysqlSessionStorageService()</li>
* <li>symfony.mysql_session_storage -> getSymfony_MysqlSessionStorageService()</li>
* </ul>
* 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 @@ class Container implements ResettableContainerInterface
*/
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 @@ class Container implements ResettableContainerInterface
*/
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;
}
return false;
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;
}
return false;
}
/**
@ -258,69 +225,60 @@ class Container implements ResettableContainerInterface
*/
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);
}
$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);
if (isset($this->methodMap[$id])) {
$method = $this->methodMap[$id];
} else {
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
if (!$id) {
throw new ServiceNotFoundException($id);
}
return;
$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);
}
$this->loading[$id] = true;
try {
$service = $this->$method();
} catch (\Exception $e) {
unset($this->services[$id]);
throw $e;
} finally {
unset($this->loading[$id]);
}
return $service;
return;
}
$this->loading[$id] = true;
try {
$service = $this->$method();
} catch (\Exception $e) {
unset($this->services[$id]);
throw $e;
} finally {
unset($this->loading[$id]);
}
return $service;
}
/**
@ -332,8 +290,6 @@ class Container implements ResettableContainerInterface
*/
public function initialized($id)
{
$id = $this->normalizeId($id);
if ('service_container' === $id) {
return false;
}
@ -418,32 +374,6 @@ class Container implements ResettableContainerInterface
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()
{
}

View File

@ -485,8 +485,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
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 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
public function removeDefinition($id)
{
unset($this->definitions[$this->normalizeId($id)]);
unset($this->definitions[$id]);
}
/**
@ -516,8 +514,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
public function has($id)
{
$id = $this->normalizeId($id);
return isset($this->definitions[$id]) || isset($this->aliasDefinitions[$id]) || parent::has($id);
}
@ -538,8 +534,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
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 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
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 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
public function removeAlias($alias)
{
unset($this->aliasDefinitions[$this->normalizeId($alias)]);
unset($this->aliasDefinitions[$alias]);
}
/**
@ -798,7 +790,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
public function hasAlias($id)
{
return isset($this->aliasDefinitions[$this->normalizeId($id)]);
return isset($this->aliasDefinitions[$id]);
}
/**
@ -822,8 +814,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
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 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
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 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
public function hasDefinition($id)
{
return isset($this->definitions[$this->normalizeId($id)]);
return isset($this->definitions[$id]);
}
/**
@ -942,8 +930,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
public function getDefinition($id)
{
$id = $this->normalizeId($id);
if (!isset($this->definitions[$id])) {
throw new ServiceNotFoundException($id);
}
@ -964,8 +950,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
public function findDefinition($id)
{
$id = $this->normalizeId($id);
while (isset($this->aliasDefinitions[$id])) {
$id = (string) $this->aliasDefinitions[$id];
}
@ -1311,22 +1295,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
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 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
private function shareService(Definition $definition, $service, $id)
{
if (null !== $id && $definition->isShared()) {
$this->services[$this->normalizeId($id)] = $service;
$this->services[$id] = $service;
}
}

View File

@ -281,7 +281,7 @@ class GraphvizDumper extends Dumper
*/
private function dotize($id)
{
return strtolower(preg_replace('/\W/i', '_', $id));
return preg_replace('/\W/i', '_', $id);
}
/**

View File

@ -826,7 +826,6 @@ EOF;
}
$code .= "\n \$this->services = array();\n";
$code .= $this->addNormalizedIds();
$code .= $this->addMethodMap();
$code .= $this->addPrivateServices();
$code .= $this->addAliases();
@ -879,25 +878,6 @@ EOF;
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.
*

View File

@ -1082,6 +1082,21 @@ class ContainerBuilderTest extends TestCase
// 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

View File

@ -193,26 +193,15 @@ class ContainerTest extends TestCase
$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()

View File

@ -55,12 +55,6 @@ class CrossCheckTest extends TestCase
$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();

View File

@ -139,5 +139,11 @@ $container
->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;

View File

@ -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"];
}

View File

@ -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',
);

View File

@ -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 @@ class ProjectServiceContainer extends Container
);
}
/**
* 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 @@ class ProjectServiceContainer extends Container
*
* @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 @@ class ProjectServiceContainer extends Container
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.
*

View File

@ -30,7 +30,10 @@ class ProjectServiceContainer extends Container
$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 @@ class ProjectServiceContainer extends Container
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 @@ class ProjectServiceContainer extends Container
*
* @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 @@ class ProjectServiceContainer extends Container
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.
*

View File

@ -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',

View File

@ -130,6 +130,11 @@
</argument>
<argument type="iterator"/>
</service>
<service id="BAR" class="stdClass">
<property name="bar" type="service" id="bar"/>
</service>
<service id="bar2" class="stdClass"/>
<service id="BAR2" class="stdClass"/>
<service id="Psr\Container\ContainerInterface" alias="service_container" public="false"/>
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false"/>
<service id="alias_for_foo" alias="foo"/>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="bar" class="stdClass"/>
<service id="Bar" class="stdClass">
<property name="bar" type="service" id="bar"/>
</service>
<service id="BAR" class="Bar\FooClass">
<argument type="service" id="Bar"/>
<call method="setBar">
<argument type="service" id="bar"/>
</call>
</service>
</services>
</container>

View File

@ -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:

View File

@ -0,0 +1,10 @@
services:
bar:
class: stdClass
Bar:
class: stdClass
properties: { bar: '@bar' }
BAR:
class: Bar\FooClass
arguments: ['@Bar']
calls: [[setBar, ['@bar']]]

View File

@ -756,6 +756,21 @@ class XmlFileLoaderTest extends TestCase
$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

View File

@ -624,6 +624,21 @@ class YamlFileLoaderTest extends TestCase
$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