[DependencyInjection] fixed inheritence when using extensions
This commit is contained in:
parent
733c5d5a09
commit
0e3b88a058
|
@ -53,12 +53,6 @@ class XmlFileLoader extends FileLoader
|
|||
// imports
|
||||
$this->parseImports($configuration, $xml, $file);
|
||||
|
||||
// parameters
|
||||
$this->parseParameters($configuration, $xml, $file);
|
||||
|
||||
// services
|
||||
$this->parseDefinitions($configuration, $xml, $file);
|
||||
|
||||
// extensions
|
||||
$this->loadFromExtensions($configuration, $xml);
|
||||
|
||||
|
@ -66,6 +60,12 @@ class XmlFileLoader extends FileLoader
|
|||
$configuration->mergeExtensionsConfiguration();
|
||||
}
|
||||
|
||||
// parameters
|
||||
$this->parseParameters($configuration, $xml, $file);
|
||||
|
||||
// services
|
||||
$this->parseDefinitions($configuration, $xml, $file);
|
||||
|
||||
return $configuration;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,13 @@ class YamlFileLoader extends FileLoader
|
|||
// imports
|
||||
$this->parseImports($configuration, $content, $file);
|
||||
|
||||
// extensions
|
||||
$this->loadFromExtensions($configuration, $content);
|
||||
|
||||
if ($main) {
|
||||
$configuration->mergeExtensionsConfiguration();
|
||||
}
|
||||
|
||||
// parameters
|
||||
if (isset($content['parameters'])) {
|
||||
foreach ($content['parameters'] as $key => $value) {
|
||||
|
@ -67,13 +74,6 @@ class YamlFileLoader extends FileLoader
|
|||
// services
|
||||
$this->parseDefinitions($configuration, $content, $file);
|
||||
|
||||
// extensions
|
||||
$this->loadFromExtensions($configuration, $content);
|
||||
|
||||
if ($main) {
|
||||
$configuration->mergeExtensionsConfiguration();
|
||||
}
|
||||
|
||||
return $configuration;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,6 @@ class LoaderExtensionTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
$config = $extension->load('bar', array('foo' => 'bar'), new BuilderConfiguration());
|
||||
$this->assertEquals(array('project.parameter.bar' => 'bar'), $config->getParameters(), '->load() calls the method tied to the given tag');
|
||||
$this->assertEquals(array('project.parameter.bar' => 'bar', 'project.parameter.foo' => 'bar'), $config->getParameters(), '->load() calls the method tied to the given tag');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,9 +166,13 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||
$config = $loader->load('services10.xml');
|
||||
$services = $config->getDefinitions();
|
||||
$parameters = $config->getParameters();
|
||||
|
||||
$this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements');
|
||||
$this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements');
|
||||
|
||||
$this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
|
||||
$this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
|
||||
|
||||
try {
|
||||
$config = $loader->load('services11.xml');
|
||||
$this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
|
||||
|
|
|
@ -107,9 +107,13 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||
$config = $loader->load('services10.yml');
|
||||
$services = $config->getDefinitions();
|
||||
$parameters = $config->getParameters();
|
||||
|
||||
$this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements');
|
||||
$this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements');
|
||||
|
||||
$this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
|
||||
$this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
|
||||
|
||||
try {
|
||||
$config = $loader->load('services11.yml');
|
||||
$this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
|
||||
|
|
|
@ -11,6 +11,9 @@ class ProjectExtension extends LoaderExtension
|
|||
$configuration->setDefinition('project.service.bar', new Definition('FooClass'));
|
||||
$configuration->setParameter('project.parameter.bar', isset($config['foo']) ? $config['foo'] : 'foobar');
|
||||
|
||||
$configuration->setDefinition('project.service.foo', new Definition('FooClass'));
|
||||
$configuration->setParameter('project.parameter.foo', isset($config['foo']) ? $config['foo'] : 'foobar');
|
||||
|
||||
return $configuration;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,14 @@
|
|||
<container xmlns="http://www.symfony-project.org/schema/dic/services"
|
||||
xmlns:project="http://www.example.com/schema/project">
|
||||
|
||||
<project:bar />
|
||||
<parameters>
|
||||
<parameter key="project.parameter.foo">BAR</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="project.service.foo" class="BAR" />
|
||||
</services>
|
||||
|
||||
<project:bar />
|
||||
|
||||
</container>
|
||||
|
|
|
@ -1 +1,8 @@
|
|||
parameters:
|
||||
project.parameter.foo: BAR
|
||||
|
||||
services:
|
||||
project.service.foo:
|
||||
class: BAR
|
||||
|
||||
project.bar: ~
|
||||
|
|
Reference in New Issue