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