Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 additions and 0 deletions

View file

@ -0,0 +1,146 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class AnalyzeServiceReferencesPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$a = $container
->register('a')
->addArgument($ref1 = new Reference('b'))
;
$b = $container
->register('b')
->addMethodCall('setA', array($ref2 = new Reference('a')))
;
$c = $container
->register('c')
->addArgument($ref3 = new Reference('a'))
->addArgument($ref4 = new Reference('b'))
;
$d = $container
->register('d')
->setProperty('foo', $ref5 = new Reference('b'))
;
$e = $container
->register('e')
->setConfigurator(array($ref6 = new Reference('b'), 'methodName'))
;
$graph = $this->process($container);
$this->assertCount(4, $edges = $graph->getNode('b')->getInEdges());
$this->assertSame($ref1, $edges[0]->getValue());
$this->assertSame($ref4, $edges[1]->getValue());
$this->assertSame($ref5, $edges[2]->getValue());
$this->assertSame($ref6, $edges[3]->getValue());
}
public function testProcessDetectsReferencesFromInlinedDefinitions()
{
$container = new ContainerBuilder();
$container
->register('a')
;
$container
->register('b')
->addArgument(new Definition(null, array($ref = new Reference('a'))))
;
$graph = $this->process($container);
$this->assertCount(1, $refs = $graph->getNode('a')->getInEdges());
$this->assertSame($ref, $refs[0]->getValue());
}
public function testProcessDetectsReferencesFromInlinedFactoryDefinitions()
{
$container = new ContainerBuilder();
$container
->register('a')
;
$factory = new Definition();
$factory->setFactory(array(new Reference('a'), 'a'));
$container
->register('b')
->addArgument($factory)
;
$graph = $this->process($container);
$this->assertTrue($graph->hasNode('a'));
$this->assertCount(1, $refs = $graph->getNode('a')->getInEdges());
}
public function testProcessDoesNotSaveDuplicateReferences()
{
$container = new ContainerBuilder();
$container
->register('a')
;
$container
->register('b')
->addArgument(new Definition(null, array($ref1 = new Reference('a'))))
->addArgument(new Definition(null, array($ref2 = new Reference('a'))))
;
$graph = $this->process($container);
$this->assertCount(2, $graph->getNode('a')->getInEdges());
}
public function testProcessDetectsFactoryReferences()
{
$container = new ContainerBuilder();
$container
->register('foo', 'stdClass')
->setFactory(array('stdClass', 'getInstance'));
$container
->register('bar', 'stdClass')
->setFactory(array(new Reference('foo'), 'getInstance'));
$graph = $this->process($container);
$this->assertTrue($graph->hasNode('foo'));
$this->assertCount(1, $graph->getNode('foo')->getInEdges());
}
protected function process(ContainerBuilder $container)
{
$pass = new RepeatedPass(array(new AnalyzeServiceReferencesPass()));
$pass->process($container);
return $container->getCompiler()->getServiceReferenceGraph();
}
}

View file

@ -0,0 +1,103 @@
<?php
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Compiler\AutoAliasServicePass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class AutoAliasServicePassTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException
*/
public function testProcessWithMissingParameter()
{
$container = new ContainerBuilder();
$container->register('example')
->addTag('auto_alias', array('format' => '%non_existing%.example'));
$pass = new AutoAliasServicePass();
$pass->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testProcessWithMissingFormat()
{
$container = new ContainerBuilder();
$container->register('example')
->addTag('auto_alias', array());
$container->setParameter('existing', 'mysql');
$pass = new AutoAliasServicePass();
$pass->process($container);
}
public function testProcessWithNonExistingAlias()
{
$container = new ContainerBuilder();
$container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault')
->addTag('auto_alias', array('format' => '%existing%.example'));
$container->setParameter('existing', 'mysql');
$pass = new AutoAliasServicePass();
$pass->process($container);
$this->assertEquals('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault', $container->getDefinition('example')->getClass());
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault', $container->get('example'));
}
public function testProcessWithExistingAlias()
{
$container = new ContainerBuilder();
$container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault')
->addTag('auto_alias', array('format' => '%existing%.example'));
$container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql');
$container->setParameter('existing', 'mysql');
$pass = new AutoAliasServicePass();
$pass->process($container);
$this->assertTrue($container->hasAlias('example'));
$this->assertEquals('mysql.example', $container->getAlias('example'));
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql', $container->get('example'));
}
public function testProcessWithManualAlias()
{
$container = new ContainerBuilder();
$container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault')
->addTag('auto_alias', array('format' => '%existing%.example'));
$container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql');
$container->register('mariadb.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariadb');
$container->setAlias('example', 'mariadb.example');
$container->setParameter('existing', 'mysql');
$pass = new AutoAliasServicePass();
$pass->process($container);
$this->assertTrue($container->hasAlias('example'));
$this->assertEquals('mariadb.example', $container->getAlias('example'));
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariaDb', $container->get('example'));
}
}
class ServiceClassDefault
{
}
class ServiceClassMysql extends ServiceClassDefault
{
}
class ServiceClassMariaDb extends ServiceClassMysql
{
}

View file

@ -0,0 +1,130 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\CheckCircularReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testProcess()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container->register('b')->addArgument(new Reference('a'));
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testProcessWithAliases()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container->setAlias('b', 'c');
$container->setAlias('c', 'a');
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testProcessWithFactory()
{
$container = new ContainerBuilder();
$container
->register('a', 'stdClass')
->setFactory(array(new Reference('b'), 'getInstance'));
$container
->register('b', 'stdClass')
->setFactory(array(new Reference('a'), 'getInstance'));
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testProcessDetectsIndirectCircularReference()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container->register('b')->addArgument(new Reference('c'));
$container->register('c')->addArgument(new Reference('a'));
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testProcessDetectsIndirectCircularReferenceWithFactory()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container
->register('b', 'stdClass')
->setFactory(array(new Reference('c'), 'getInstance'));
$container->register('c')->addArgument(new Reference('a'));
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testDeepCircularReference()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container->register('b')->addArgument(new Reference('c'));
$container->register('c')->addArgument(new Reference('b'));
$this->process($container);
}
public function testProcessIgnoresMethodCalls()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container->register('b')->addMethodCall('setA', array(new Reference('a')));
$this->process($container);
}
protected function process(ContainerBuilder $container)
{
$compiler = new Compiler();
$passConfig = $compiler->getPassConfig();
$passConfig->setOptimizationPasses(array(
new AnalyzeServiceReferencesPass(true),
new CheckCircularReferencesPass(),
));
$passConfig->setRemovingPasses(array());
$compiler->compile($container);
}
}

View file

@ -0,0 +1,105 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class CheckDefinitionValidityPassTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
*/
public function testProcessDetectsSyntheticNonPublicDefinitions()
{
$container = new ContainerBuilder();
$container->register('a')->setSynthetic(true)->setPublic(false);
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
*/
public function testProcessDetectsSyntheticPrototypeDefinitions()
{
$container = new ContainerBuilder();
$container->register('a')->setSynthetic(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
*/
public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
{
$container = new ContainerBuilder();
$container->register('a')->setSynthetic(false)->setAbstract(false);
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @group legacy
*/
public function testLegacyProcessDetectsBothFactorySyntaxesUsed()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$container = new ContainerBuilder();
$container->register('a')->setFactory(array('a', 'b'))->setFactoryClass('a');
$this->process($container);
}
public function testProcess()
{
$container = new ContainerBuilder();
$container->register('a', 'class');
$container->register('b', 'class')->setSynthetic(true)->setPublic(true);
$container->register('c', 'class')->setAbstract(true);
$container->register('d', 'class')->setSynthetic(true);
$this->process($container);
}
public function testValidTags()
{
$container = new ContainerBuilder();
$container->register('a', 'class')->addTag('foo', array('bar' => 'baz'));
$container->register('b', 'class')->addTag('foo', array('bar' => null));
$container->register('c', 'class')->addTag('foo', array('bar' => 1));
$container->register('d', 'class')->addTag('foo', array('bar' => 1.1));
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
*/
public function testInvalidTags()
{
$container = new ContainerBuilder();
$container->register('a', 'class')->addTag('foo', array('bar' => array('baz' => 'baz')));
$this->process($container);
}
protected function process(ContainerBuilder $container)
{
$pass = new CheckDefinitionValidityPass();
$pass->process($container);
}
}

View file

@ -0,0 +1,70 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class CheckExceptionOnInvalidReferenceBehaviorPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$container
->register('a', '\stdClass')
->addArgument(new Reference('b'))
;
$container->register('b', '\stdClass');
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
*/
public function testProcessThrowsExceptionOnInvalidReference()
{
$container = new ContainerBuilder();
$container
->register('a', '\stdClass')
->addArgument(new Reference('b'))
;
$this->process($container);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
*/
public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinition()
{
$container = new ContainerBuilder();
$def = new Definition();
$def->addArgument(new Reference('b'));
$container
->register('a', '\stdClass')
->addArgument($def)
;
$this->process($container);
}
private function process(ContainerBuilder $container)
{
$pass = new CheckExceptionOnInvalidReferenceBehaviorPass();
$pass->process($container);
}
}

View file

@ -0,0 +1,97 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\DependencyInjection\Compiler\CheckReferenceValidityPass;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class CheckReferenceValidityPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcessIgnoresScopeWideningIfNonStrictReference()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false));
$container->register('b')->setScope('prototype');
$this->process($container);
}
/**
* @expectedException \RuntimeException
*/
public function testProcessDetectsScopeWidening()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container->register('b')->setScope('prototype');
$this->process($container);
}
public function testProcessIgnoresCrossScopeHierarchyReferenceIfNotStrict()
{
$container = new ContainerBuilder();
$container->addScope(new Scope('a'));
$container->addScope(new Scope('b'));
$container->register('a')->setScope('a')->addArgument(new Reference('b', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false));
$container->register('b')->setScope('b');
$this->process($container);
}
/**
* @expectedException \RuntimeException
*/
public function testProcessDetectsCrossScopeHierarchyReference()
{
$container = new ContainerBuilder();
$container->addScope(new Scope('a'));
$container->addScope(new Scope('b'));
$container->register('a')->setScope('a')->addArgument(new Reference('b'));
$container->register('b')->setScope('b');
$this->process($container);
}
/**
* @expectedException \RuntimeException
*/
public function testProcessDetectsReferenceToAbstractDefinition()
{
$container = new ContainerBuilder();
$container->register('a')->setAbstract(true);
$container->register('b')->addArgument(new Reference('a'));
$this->process($container);
}
public function testProcess()
{
$container = new ContainerBuilder();
$container->register('a')->addArgument(new Reference('b'));
$container->register('b');
$this->process($container);
}
protected function process(ContainerBuilder $container)
{
$pass = new CheckReferenceValidityPass();
$pass->process($container);
}
}

View file

@ -0,0 +1,81 @@
<?php
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\DecoratorServicePass;
class DecoratorServicePassTest extends \PHPUnit_Framework_TestCase
{
public function testProcessWithoutAlias()
{
$container = new ContainerBuilder();
$fooDefinition = $container
->register('foo')
->setPublic(false)
;
$fooExtendedDefinition = $container
->register('foo.extended')
->setPublic(true)
->setDecoratedService('foo')
;
$barDefinition = $container
->register('bar')
->setPublic(true)
;
$barExtendedDefinition = $container
->register('bar.extended')
->setPublic(true)
->setDecoratedService('bar', 'bar.yoo')
;
$this->process($container);
$this->assertEquals('foo.extended', $container->getAlias('foo'));
$this->assertFalse($container->getAlias('foo')->isPublic());
$this->assertEquals('bar.extended', $container->getAlias('bar'));
$this->assertTrue($container->getAlias('bar')->isPublic());
$this->assertSame($fooDefinition, $container->getDefinition('foo.extended.inner'));
$this->assertFalse($container->getDefinition('foo.extended.inner')->isPublic());
$this->assertSame($barDefinition, $container->getDefinition('bar.yoo'));
$this->assertFalse($container->getDefinition('bar.yoo')->isPublic());
$this->assertNull($fooExtendedDefinition->getDecoratedService());
$this->assertNull($barExtendedDefinition->getDecoratedService());
}
public function testProcessWithAlias()
{
$container = new ContainerBuilder();
$container
->register('foo')
->setPublic(true)
;
$container->setAlias('foo.alias', new Alias('foo', false));
$fooExtendedDefinition = $container
->register('foo.extended')
->setPublic(true)
->setDecoratedService('foo.alias')
;
$this->process($container);
$this->assertEquals('foo.extended', $container->getAlias('foo.alias'));
$this->assertFalse($container->getAlias('foo.alias')->isPublic());
$this->assertEquals('foo', $container->getAlias('foo.extended.inner'));
$this->assertFalse($container->getAlias('foo.extended.inner')->isPublic());
$this->assertNull($fooExtendedDefinition->getDecoratedService());
}
protected function process(ContainerBuilder $container)
{
$repeatedPass = new DecoratorServicePass();
$repeatedPass->process($container);
}
}

View file

@ -0,0 +1,245 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class InlineServiceDefinitionsPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$container
->register('inlinable.service')
->setPublic(false)
;
$container
->register('service')
->setArguments(array(new Reference('inlinable.service')))
;
$this->process($container);
$arguments = $container->getDefinition('service')->getArguments();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Definition', $arguments[0]);
$this->assertSame($container->getDefinition('inlinable.service'), $arguments[0]);
}
public function testProcessDoesNotInlineWhenAliasedServiceIsNotOfPrototypeScope()
{
$container = new ContainerBuilder();
$container
->register('foo')
->setPublic(false)
;
$container->setAlias('moo', 'foo');
$container
->register('service')
->setArguments(array($ref = new Reference('foo')))
;
$this->process($container);
$arguments = $container->getDefinition('service')->getArguments();
$this->assertSame($ref, $arguments[0]);
}
public function testProcessDoesInlineServiceOfPrototypeScope()
{
$container = new ContainerBuilder();
$container
->register('foo')
->setScope('prototype')
;
$container
->register('bar')
->setPublic(false)
->setScope('prototype')
;
$container->setAlias('moo', 'bar');
$container
->register('service')
->setArguments(array(new Reference('foo'), $ref = new Reference('moo'), new Reference('bar')))
;
$this->process($container);
$arguments = $container->getDefinition('service')->getArguments();
$this->assertEquals($container->getDefinition('foo'), $arguments[0]);
$this->assertNotSame($container->getDefinition('foo'), $arguments[0]);
$this->assertSame($ref, $arguments[1]);
$this->assertEquals($container->getDefinition('bar'), $arguments[2]);
$this->assertNotSame($container->getDefinition('bar'), $arguments[2]);
}
public function testProcessInlinesIfMultipleReferencesButAllFromTheSameDefinition()
{
$container = new ContainerBuilder();
$a = $container->register('a')->setPublic(false);
$b = $container
->register('b')
->addArgument(new Reference('a'))
->addArgument(new Definition(null, array(new Reference('a'))))
;
$this->process($container);
$arguments = $b->getArguments();
$this->assertSame($a, $arguments[0]);
$inlinedArguments = $arguments[1]->getArguments();
$this->assertSame($a, $inlinedArguments[0]);
}
public function testProcessInlinesPrivateFactoryReference()
{
$container = new ContainerBuilder();
$container->register('a')->setPublic(false);
$b = $container
->register('b')
->setPublic(false)
->setFactory(array(new Reference('a'), 'a'))
;
$container
->register('foo')
->setArguments(array(
$ref = new Reference('b'),
));
$this->process($container);
$inlinedArguments = $container->getDefinition('foo')->getArguments();
$this->assertSame($b, $inlinedArguments[0]);
}
public function testProcessDoesNotInlinePrivateFactoryIfReferencedMultipleTimesWithinTheSameDefinition()
{
$container = new ContainerBuilder();
$container
->register('a')
;
$container
->register('b')
->setPublic(false)
->setFactory(array(new Reference('a'), 'a'))
;
$container
->register('foo')
->setArguments(array(
$ref1 = new Reference('b'),
$ref2 = new Reference('b'),
))
;
$this->process($container);
$args = $container->getDefinition('foo')->getArguments();
$this->assertSame($ref1, $args[0]);
$this->assertSame($ref2, $args[1]);
}
public function testProcessDoesNotInlineReferenceWhenUsedByInlineFactory()
{
$container = new ContainerBuilder();
$container
->register('a')
;
$container
->register('b')
->setPublic(false)
->setFactory(array(new Reference('a'), 'a'))
;
$inlineFactory = new Definition();
$inlineFactory->setPublic(false);
$inlineFactory->setFactory(array(new Reference('b'), 'b'));
$container
->register('foo')
->setArguments(array(
$ref = new Reference('b'),
$inlineFactory,
))
;
$this->process($container);
$args = $container->getDefinition('foo')->getArguments();
$this->assertSame($ref, $args[0]);
}
public function testProcessInlinesOnlyIfSameScope()
{
$container = new ContainerBuilder();
$container->addScope(new Scope('foo'));
$a = $container->register('a')->setPublic(false)->setScope('foo');
$b = $container->register('b')->addArgument(new Reference('a'));
$this->process($container);
$arguments = $b->getArguments();
$this->assertEquals(new Reference('a'), $arguments[0]);
$this->assertTrue($container->hasDefinition('a'));
}
public function testProcessDoesNotInlineWhenServiceIsPrivateButLazy()
{
$container = new ContainerBuilder();
$container
->register('foo')
->setPublic(false)
->setLazy(true)
;
$container
->register('service')
->setArguments(array($ref = new Reference('foo')))
;
$this->process($container);
$arguments = $container->getDefinition('service')->getArguments();
$this->assertSame($ref, $arguments[0]);
}
public function testProcessDoesNotInlineWhenServiceReferencesItself()
{
$container = new ContainerBuilder();
$container
->register('foo')
->setPublic(false)
->addMethodCall('foo', array($ref = new Reference('foo')))
;
$this->process($container);
$calls = $container->getDefinition('foo')->getMethodCalls();
$this->assertSame($ref, $calls[0][1][0]);
}
protected function process(ContainerBuilder $container)
{
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));
$repeatedPass->process($container);
}
}

View file

@ -0,0 +1,116 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* This class tests the integration of the different compiler passes.
*/
class IntegrationTest extends \PHPUnit_Framework_TestCase
{
/**
* This tests that dependencies are correctly processed.
*
* We're checking that:
*
* * A is public, B/C are private
* * A -> C
* * B -> C
*/
public function testProcessRemovesAndInlinesRecursively()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$a = $container
->register('a', '\stdClass')
->addArgument(new Reference('c'))
;
$b = $container
->register('b', '\stdClass')
->addArgument(new Reference('c'))
->setPublic(false)
;
$c = $container
->register('c', '\stdClass')
->setPublic(false)
;
$container->compile();
$this->assertTrue($container->hasDefinition('a'));
$arguments = $a->getArguments();
$this->assertSame($c, $arguments[0]);
$this->assertFalse($container->hasDefinition('b'));
$this->assertFalse($container->hasDefinition('c'));
}
public function testProcessInlinesReferencesToAliases()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$a = $container
->register('a', '\stdClass')
->addArgument(new Reference('b'))
;
$container->setAlias('b', new Alias('c', false));
$c = $container
->register('c', '\stdClass')
->setPublic(false)
;
$container->compile();
$this->assertTrue($container->hasDefinition('a'));
$arguments = $a->getArguments();
$this->assertSame($c, $arguments[0]);
$this->assertFalse($container->hasAlias('b'));
$this->assertFalse($container->hasDefinition('c'));
}
public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDefinition()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container
->register('a', '\stdClass')
->addArgument(new Reference('b'))
->addMethodCall('setC', array(new Reference('c')))
;
$container
->register('b', '\stdClass')
->addArgument(new Reference('c'))
->setPublic(false)
;
$container
->register('c', '\stdClass')
->setPublic(false)
;
$container->compile();
$this->assertTrue($container->hasDefinition('a'));
$this->assertFalse($container->hasDefinition('b'));
$this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.');
}
}

View file

@ -0,0 +1,37 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @group legacy
*/
class LegacyResolveParameterPlaceHoldersPassTest extends \PHPUnit_Framework_TestCase
{
public function testFactoryClassParametersShouldBeResolved()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$compilerPass = new ResolveParameterPlaceHoldersPass();
$container = new ContainerBuilder();
$container->setParameter('foo.factory.class', 'FooFactory');
$fooDefinition = $container->register('foo', '%foo.factory.class%');
$fooDefinition->setFactoryClass('%foo.factory.class%');
$compilerPass->process($container);
$fooDefinition = $container->getDefinition('foo');
$this->assertSame('FooFactory', $fooDefinition->getFactoryClass());
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class MergeExtensionConfigurationPassTest extends \PHPUnit_Framework_TestCase
{
public function testExpressionLanguageProviderForwarding()
{
if (true !== class_exists('Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage')) {
$this->markTestSkipped('The ExpressionLanguage component isn\'t available!');
}
$tmpProviders = array();
$extension = $this->getMock('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface');
$extension->expects($this->any())
->method('getXsdValidationBasePath')
->will($this->returnValue(false));
$extension->expects($this->any())
->method('getNamespace')
->will($this->returnValue('http://example.org/schema/dic/foo'));
$extension->expects($this->any())
->method('getAlias')
->will($this->returnValue('foo'));
$extension->expects($this->once())
->method('load')
->will($this->returnCallback(function (array $config, ContainerBuilder $container) use (&$tmpProviders) {
$tmpProviders = $container->getExpressionLanguageProviders();
}));
$provider = $this->getMock('Symfony\\Component\\ExpressionLanguage\\ExpressionFunctionProviderInterface');
$container = new ContainerBuilder(new ParameterBag());
$container->registerExtension($extension);
$container->prependExtensionConfig('foo', array('bar' => true ));
$container->addExpressionLanguageProvider($provider);
$pass = new MergeExtensionConfigurationPass();
$pass->process($container);
$this->assertEquals(array($provider), $tmpProviders);
}
}

View file

@ -0,0 +1,113 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
use Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class RemoveUnusedDefinitionsPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$container
->register('foo')
->setPublic(false)
;
$container
->register('bar')
->setPublic(false)
;
$container
->register('moo')
->setArguments(array(new Reference('bar')))
;
$this->process($container);
$this->assertFalse($container->hasDefinition('foo'));
$this->assertTrue($container->hasDefinition('bar'));
$this->assertTrue($container->hasDefinition('moo'));
}
public function testProcessRemovesUnusedDefinitionsRecursively()
{
$container = new ContainerBuilder();
$container
->register('foo')
->setPublic(false)
;
$container
->register('bar')
->setArguments(array(new Reference('foo')))
->setPublic(false)
;
$this->process($container);
$this->assertFalse($container->hasDefinition('foo'));
$this->assertFalse($container->hasDefinition('bar'));
}
public function testProcessWorksWithInlinedDefinitions()
{
$container = new ContainerBuilder();
$container
->register('foo')
->setPublic(false)
;
$container
->register('bar')
->setArguments(array(new Definition(null, array(new Reference('foo')))))
;
$this->process($container);
$this->assertTrue($container->hasDefinition('foo'));
$this->assertTrue($container->hasDefinition('bar'));
}
public function testProcessWontRemovePrivateFactory()
{
$container = new ContainerBuilder();
$container
->register('foo', 'stdClass')
->setFactory(array('stdClass', 'getInstance'))
->setPublic(false);
$container
->register('bar', 'stdClass')
->setFactory(array(new Reference('foo'), 'getInstance'))
->setPublic(false);
$container
->register('foobar')
->addArgument(new Reference('bar'));
$this->process($container);
$this->assertTrue($container->hasDefinition('foo'));
$this->assertTrue($container->hasDefinition('bar'));
$this->assertTrue($container->hasDefinition('foobar'));
}
protected function process(ContainerBuilder $container)
{
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new RemoveUnusedDefinitionsPass()));
$repeatedPass->process($container);
}
}

View file

@ -0,0 +1,59 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$container->register('a', '\stdClass');
$bDefinition = new Definition('\stdClass');
$bDefinition->setPublic(false);
$container->setDefinition('b', $bDefinition);
$container->setAlias('a_alias', 'a');
$container->setAlias('b_alias', 'b');
$this->process($container);
$this->assertTrue($container->has('a'), '->process() does nothing to public definitions.');
$this->assertTrue($container->hasAlias('a_alias'));
$this->assertFalse($container->has('b'), '->process() removes non-public definitions.');
$this->assertTrue(
$container->has('b_alias') && !$container->hasAlias('b_alias'),
'->process() replaces alias to actual.'
);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testProcessWithInvalidAlias()
{
$container = new ContainerBuilder();
$container->setAlias('a_alias', 'a');
$this->process($container);
}
protected function process(ContainerBuilder $container)
{
$pass = new ReplaceAliasByActualDefinitionPass();
$pass->process($container);
}
}

View file

@ -0,0 +1,181 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$container->register('parent', 'foo')->setArguments(array('moo', 'b'))->setProperty('foo', 'moo');
$container->setDefinition('child', new DefinitionDecorator('parent'))
->replaceArgument(0, 'a')
->setProperty('foo', 'bar')
->setClass('bar')
;
$this->process($container);
$def = $container->getDefinition('child');
$this->assertNotInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $def);
$this->assertEquals('bar', $def->getClass());
$this->assertEquals(array('a', 'b'), $def->getArguments());
$this->assertEquals(array('foo' => 'bar'), $def->getProperties());
}
public function testProcessAppendsMethodCallsAlways()
{
$container = new ContainerBuilder();
$container
->register('parent')
->addMethodCall('foo', array('bar'))
;
$container
->setDefinition('child', new DefinitionDecorator('parent'))
->addMethodCall('bar', array('foo'))
;
$this->process($container);
$def = $container->getDefinition('child');
$this->assertEquals(array(
array('foo', array('bar')),
array('bar', array('foo')),
), $def->getMethodCalls());
}
public function testProcessDoesNotCopyAbstract()
{
$container = new ContainerBuilder();
$container
->register('parent')
->setAbstract(true)
;
$container
->setDefinition('child', new DefinitionDecorator('parent'))
;
$this->process($container);
$def = $container->getDefinition('child');
$this->assertFalse($def->isAbstract());
}
public function testProcessDoesNotCopyScope()
{
$container = new ContainerBuilder();
$container
->register('parent')
->setScope('foo')
;
$container
->setDefinition('child', new DefinitionDecorator('parent'))
;
$this->process($container);
$def = $container->getDefinition('child');
$this->assertEquals(ContainerInterface::SCOPE_CONTAINER, $def->getScope());
}
public function testProcessDoesNotCopyTags()
{
$container = new ContainerBuilder();
$container
->register('parent')
->addTag('foo')
;
$container
->setDefinition('child', new DefinitionDecorator('parent'))
;
$this->process($container);
$def = $container->getDefinition('child');
$this->assertEquals(array(), $def->getTags());
}
public function testProcessHandlesMultipleInheritance()
{
$container = new ContainerBuilder();
$container
->register('parent', 'foo')
->setArguments(array('foo', 'bar', 'c'))
;
$container
->setDefinition('child2', new DefinitionDecorator('child1'))
->replaceArgument(1, 'b')
;
$container
->setDefinition('child1', new DefinitionDecorator('parent'))
->replaceArgument(0, 'a')
;
$this->process($container);
$def = $container->getDefinition('child2');
$this->assertEquals(array('a', 'b', 'c'), $def->getArguments());
$this->assertEquals('foo', $def->getClass());
}
public function testSetLazyOnServiceHasParent()
{
$container = new ContainerBuilder();
$container->register('parent', 'stdClass');
$container->setDefinition('child1', new DefinitionDecorator('parent'))
->setLazy(true)
;
$this->process($container);
$this->assertTrue($container->getDefinition('child1')->isLazy());
}
public function testSetLazyOnServiceIsParent()
{
$container = new ContainerBuilder();
$container->register('parent', 'stdClass')
->setLazy(true)
;
$container->setDefinition('child1', new DefinitionDecorator('parent'));
$this->process($container);
$this->assertTrue($container->getDefinition('child1')->isLazy());
}
protected function process(ContainerBuilder $container)
{
$pass = new ResolveDefinitionTemplatesPass();
$pass->process($container);
}
}

View file

@ -0,0 +1,83 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\ResolveInvalidReferencesPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class ResolveInvalidReferencesPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$def = $container
->register('foo')
->setArguments(array(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)))
->addMethodCall('foo', array(new Reference('moo', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))
;
$this->process($container);
$arguments = $def->getArguments();
$this->assertNull($arguments[0]);
$this->assertCount(0, $def->getMethodCalls());
}
public function testProcessIgnoreNonExistentServices()
{
$container = new ContainerBuilder();
$def = $container
->register('foo')
->setArguments(array(new Reference('bar')))
;
$this->process($container);
$arguments = $def->getArguments();
$this->assertEquals('bar', (string) $arguments[0]);
}
public function testProcessRemovesPropertiesOnInvalid()
{
$container = new ContainerBuilder();
$def = $container
->register('foo')
->setProperty('foo', new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
;
$this->process($container);
$this->assertEquals(array(), $def->getProperties());
}
public function testStrictFlagIsPreserved()
{
$container = new ContainerBuilder();
$container->register('bar');
$def = $container
->register('foo')
->addArgument(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE, false))
;
$this->process($container);
$this->assertFalse($def->getArgument(0)->isStrict());
}
protected function process(ContainerBuilder $container)
{
$pass = new ResolveInvalidReferencesPass();
$pass->process($container);
}
}

View file

@ -0,0 +1,91 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class ResolveParameterPlaceHoldersPassTest extends \PHPUnit_Framework_TestCase
{
private $compilerPass;
private $container;
private $fooDefinition;
protected function setUp()
{
$this->compilerPass = new ResolveParameterPlaceHoldersPass();
$this->container = $this->createContainerBuilder();
$this->compilerPass->process($this->container);
$this->fooDefinition = $this->container->getDefinition('foo');
}
public function testClassParametersShouldBeResolved()
{
$this->assertSame('Foo', $this->fooDefinition->getClass());
}
public function testFactoryParametersShouldBeResolved()
{
$this->assertSame(array('FooFactory', 'getFoo'), $this->fooDefinition->getFactory());
}
public function testArgumentParametersShouldBeResolved()
{
$this->assertSame(array('bar', 'baz'), $this->fooDefinition->getArguments());
}
public function testMethodCallParametersShouldBeResolved()
{
$this->assertSame(array(array('foobar', array('bar', 'baz'))), $this->fooDefinition->getMethodCalls());
}
public function testPropertyParametersShouldBeResolved()
{
$this->assertSame(array('bar' => 'baz'), $this->fooDefinition->getProperties());
}
public function testFileParametersShouldBeResolved()
{
$this->assertSame('foo.php', $this->fooDefinition->getFile());
}
public function testAliasParametersShouldBeResolved()
{
$this->assertSame('foo', $this->container->getAlias('bar')->__toString());
}
private function createContainerBuilder()
{
$containerBuilder = new ContainerBuilder();
$containerBuilder->setParameter('foo.class', 'Foo');
$containerBuilder->setParameter('foo.factory.class', 'FooFactory');
$containerBuilder->setParameter('foo.arg1', 'bar');
$containerBuilder->setParameter('foo.arg2', 'baz');
$containerBuilder->setParameter('foo.method', 'foobar');
$containerBuilder->setParameter('foo.property.name', 'bar');
$containerBuilder->setParameter('foo.property.value', 'baz');
$containerBuilder->setParameter('foo.file', 'foo.php');
$containerBuilder->setParameter('alias.id', 'bar');
$fooDefinition = $containerBuilder->register('foo', '%foo.class%');
$fooDefinition->setFactory(array('%foo.factory.class%', 'getFoo'));
$fooDefinition->setArguments(array('%foo.arg1%', '%foo.arg2%'));
$fooDefinition->addMethodCall('%foo.method%', array('%foo.arg1%', '%foo.arg2%'));
$fooDefinition->setProperty('%foo.property.name%', '%foo.property.value%');
$fooDefinition->setFile('%foo.file%');
$containerBuilder->setAlias('%alias.id%', 'foo');
return $containerBuilder;
}
}

View file

@ -0,0 +1,67 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class ResolveReferencesToAliasesPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$container->setAlias('bar', 'foo');
$def = $container
->register('moo')
->setArguments(array(new Reference('bar')))
;
$this->process($container);
$arguments = $def->getArguments();
$this->assertEquals('foo', (string) $arguments[0]);
}
public function testProcessRecursively()
{
$container = new ContainerBuilder();
$container->setAlias('bar', 'foo');
$container->setAlias('moo', 'bar');
$def = $container
->register('foobar')
->setArguments(array(new Reference('moo')))
;
$this->process($container);
$arguments = $def->getArguments();
$this->assertEquals('foo', (string) $arguments[0]);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testAliasCircularReference()
{
$container = new ContainerBuilder();
$container->setAlias('bar', 'foo');
$container->setAlias('foo', 'bar');
$this->process($container);
}
protected function process(ContainerBuilder $container)
{
$pass = new ResolveReferencesToAliasesPass();
$pass->process($container);
}
}

View file

@ -0,0 +1,863 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests;
require_once __DIR__.'/Fixtures/includes/classes.php';
require_once __DIR__.'/Fixtures/includes/ProjectExtension.php';
use Symfony\Component\Config\Resource\ResourceInterface;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\ExpressionLanguage\Expression;
class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::setDefinitions
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getDefinitions
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::setDefinition
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getDefinition
*/
public function testDefinitions()
{
$builder = new ContainerBuilder();
$definitions = array(
'foo' => new Definition('Bar\FooClass'),
'bar' => new Definition('BarClass'),
);
$builder->setDefinitions($definitions);
$this->assertEquals($definitions, $builder->getDefinitions(), '->setDefinitions() sets the service definitions');
$this->assertTrue($builder->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$this->assertFalse($builder->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$builder->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$this->assertEquals($foo, $builder->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
$this->assertTrue($builder->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fluid interface by returning the service reference');
$builder->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$this->assertEquals(array_merge($definitions, $defs), $builder->getDefinitions(), '->addDefinitions() adds the service definitions');
try {
$builder->getDefinition('baz');
$this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
} catch (\InvalidArgumentException $e) {
$this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::register
*/
public function testRegister()
{
$builder = new ContainerBuilder();
$builder->register('foo', 'Bar\FooClass');
$this->assertTrue($builder->hasDefinition('foo'), '->register() registers a new service definition');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Definition', $builder->getDefinition('foo'), '->register() returns the newly created Definition instance');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::has
*/
public function testHas()
{
$builder = new ContainerBuilder();
$this->assertFalse($builder->has('foo'), '->has() returns false if the service does not exist');
$builder->register('foo', 'Bar\FooClass');
$this->assertTrue($builder->has('foo'), '->has() returns true if a service definition exists');
$builder->set('bar', new \stdClass());
$this->assertTrue($builder->has('bar'), '->has() returns true if a service exists');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::get
*/
public function testGet()
{
$builder = new ContainerBuilder();
try {
$builder->get('foo');
$this->fail('->get() throws an InvalidArgumentException if the service does not exist');
} catch (\InvalidArgumentException $e) {
$this->assertEquals('The service definition "foo" does not exist.', $e->getMessage(), '->get() throws an InvalidArgumentException if the service does not exist');
}
$this->assertNull($builder->get('foo', ContainerInterface::NULL_ON_INVALID_REFERENCE), '->get() returns null if the service does not exist and NULL_ON_INVALID_REFERENCE is passed as a second argument');
$builder->register('foo', 'stdClass');
$this->assertInternalType('object', $builder->get('foo'), '->get() returns the service definition associated with the id');
$builder->set('bar', $bar = new \stdClass());
$this->assertEquals($bar, $builder->get('bar'), '->get() returns the service associated with the id');
$builder->register('bar', 'stdClass');
$this->assertEquals($bar, $builder->get('bar'), '->get() returns the service associated with the id even if a definition has been defined');
$builder->register('baz', 'stdClass')->setArguments(array(new Reference('baz')));
try {
@$builder->get('baz');
$this->fail('->get() throws a ServiceCircularReferenceException if the service has a circular reference to itself');
} catch (\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException $e) {
$this->assertEquals('Circular reference detected for service "baz", path: "baz".', $e->getMessage(), '->get() throws a LogicException if the service has a circular reference to itself');
}
$builder->register('foobar', 'stdClass')->setScope('container');
$this->assertTrue($builder->get('bar') === $builder->get('bar'), '->get() always returns the same instance if the service is shared');
}
/**
* @covers \Symfony\Component\DependencyInjection\ContainerBuilder::get
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage You have requested a synthetic service ("foo"). The DIC does not know how to construct this service.
*/
public function testGetUnsetLoadingServiceWhenCreateServiceThrowsAnException()
{
$builder = new ContainerBuilder();
$builder->register('foo', 'stdClass')->setSynthetic(true);
// we expect a RuntimeException here as foo is synthetic
try {
$builder->get('foo');
} catch (RuntimeException $e) {
}
// we must also have the same RuntimeException here
$builder->get('foo');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::get
*/
public function testGetReturnsNullOnInactiveScope()
{
$builder = new ContainerBuilder();
$builder->register('foo', 'stdClass')->setScope('request');
$this->assertNull($builder->get('foo', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::get
*/
public function testGetReturnsNullOnInactiveScopeWhenServiceIsCreatedByAMethod()
{
$builder = new ProjectContainer();
$this->assertNull($builder->get('foobaz', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getServiceIds
*/
public function testGetServiceIds()
{
$builder = new ContainerBuilder();
$builder->register('foo', 'stdClass');
$builder->bar = $bar = new \stdClass();
$builder->register('bar', 'stdClass');
$this->assertEquals(array('foo', 'bar', 'service_container'), $builder->getServiceIds(), '->getServiceIds() returns all defined service ids');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::setAlias
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::hasAlias
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getAlias
*/
public function testAliases()
{
$builder = new ContainerBuilder();
$builder->register('foo', 'stdClass');
$builder->setAlias('bar', 'foo');
$this->assertTrue($builder->hasAlias('bar'), '->hasAlias() returns true if the alias exists');
$this->assertFalse($builder->hasAlias('foobar'), '->hasAlias() returns false if the alias does not exist');
$this->assertEquals('foo', (string) $builder->getAlias('bar'), '->getAlias() returns the aliased service');
$this->assertTrue($builder->has('bar'), '->setAlias() defines a new service');
$this->assertTrue($builder->get('bar') === $builder->get('foo'), '->setAlias() creates a service that is an alias to another one');
try {
$builder->setAlias('foobar', 'foobar');
$this->fail('->setAlias() throws an InvalidArgumentException if the alias references itself');
} catch (\InvalidArgumentException $e) {
$this->assertEquals('An alias can not reference itself, got a circular reference on "foobar".', $e->getMessage(), '->setAlias() throws an InvalidArgumentException if the alias references itself');
}
try {
$builder->getAlias('foobar');
$this->fail('->getAlias() throws an InvalidArgumentException if the alias does not exist');
} catch (\InvalidArgumentException $e) {
$this->assertEquals('The service alias "foobar" does not exist.', $e->getMessage(), '->getAlias() throws an InvalidArgumentException if the alias does not exist');
}
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getAliases
*/
public function testGetAliases()
{
$builder = new ContainerBuilder();
$builder->setAlias('bar', 'foo');
$builder->setAlias('foobar', 'foo');
$builder->setAlias('moo', new Alias('foo', false));
$aliases = $builder->getAliases();
$this->assertEquals('foo', (string) $aliases['bar']);
$this->assertTrue($aliases['bar']->isPublic());
$this->assertEquals('foo', (string) $aliases['foobar']);
$this->assertEquals('foo', (string) $aliases['moo']);
$this->assertFalse($aliases['moo']->isPublic());
$builder->register('bar', 'stdClass');
$this->assertFalse($builder->hasAlias('bar'));
$builder->set('foobar', 'stdClass');
$builder->set('moo', 'stdClass');
$this->assertCount(0, $builder->getAliases(), '->getAliases() does not return aliased services that have been overridden');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::setAliases
*/
public function testSetAliases()
{
$builder = new ContainerBuilder();
$builder->setAliases(array('bar' => 'foo', 'foobar' => 'foo'));
$aliases = $builder->getAliases();
$this->assertTrue(isset($aliases['bar']));
$this->assertTrue(isset($aliases['foobar']));
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::addAliases
*/
public function testAddAliases()
{
$builder = new ContainerBuilder();
$builder->setAliases(array('bar' => 'foo'));
$builder->addAliases(array('foobar' => 'foo'));
$aliases = $builder->getAliases();
$this->assertTrue(isset($aliases['bar']));
$this->assertTrue(isset($aliases['foobar']));
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::addCompilerPass
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getCompilerPassConfig
*/
public function testAddGetCompilerPass()
{
$builder = new ContainerBuilder();
$builder->setResourceTracking(false);
$builderCompilerPasses = $builder->getCompiler()->getPassConfig()->getPasses();
$builder->addCompilerPass($this->getMock('Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface'));
$this->assertCount(count($builder->getCompiler()->getPassConfig()->getPasses()) - 1, $builderCompilerPasses);
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
public function testCreateService()
{
$builder = new ContainerBuilder();
$builder->register('foo1', 'Bar\FooClass')->setFile(__DIR__.'/Fixtures/includes/foo.php');
$this->assertInstanceOf('\Bar\FooClass', $builder->get('foo1'), '->createService() requires the file defined by the service definition');
$builder->register('foo2', 'Bar\FooClass')->setFile(__DIR__.'/Fixtures/includes/%file%.php');
$builder->setParameter('file', 'foo');
$this->assertInstanceOf('\Bar\FooClass', $builder->get('foo2'), '->createService() replaces parameters in the file provided by the service definition');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
public function testCreateProxyWithRealServiceInstantiator()
{
$builder = new ContainerBuilder();
$builder->register('foo1', 'Bar\FooClass')->setFile(__DIR__.'/Fixtures/includes/foo.php');
$builder->getDefinition('foo1')->setLazy(true);
$foo1 = $builder->get('foo1');
$this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved on multiple subsequent calls');
$this->assertSame('Bar\FooClass', get_class($foo1));
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
public function testCreateServiceClass()
{
$builder = new ContainerBuilder();
$builder->register('foo1', '%class%');
$builder->setParameter('class', 'stdClass');
$this->assertInstanceOf('\stdClass', $builder->get('foo1'), '->createService() replaces parameters in the class provided by the service definition');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
public function testCreateServiceArguments()
{
$builder = new ContainerBuilder();
$builder->register('bar', 'stdClass');
$builder->register('foo1', 'Bar\FooClass')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar'), '%%unescape_it%%'));
$builder->setParameter('value', 'bar');
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->get('bar'), '%unescape_it%'), $builder->get('foo1')->arguments, '->createService() replaces parameters and service references in the arguments provided by the service definition');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
public function testCreateServiceFactory()
{
$builder = new ContainerBuilder();
$builder->register('foo', 'Bar\FooClass')->setFactory('Bar\FooClass::getInstance');
$builder->register('qux', 'Bar\FooClass')->setFactory(array('Bar\FooClass', 'getInstance'));
$builder->register('bar', 'Bar\FooClass')->setFactory(array(new Definition('Bar\FooClass'), 'getInstance'));
$builder->register('baz', 'Bar\FooClass')->setFactory(array(new Reference('bar'), 'getInstance'));
$this->assertTrue($builder->get('foo')->called, '->createService() calls the factory method to create the service instance');
$this->assertTrue($builder->get('qux')->called, '->createService() calls the factory method to create the service instance');
$this->assertTrue($builder->get('bar')->called, '->createService() uses anonymous service as factory');
$this->assertTrue($builder->get('baz')->called, '->createService() uses another service as factory');
}
public function testLegacyCreateServiceFactory()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$builder = new ContainerBuilder();
$builder->register('bar', 'Bar\FooClass');
$builder
->register('foo1', 'Bar\FooClass')
->setFactoryClass('%foo_class%')
->setFactoryMethod('getInstance')
->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')))
;
$builder->setParameter('value', 'bar');
$builder->setParameter('foo_class', 'Bar\FooClass');
$this->assertTrue($builder->get('foo1')->called, '->createService() calls the factory method to create the service instance');
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->get('bar')), $builder->get('foo1')->arguments, '->createService() passes the arguments to the factory method');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
public function testLegacyCreateServiceFactoryService()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$builder = new ContainerBuilder();
$builder->register('foo_service', 'Bar\FooClass');
$builder
->register('foo', 'Bar\FooClass')
->setFactoryService('%foo_service%')
->setFactoryMethod('getInstance')
;
$builder->setParameter('foo_service', 'foo_service');
$this->assertTrue($builder->get('foo')->called, '->createService() calls the factory method to create the service instance');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
public function testCreateServiceMethodCalls()
{
$builder = new ContainerBuilder();
$builder->register('bar', 'stdClass');
$builder->register('foo1', 'Bar\FooClass')->addMethodCall('setBar', array(array('%value%', new Reference('bar'))));
$builder->setParameter('value', 'bar');
$this->assertEquals(array('bar', $builder->get('bar')), $builder->get('foo1')->bar, '->createService() replaces the values in the method calls arguments');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
public function testCreateServiceConfigurator()
{
$builder = new ContainerBuilder();
$builder->register('foo1', 'Bar\FooClass')->setConfigurator('sc_configure');
$this->assertTrue($builder->get('foo1')->configured, '->createService() calls the configurator');
$builder->register('foo2', 'Bar\FooClass')->setConfigurator(array('%class%', 'configureStatic'));
$builder->setParameter('class', 'BazClass');
$this->assertTrue($builder->get('foo2')->configured, '->createService() calls the configurator');
$builder->register('baz', 'BazClass');
$builder->register('foo3', 'Bar\FooClass')->setConfigurator(array(new Reference('baz'), 'configure'));
$this->assertTrue($builder->get('foo3')->configured, '->createService() calls the configurator');
$builder->register('foo4', 'Bar\FooClass')->setConfigurator('foo');
try {
$builder->get('foo4');
$this->fail('->createService() throws an InvalidArgumentException if the configure callable is not a valid callable');
} catch (\InvalidArgumentException $e) {
$this->assertEquals('The configure callable for class "Bar\FooClass" is not a callable.', $e->getMessage(), '->createService() throws an InvalidArgumentException if the configure callable is not a valid callable');
}
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
* @expectedException \RuntimeException
*/
public function testCreateSyntheticService()
{
$builder = new ContainerBuilder();
$builder->register('foo', 'Bar\FooClass')->setSynthetic(true);
$builder->get('foo');
}
public function testCreateServiceWithExpression()
{
$builder = new ContainerBuilder();
$builder->setParameter('bar', 'bar');
$builder->register('bar', 'BarClass');
$builder->register('foo', 'Bar\FooClass')->addArgument(array('foo' => new Expression('service("bar").foo ~ parameter("bar")')));
$this->assertEquals('foobar', $builder->get('foo')->arguments['foo']);
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::resolveServices
*/
public function testResolveServices()
{
$builder = new ContainerBuilder();
$builder->register('foo', 'Bar\FooClass');
$this->assertEquals($builder->get('foo'), $builder->resolveServices(new Reference('foo')), '->resolveServices() resolves service references to service instances');
$this->assertEquals(array('foo' => array('foo', $builder->get('foo'))), $builder->resolveServices(array('foo' => array('foo', new Reference('foo')))), '->resolveServices() resolves service references to service instances in nested arrays');
$this->assertEquals($builder->get('foo'), $builder->resolveServices(new Expression('service("foo")')), '->resolveServices() resolves expressions');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::merge
*/
public function testMerge()
{
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
$container->setResourceTracking(false);
$config = new ContainerBuilder(new ParameterBag(array('foo' => 'bar')));
$container->merge($config);
$this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $container->getParameterBag()->all(), '->merge() merges current parameters with the loaded ones');
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
$container->setResourceTracking(false);
$config = new ContainerBuilder(new ParameterBag(array('foo' => '%bar%')));
$container->merge($config);
$container->compile();
$this->assertEquals(array('bar' => 'foo', 'foo' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
$container->setResourceTracking(false);
$config = new ContainerBuilder(new ParameterBag(array('foo' => '%bar%', 'baz' => '%foo%')));
$container->merge($config);
$container->compile();
$this->assertEquals(array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->register('foo', 'Bar\FooClass');
$container->register('bar', 'BarClass');
$config = new ContainerBuilder();
$config->setDefinition('baz', new Definition('BazClass'));
$config->setAlias('alias_for_foo', 'foo');
$container->merge($config);
$this->assertEquals(array('foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
$aliases = $container->getAliases();
$this->assertTrue(isset($aliases['alias_for_foo']));
$this->assertEquals('foo', (string) $aliases['alias_for_foo']);
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->register('foo', 'Bar\FooClass');
$config->setDefinition('foo', new Definition('BazClass'));
$container->merge($config);
$this->assertEquals('BazClass', $container->getDefinition('foo')->getClass(), '->merge() overrides already defined services');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::merge
* @expectedException \LogicException
*/
public function testMergeLogicException()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->compile();
$container->merge(new ContainerBuilder());
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::findTaggedServiceIds
*/
public function testfindTaggedServiceIds()
{
$builder = new ContainerBuilder();
$builder
->register('foo', 'Bar\FooClass')
->addTag('foo', array('foo' => 'foo'))
->addTag('bar', array('bar' => 'bar'))
->addTag('foo', array('foofoo' => 'foofoo'))
;
$this->assertEquals($builder->findTaggedServiceIds('foo'), array(
'foo' => array(
array('foo' => 'foo'),
array('foofoo' => 'foofoo'),
),
), '->findTaggedServiceIds() returns an array of service ids and its tag attributes');
$this->assertEquals(array(), $builder->findTaggedServiceIds('foobar'), '->findTaggedServiceIds() returns an empty array if there is annotated services');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::findDefinition
*/
public function testFindDefinition()
{
$container = new ContainerBuilder();
$container->setDefinition('foo', $definition = new Definition('Bar\FooClass'));
$container->setAlias('bar', 'foo');
$container->setAlias('foobar', 'bar');
$this->assertEquals($definition, $container->findDefinition('foobar'), '->findDefinition() returns a Definition');
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::addObjectResource
*/
public function testAddObjectResource()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->addObjectResource(new \BarClass());
$this->assertEmpty($container->getResources(), 'No resources get registered without resource tracking');
$container->setResourceTracking(true);
$container->addObjectResource(new \BarClass());
$resources = $container->getResources();
$this->assertCount(1, $resources, '1 resource was registered');
/* @var $resource \Symfony\Component\Config\Resource\FileResource */
$resource = end($resources);
$this->assertInstanceOf('Symfony\Component\Config\Resource\FileResource', $resource);
$this->assertSame(realpath(__DIR__.'/Fixtures/includes/classes.php'), realpath($resource->getResource()));
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::addClassResource
*/
public function testAddClassResource()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->addClassResource(new \ReflectionClass('BarClass'));
$this->assertEmpty($container->getResources(), 'No resources get registered without resource tracking');
$container->setResourceTracking(true);
$container->addClassResource(new \ReflectionClass('BarClass'));
$resources = $container->getResources();
$this->assertCount(1, $resources, '1 resource was registered');
/* @var $resource \Symfony\Component\Config\Resource\FileResource */
$resource = end($resources);
$this->assertInstanceOf('Symfony\Component\Config\Resource\FileResource', $resource);
$this->assertSame(realpath(__DIR__.'/Fixtures/includes/classes.php'), realpath($resource->getResource()));
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::compile
*/
public function testCompilesClassDefinitionsOfLazyServices()
{
$container = new ContainerBuilder();
$this->assertEmpty($container->getResources(), 'No resources get registered without resource tracking');
$container->register('foo', 'BarClass');
$container->getDefinition('foo')->setLazy(true);
$container->compile();
$classesPath = realpath(__DIR__.'/Fixtures/includes/classes.php');
$matchingResources = array_filter(
$container->getResources(),
function (ResourceInterface $resource) use ($classesPath) {
return $resource instanceof FileResource && $classesPath === realpath($resource->getResource());
}
);
$this->assertNotEmpty($matchingResources);
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getResources
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::addResource
*/
public function testResources()
{
$container = new ContainerBuilder();
$container->addResource($a = new FileResource(__DIR__.'/Fixtures/xml/services1.xml'));
$container->addResource($b = new FileResource(__DIR__.'/Fixtures/xml/services2.xml'));
$resources = array();
foreach ($container->getResources() as $resource) {
if (false === strpos($resource, '.php')) {
$resources[] = $resource;
}
}
$this->assertEquals(array($a, $b), $resources, '->getResources() returns an array of resources read for the current configuration');
$this->assertSame($container, $container->setResources(array()));
$this->assertEquals(array(), $container->getResources());
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::registerExtension
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getExtension
*/
public function testExtension()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->registerExtension($extension = new \ProjectExtension());
$this->assertTrue($container->getExtension('project') === $extension, '->registerExtension() registers an extension');
$this->setExpectedException('LogicException');
$container->getExtension('no_registered');
}
public function testRegisteredButNotLoadedExtension()
{
$extension = $this->getMock('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface');
$extension->expects($this->once())->method('getAlias')->will($this->returnValue('project'));
$extension->expects($this->never())->method('load');
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->registerExtension($extension);
$container->compile();
}
public function testRegisteredAndLoadedExtension()
{
$extension = $this->getMock('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface');
$extension->expects($this->exactly(2))->method('getAlias')->will($this->returnValue('project'));
$extension->expects($this->once())->method('load')->with(array(array('foo' => 'bar')));
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->registerExtension($extension);
$container->loadFromExtension('project', array('foo' => 'bar'));
$container->compile();
}
public function testPrivateServiceUser()
{
$fooDefinition = new Definition('BarClass');
$fooUserDefinition = new Definition('BarUserClass', array(new Reference('bar')));
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$fooDefinition->setPublic(false);
$container->addDefinitions(array(
'bar' => $fooDefinition,
'bar_user' => $fooUserDefinition,
));
$container->compile();
$this->assertInstanceOf('BarClass', $container->get('bar_user')->bar);
}
/**
* @expectedException \BadMethodCallException
*/
public function testThrowsExceptionWhenSetServiceOnAFrozenContainer()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->setDefinition('a', new Definition('stdClass'));
$container->compile();
$container->set('a', new \stdClass());
}
/**
* @expectedException \BadMethodCallException
*/
public function testThrowsExceptionWhenAddServiceOnAFrozenContainer()
{
$container = new ContainerBuilder();
$container->compile();
$container->set('a', new \stdClass());
}
public function testNoExceptionWhenSetSyntheticServiceOnAFrozenContainer()
{
$container = new ContainerBuilder();
$def = new Definition('stdClass');
$def->setSynthetic(true);
$container->setDefinition('a', $def);
$container->compile();
$container->set('a', $a = new \stdClass());
$this->assertEquals($a, $container->get('a'));
}
/**
* @group legacy
*/
public function testLegacySetOnSynchronizedService()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$container = new ContainerBuilder();
$container->register('baz', 'BazClass')
->setSynchronized(true)
;
$container->register('bar', 'BarClass')
->addMethodCall('setBaz', array(new Reference('baz')))
;
$container->set('baz', $baz = new \BazClass());
$this->assertSame($baz, $container->get('bar')->getBaz());
$container->set('baz', $baz = new \BazClass());
$this->assertSame($baz, $container->get('bar')->getBaz());
}
/**
* @group legacy
*/
public function testLegacySynchronizedServiceWithScopes()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$container = new ContainerBuilder();
$container->addScope(new Scope('foo'));
$container->register('baz', 'BazClass')
->setSynthetic(true)
->setSynchronized(true)
->setScope('foo')
;
$container->register('bar', 'BarClass')
->addMethodCall('setBaz', array(new Reference('baz', ContainerInterface::NULL_ON_INVALID_REFERENCE, false)))
;
$container->compile();
$container->enterScope('foo');
$container->set('baz', $outerBaz = new \BazClass(), 'foo');
$this->assertSame($outerBaz, $container->get('bar')->getBaz());
$container->enterScope('foo');
$container->set('baz', $innerBaz = new \BazClass(), 'foo');
$this->assertSame($innerBaz, $container->get('bar')->getBaz());
$container->leaveScope('foo');
$this->assertNotSame($innerBaz, $container->get('bar')->getBaz());
$this->assertSame($outerBaz, $container->get('bar')->getBaz());
$container->leaveScope('foo');
}
/**
* @expectedException \BadMethodCallException
*/
public function testThrowsExceptionWhenSetDefinitionOnAFrozenContainer()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->compile();
$container->setDefinition('a', new Definition());
}
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getExtensionConfig
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::prependExtensionConfig
*/
public function testExtensionConfig()
{
$container = new ContainerBuilder();
$configs = $container->getExtensionConfig('foo');
$this->assertEmpty($configs);
$first = array('foo' => 'bar');
$container->prependExtensionConfig('foo', $first);
$configs = $container->getExtensionConfig('foo');
$this->assertEquals(array($first), $configs);
$second = array('ding' => 'dong');
$container->prependExtensionConfig('foo', $second);
$configs = $container->getExtensionConfig('foo');
$this->assertEquals(array($second, $first), $configs);
}
public function testLazyLoadedService()
{
$loader = new ClosureLoader($container = new ContainerBuilder());
$loader->load(function (ContainerBuilder $container) {
$container->set('a', new \BazClass());
$definition = new Definition('BazClass');
$definition->setLazy(true);
$container->setDefinition('a', $definition);
}
);
$container->setResourceTracking(true);
$container->compile();
$class = new \BazClass();
$reflectionClass = new \ReflectionClass($class);
$r = new \ReflectionProperty($container, 'resources');
$r->setAccessible(true);
$resources = $r->getValue($container);
$classInList = false;
foreach ($resources as $resource) {
if ($resource->getResource() === $reflectionClass->getFileName()) {
$classInList = true;
break;
}
}
$this->assertTrue($classInList);
}
}
class FooClass
{
}
class ProjectContainer extends ContainerBuilder
{
public function getFoobazService()
{
throw new InactiveScopeException('foo', 'request');
}
}

View file

@ -0,0 +1,713 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
class ContainerTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Symfony\Component\DependencyInjection\Container::__construct
*/
public function testConstructor()
{
$sc = new Container();
$this->assertSame($sc, $sc->get('service_container'), '__construct() automatically registers itself as a service');
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
$this->assertEquals(array('foo' => 'bar'), $sc->getParameterBag()->all(), '__construct() takes an array of parameters as its first argument');
}
/**
* @dataProvider dataForTestCamelize
*/
public function testCamelize($id, $expected)
{
$this->assertEquals($expected, Container::camelize($id), sprintf('Container::camelize("%s")', $id));
}
public function dataForTestCamelize()
{
return array(
array('foo_bar', 'FooBar'),
array('foo.bar', 'Foo_Bar'),
array('foo.bar_baz', 'Foo_BarBaz'),
array('foo._bar', 'Foo_Bar'),
array('foo_.bar', 'Foo_Bar'),
array('_foo', 'Foo'),
array('.foo', '_Foo'),
array('foo_', 'Foo'),
array('foo.', 'Foo_'),
array('foo\bar', 'Foo_Bar'),
);
}
/**
* @dataProvider dataForTestUnderscore
*/
public function testUnderscore($id, $expected)
{
$this->assertEquals($expected, Container::underscore($id), sprintf('Container::underscore("%s")', $id));
}
public function dataForTestUnderscore()
{
return array(
array('FooBar', 'foo_bar'),
array('Foo_Bar', 'foo.bar'),
array('Foo_BarBaz', 'foo.bar_baz'),
array('FooBar_BazQux', 'foo_bar.baz_qux'),
array('_Foo', '.foo'),
array('Foo_', 'foo.'),
);
}
/**
* @covers Symfony\Component\DependencyInjection\Container::compile
*/
public function testCompile()
{
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
$this->assertFalse($sc->getParameterBag()->isResolved(), '->compile() resolves the parameter bag');
$sc->compile();
$this->assertTrue($sc->getParameterBag()->isResolved(), '->compile() resolves the parameter bag');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag', $sc->getParameterBag(), '->compile() changes the parameter bag to a FrozenParameterBag instance');
$this->assertEquals(array('foo' => 'bar'), $sc->getParameterBag()->all(), '->compile() copies the current parameters to the new parameter bag');
}
/**
* @covers Symfony\Component\DependencyInjection\Container::isFrozen
*/
public function testIsFrozen()
{
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
$this->assertFalse($sc->isFrozen(), '->isFrozen() returns false if the parameters are not frozen');
$sc->compile();
$this->assertTrue($sc->isFrozen(), '->isFrozen() returns true if the parameters are frozen');
}
/**
* @covers Symfony\Component\DependencyInjection\Container::getParameterBag
*/
public function testGetParameterBag()
{
$sc = new Container();
$this->assertEquals(array(), $sc->getParameterBag()->all(), '->getParameterBag() returns an empty array if no parameter has been defined');
}
/**
* @covers Symfony\Component\DependencyInjection\Container::setParameter
* @covers Symfony\Component\DependencyInjection\Container::getParameter
*/
public function testGetSetParameter()
{
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
$sc->setParameter('bar', 'foo');
$this->assertEquals('foo', $sc->getParameter('bar'), '->setParameter() sets the value of a new parameter');
$sc->setParameter('foo', 'baz');
$this->assertEquals('baz', $sc->getParameter('foo'), '->setParameter() overrides previously set parameter');
$sc->setParameter('Foo', 'baz1');
$this->assertEquals('baz1', $sc->getParameter('foo'), '->setParameter() converts the key to lowercase');
$this->assertEquals('baz1', $sc->getParameter('FOO'), '->getParameter() converts the key to lowercase');
try {
$sc->getParameter('baba');
$this->fail('->getParameter() thrown an \InvalidArgumentException if the key does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getParameter() thrown an \InvalidArgumentException if the key does not exist');
$this->assertEquals('You have requested a non-existent parameter "baba".', $e->getMessage(), '->getParameter() thrown an \InvalidArgumentException if the key does not exist');
}
}
/**
* @covers Symfony\Component\DependencyInjection\Container::getServiceIds
*/
public function testGetServiceIds()
{
$sc = new Container();
$sc->set('foo', $obj = new \stdClass());
$sc->set('bar', $obj = new \stdClass());
$this->assertEquals(array('service_container', 'foo', 'bar'), $sc->getServiceIds(), '->getServiceIds() returns all defined service ids');
$sc = new ProjectServiceContainer();
$sc->set('foo', $obj = new \stdClass());
$this->assertEquals(array('scoped', 'scoped_foo', 'scoped_synchronized_foo', 'inactive', '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()');
}
/**
* @covers Symfony\Component\DependencyInjection\Container::set
*/
public function testSet()
{
$sc = new Container();
$sc->set('foo', $foo = new \stdClass());
$this->assertEquals($foo, $sc->get('foo'), '->set() sets a service');
}
/**
* @covers Symfony\Component\DependencyInjection\Container::set
*/
public function testSetWithNullResetTheService()
{
$sc = new Container();
$sc->set('foo', null);
$this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
}
/**
* @expectedException \InvalidArgumentException
*/
public function testSetDoesNotAllowPrototypeScope()
{
$c = new Container();
$c->set('foo', new \stdClass(), Container::SCOPE_PROTOTYPE);
}
/**
* @expectedException \RuntimeException
*/
public function testSetDoesNotAllowInactiveScope()
{
$c = new Container();
$c->addScope(new Scope('foo'));
$c->set('foo', new \stdClass(), 'foo');
}
public function testSetAlsoSetsScopedService()
{
$c = new Container();
$c->addScope(new Scope('foo'));
$c->enterScope('foo');
$c->set('foo', $foo = new \stdClass(), 'foo');
$scoped = $this->getField($c, 'scopedServices');
$this->assertTrue(isset($scoped['foo']['foo']), '->set() sets a scoped service');
$this->assertSame($foo, $scoped['foo']['foo'], '->set() sets a scoped service');
}
public function testSetAlsoCallsSynchronizeService()
{
$c = new ProjectServiceContainer();
$c->addScope(new Scope('foo'));
$c->enterScope('foo');
$c->set('scoped_synchronized_foo', $bar = new \stdClass(), 'foo');
$this->assertTrue($c->synchronized, '->set() calls synchronize*Service() if it is defined for the service');
}
/**
* @covers Symfony\Component\DependencyInjection\Container::get
*/
public function testGet()
{
$sc = new ProjectServiceContainer();
$sc->set('foo', $foo = new \stdClass());
$this->assertEquals($foo, $sc->get('foo'), '->get() returns the service for the given id');
$this->assertEquals($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
$this->assertEquals($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
$this->assertEquals($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
$this->assertEquals($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
$this->assertEquals($sc->__foo_baz, $sc->get('foo\\baz'), '->get() returns the service if a get*Method() is defined');
$sc->set('bar', $bar = new \stdClass());
$this->assertEquals($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
try {
$sc->get('');
$this->fail('->get() throws a \InvalidArgumentException exception if the service is empty');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e, '->get() throws a ServiceNotFoundException exception if the service is empty');
}
$this->assertNull($sc->get('', ContainerInterface::NULL_ON_INVALID_REFERENCE), '->get() returns null if the service is empty');
}
public function testGetThrowServiceNotFoundException()
{
$sc = new ProjectServiceContainer();
$sc->set('foo', $foo = new \stdClass());
$sc->set('bar', $foo = new \stdClass());
$sc->set('baz', $foo = new \stdClass());
try {
$sc->get('foo1');
$this->fail('->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException if the key does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e, '->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException if the key does not exist');
$this->assertEquals('You have requested a non-existent service "foo1". Did you mean this: "foo"?', $e->getMessage(), '->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException with some advices');
}
try {
$sc->get('bag');
$this->fail('->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException if the key does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException', $e, '->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException if the key does not exist');
$this->assertEquals('You have requested a non-existent service "bag". Did you mean one of these: "bar", "baz"?', $e->getMessage(), '->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException with some advices');
}
}
public function testGetCircularReference()
{
$sc = new ProjectServiceContainer();
try {
$sc->get('circular');
$this->fail('->get() throws a ServiceCircularReferenceException if it contains circular reference');
} catch (\Exception $e) {
$this->assertInstanceOf('\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException', $e, '->get() throws a ServiceCircularReferenceException if it contains circular reference');
$this->assertStringStartsWith('Circular reference detected for service "circular"', $e->getMessage(), '->get() throws a \LogicException if it contains circular reference');
}
}
/**
* @covers Symfony\Component\DependencyInjection\Container::get
*/
public function testGetReturnsNullOnInactiveScope()
{
$sc = new ProjectServiceContainer();
$this->assertNull($sc->get('inactive', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}
/**
* @covers Symfony\Component\DependencyInjection\Container::has
*/
public function testHas()
{
$sc = new ProjectServiceContainer();
$sc->set('foo', new \stdClass());
$this->assertFalse($sc->has('foo1'), '->has() returns false if the service does not exist');
$this->assertTrue($sc->has('foo'), '->has() returns true if the service exists');
$this->assertTrue($sc->has('bar'), '->has() returns true if a get*Method() is defined');
$this->assertTrue($sc->has('foo_bar'), '->has() returns true if a get*Method() is defined');
$this->assertTrue($sc->has('foo.baz'), '->has() returns true if a get*Method() is defined');
$this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined');
}
/**
* @covers Symfony\Component\DependencyInjection\Container::initialized
*/
public function testInitialized()
{
$sc = new ProjectServiceContainer();
$sc->set('foo', new \stdClass());
$this->assertTrue($sc->initialized('foo'), '->initialized() returns true if service is loaded');
$this->assertFalse($sc->initialized('foo1'), '->initialized() returns false if service is not loaded');
$this->assertFalse($sc->initialized('bar'), '->initialized() returns false if a service is defined, but not currently loaded');
$this->assertFalse($sc->initialized('alias'), '->initialized() returns false if an aliased service is not initialized');
$sc->set('bar', new \stdClass());
$this->assertTrue($sc->initialized('alias'), '->initialized() returns true for alias if aliased service is initialized');
}
public function testEnterLeaveCurrentScope()
{
$container = new ProjectServiceContainer();
$container->addScope(new Scope('foo'));
$container->enterScope('foo');
$scoped1 = $container->get('scoped');
$scopedFoo1 = $container->get('scoped_foo');
$container->enterScope('foo');
$scoped2 = $container->get('scoped');
$scoped3 = $container->get('SCOPED');
$scopedFoo2 = $container->get('scoped_foo');
$container->leaveScope('foo');
$scoped4 = $container->get('scoped');
$scopedFoo3 = $container->get('scoped_foo');
$this->assertNotSame($scoped1, $scoped2);
$this->assertSame($scoped2, $scoped3);
$this->assertSame($scoped1, $scoped4);
$this->assertNotSame($scopedFoo1, $scopedFoo2);
$this->assertSame($scopedFoo1, $scopedFoo3);
}
public function testEnterLeaveScopeWithChildScopes()
{
$container = new Container();
$container->addScope(new Scope('foo'));
$container->addScope(new Scope('bar', 'foo'));
$this->assertFalse($container->isScopeActive('foo'));
$container->enterScope('foo');
$container->enterScope('bar');
$this->assertTrue($container->isScopeActive('foo'));
$this->assertFalse($container->has('a'));
$a = new \stdClass();
$container->set('a', $a, 'bar');
$scoped = $this->getField($container, 'scopedServices');
$this->assertTrue(isset($scoped['bar']['a']));
$this->assertSame($a, $scoped['bar']['a']);
$this->assertTrue($container->has('a'));
$container->leaveScope('foo');
$scoped = $this->getField($container, 'scopedServices');
$this->assertFalse(isset($scoped['bar']));
$this->assertFalse($container->isScopeActive('foo'));
$this->assertFalse($container->has('a'));
}
public function testEnterScopeRecursivelyWithInactiveChildScopes()
{
$container = new Container();
$container->addScope(new Scope('foo'));
$container->addScope(new Scope('bar', 'foo'));
$this->assertFalse($container->isScopeActive('foo'));
$container->enterScope('foo');
$this->assertTrue($container->isScopeActive('foo'));
$this->assertFalse($container->isScopeActive('bar'));
$this->assertFalse($container->has('a'));
$a = new \stdClass();
$container->set('a', $a, 'foo');
$scoped = $this->getField($container, 'scopedServices');
$this->assertTrue(isset($scoped['foo']['a']));
$this->assertSame($a, $scoped['foo']['a']);
$this->assertTrue($container->has('a'));
$container->enterScope('foo');
$scoped = $this->getField($container, 'scopedServices');
$this->assertFalse(isset($scoped['a']));
$this->assertTrue($container->isScopeActive('foo'));
$this->assertFalse($container->isScopeActive('bar'));
$this->assertFalse($container->has('a'));
$container->enterScope('bar');
$this->assertTrue($container->isScopeActive('bar'));
$container->leaveScope('foo');
$this->assertTrue($container->isScopeActive('foo'));
$this->assertFalse($container->isScopeActive('bar'));
$this->assertTrue($container->has('a'));
}
public function testEnterChildScopeRecursively()
{
$container = new Container();
$container->addScope(new Scope('foo'));
$container->addScope(new Scope('bar', 'foo'));
$container->enterScope('foo');
$container->enterScope('bar');
$this->assertTrue($container->isScopeActive('bar'));
$this->assertFalse($container->has('a'));
$a = new \stdClass();
$container->set('a', $a, 'bar');
$scoped = $this->getField($container, 'scopedServices');
$this->assertTrue(isset($scoped['bar']['a']));
$this->assertSame($a, $scoped['bar']['a']);
$this->assertTrue($container->has('a'));
$container->enterScope('bar');
$scoped = $this->getField($container, 'scopedServices');
$this->assertFalse(isset($scoped['a']));
$this->assertTrue($container->isScopeActive('foo'));
$this->assertTrue($container->isScopeActive('bar'));
$this->assertFalse($container->has('a'));
$container->leaveScope('bar');
$this->assertTrue($container->isScopeActive('foo'));
$this->assertTrue($container->isScopeActive('bar'));
$this->assertTrue($container->has('a'));
}
/**
* @expectedException \InvalidArgumentException
*/
public function testEnterScopeNotAdded()
{
$container = new Container();
$container->enterScope('foo');
}
/**
* @expectedException \RuntimeException
*/
public function testEnterScopeDoesNotAllowInactiveParentScope()
{
$container = new Container();
$container->addScope(new Scope('foo'));
$container->addScope(new Scope('bar', 'foo'));
$container->enterScope('bar');
}
public function testLeaveScopeNotActive()
{
$container = new Container();
$container->addScope(new Scope('foo'));
try {
$container->leaveScope('foo');
$this->fail('->leaveScope() throws a \LogicException if the scope is not active yet');
} catch (\Exception $e) {
$this->assertInstanceOf('\LogicException', $e, '->leaveScope() throws a \LogicException if the scope is not active yet');
$this->assertEquals('The scope "foo" is not active.', $e->getMessage(), '->leaveScope() throws a \LogicException if the scope is not active yet');
}
try {
$container->leaveScope('bar');
$this->fail('->leaveScope() throws a \LogicException if the scope does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\LogicException', $e, '->leaveScope() throws a \LogicException if the scope does not exist');
$this->assertEquals('The scope "bar" is not active.', $e->getMessage(), '->leaveScope() throws a \LogicException if the scope does not exist');
}
}
/**
* @expectedException \InvalidArgumentException
* @dataProvider getBuiltInScopes
*/
public function testAddScopeDoesNotAllowBuiltInScopes($scope)
{
$container = new Container();
$container->addScope(new Scope($scope));
}
/**
* @expectedException \InvalidArgumentException
*/
public function testAddScopeDoesNotAllowExistingScope()
{
$container = new Container();
$container->addScope(new Scope('foo'));
$container->addScope(new Scope('foo'));
}
/**
* @expectedException \InvalidArgumentException
* @dataProvider getInvalidParentScopes
*/
public function testAddScopeDoesNotAllowInvalidParentScope($scope)
{
$c = new Container();
$c->addScope(new Scope('foo', $scope));
}
public function testAddScope()
{
$c = new Container();
$c->addScope(new Scope('foo'));
$c->addScope(new Scope('bar', 'foo'));
$this->assertSame(array('foo' => 'container', 'bar' => 'foo'), $this->getField($c, 'scopes'));
$this->assertSame(array('foo' => array('bar'), 'bar' => array()), $this->getField($c, 'scopeChildren'));
$c->addScope(new Scope('baz', 'bar'));
$this->assertSame(array('foo' => 'container', 'bar' => 'foo', 'baz' => 'bar'), $this->getField($c, 'scopes'));
$this->assertSame(array('foo' => array('bar', 'baz'), 'bar' => array('baz'), 'baz' => array()), $this->getField($c, 'scopeChildren'));
}
public function testHasScope()
{
$c = new Container();
$this->assertFalse($c->hasScope('foo'));
$c->addScope(new Scope('foo'));
$this->assertTrue($c->hasScope('foo'));
}
/**
* @expectedException Exception
* @expectedExceptionMessage Something went terribly wrong!
*/
public function testGetThrowsException()
{
$c = new ProjectServiceContainer();
try {
$c->get('throw_exception');
} catch (\Exception $e) {
// Do nothing.
}
// Retry, to make sure that get*Service() will be called.
$c->get('throw_exception');
}
public function testGetThrowsExceptionOnServiceConfiguration()
{
$c = new ProjectServiceContainer();
try {
$c->get('throws_exception_on_service_configuration');
} catch (\Exception $e) {
// Do nothing.
}
$this->assertFalse($c->initialized('throws_exception_on_service_configuration'));
// Retry, to make sure that get*Service() will be called.
try {
$c->get('throws_exception_on_service_configuration');
} catch (\Exception $e) {
// Do nothing.
}
$this->assertFalse($c->initialized('throws_exception_on_service_configuration'));
}
public function testIsScopeActive()
{
$c = new Container();
$this->assertFalse($c->isScopeActive('foo'));
$c->addScope(new Scope('foo'));
$this->assertFalse($c->isScopeActive('foo'));
$c->enterScope('foo');
$this->assertTrue($c->isScopeActive('foo'));
$c->leaveScope('foo');
$this->assertFalse($c->isScopeActive('foo'));
}
public function getInvalidParentScopes()
{
return array(
array(ContainerInterface::SCOPE_PROTOTYPE),
array('bar'),
);
}
public function getBuiltInScopes()
{
return array(
array(ContainerInterface::SCOPE_CONTAINER),
array(ContainerInterface::SCOPE_PROTOTYPE),
);
}
protected function getField($obj, $field)
{
$reflection = new \ReflectionProperty($obj, $field);
$reflection->setAccessible(true);
return $reflection->getValue($obj);
}
public function testAlias()
{
$c = new ProjectServiceContainer();
$this->assertTrue($c->has('alias'));
$this->assertSame($c->get('alias'), $c->get('bar'));
}
}
class ProjectServiceContainer extends Container
{
public $__bar, $__foo_bar, $__foo_baz;
public $synchronized;
public function __construct()
{
parent::__construct();
$this->__bar = new \stdClass();
$this->__foo_bar = new \stdClass();
$this->__foo_baz = new \stdClass();
$this->synchronized = false;
$this->aliases = array('alias' => 'bar');
}
protected function getScopedService()
{
if (!$this->isScopeActive('foo')) {
throw new \RuntimeException('Invalid call');
}
return $this->services['scoped'] = $this->scopedServices['foo']['scoped'] = new \stdClass();
}
protected function getScopedFooService()
{
if (!$this->isScopeActive('foo')) {
throw new \RuntimeException('invalid call');
}
return $this->services['scoped_foo'] = $this->scopedServices['foo']['scoped_foo'] = new \stdClass();
}
protected function getScopedSynchronizedFooService()
{
if (!$this->isScopeActive('foo')) {
throw new \RuntimeException('invalid call');
}
return $this->services['scoped_bar'] = $this->scopedServices['foo']['scoped_bar'] = new \stdClass();
}
protected function synchronizeScopedSynchronizedFooService()
{
$this->synchronized = true;
}
protected function getInactiveService()
{
throw new InactiveScopeException('request', 'request');
}
protected function getBarService()
{
return $this->__bar;
}
protected function getFooBarService()
{
return $this->__foo_bar;
}
protected function getFoo_BazService()
{
return $this->__foo_baz;
}
protected function getCircularService()
{
return $this->get('circular');
}
protected function getThrowExceptionService()
{
throw new \Exception('Something went terribly wrong!');
}
protected function getThrowsExceptionOnServiceConfigurationService()
{
$this->services['throws_exception_on_service_configuration'] = $instance = new \stdClass();
throw new \Exception('Something was terribly wrong while trying to configure the service!');
}
}

View file

@ -0,0 +1,96 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
class CrossCheckTest extends \PHPUnit_Framework_TestCase
{
protected static $fixturesPath;
public static function setUpBeforeClass()
{
self::$fixturesPath = __DIR__.'/Fixtures/';
require_once self::$fixturesPath.'/includes/classes.php';
require_once self::$fixturesPath.'/includes/foo.php';
}
/**
* @dataProvider crossCheckLoadersDumpers
*/
public function testCrossCheck($fixture, $type)
{
$loaderClass = 'Symfony\\Component\\DependencyInjection\\Loader\\'.ucfirst($type).'FileLoader';
$dumperClass = 'Symfony\\Component\\DependencyInjection\\Dumper\\'.ucfirst($type).'Dumper';
$tmp = tempnam('sf_service_container', 'sf');
file_put_contents($tmp, file_get_contents(self::$fixturesPath.'/'.$type.'/'.$fixture));
$container1 = new ContainerBuilder();
$loader1 = new $loaderClass($container1, new FileLocator());
$loader1->load($tmp);
$dumper = new $dumperClass($container1);
file_put_contents($tmp, $dumper->dump());
$container2 = new ContainerBuilder();
$loader2 = new $loaderClass($container2, new FileLocator());
$loader2->load($tmp);
unlink($tmp);
$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');
$this->assertEquals(serialize($container2), serialize($container1), 'loading a dump from a previously loaded container returns the same container');
$services1 = array();
foreach ($container1 as $id => $service) {
$services1[$id] = serialize($service);
}
$services2 = array();
foreach ($container2 as $id => $service) {
$services2[$id] = serialize($service);
}
unset($services1['service_container'], $services2['service_container']);
$this->assertEquals($services2, $services1, 'Iterator on the containers returns the same services');
}
public function crossCheckLoadersDumpers()
{
$tests = array(
array('services1.xml', 'xml'),
array('services2.xml', 'xml'),
array('services6.xml', 'xml'),
array('services8.xml', 'xml'),
array('services9.xml', 'xml'),
);
if (class_exists('Symfony\Component\Yaml\Yaml')) {
$tests = array_merge($tests, array(
array('services1.yml', 'yaml'),
array('services2.yml', 'yaml'),
array('services6.yml', 'yaml'),
array('services8.yml', 'yaml'),
array('services9.yml', 'yaml'),
));
}
return $tests;
}
}

View file

@ -0,0 +1,146 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
class DefinitionDecoratorTest extends \PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$def = new DefinitionDecorator('foo');
$this->assertEquals('foo', $def->getParent());
$this->assertEquals(array(), $def->getChanges());
}
/**
* @dataProvider getPropertyTests
*/
public function testSetProperty($property, $changeKey)
{
$def = new DefinitionDecorator('foo');
$getter = 'get'.ucfirst($property);
$setter = 'set'.ucfirst($property);
$this->assertNull($def->$getter());
$this->assertSame($def, $def->$setter('foo'));
$this->assertEquals('foo', $def->$getter());
$this->assertEquals(array($changeKey => true), $def->getChanges());
}
public function getPropertyTests()
{
return array(
array('class', 'class'),
array('factory', 'factory'),
array('configurator', 'configurator'),
array('file', 'file'),
);
}
/**
* @dataProvider provideLegacyPropertyTests
* @group legacy
*/
public function testLegacySetProperty($property, $changeKey)
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$def = new DefinitionDecorator('foo');
$getter = 'get'.ucfirst($property);
$setter = 'set'.ucfirst($property);
$this->assertNull($def->$getter());
$this->assertSame($def, $def->$setter('foo'));
$this->assertEquals('foo', $def->$getter());
$this->assertEquals(array($changeKey => true), $def->getChanges());
}
public function provideLegacyPropertyTests()
{
return array(
array('factoryClass', 'factory_class'),
array('factoryMethod', 'factory_method'),
array('factoryService', 'factory_service'),
);
}
public function testSetPublic()
{
$def = new DefinitionDecorator('foo');
$this->assertTrue($def->isPublic());
$this->assertSame($def, $def->setPublic(false));
$this->assertFalse($def->isPublic());
$this->assertEquals(array('public' => true), $def->getChanges());
}
public function testSetLazy()
{
$def = new DefinitionDecorator('foo');
$this->assertFalse($def->isLazy());
$this->assertSame($def, $def->setLazy(false));
$this->assertFalse($def->isLazy());
$this->assertEquals(array('lazy' => true), $def->getChanges());
}
public function testSetArgument()
{
$def = new DefinitionDecorator('foo');
$this->assertEquals(array(), $def->getArguments());
$this->assertSame($def, $def->replaceArgument(0, 'foo'));
$this->assertEquals(array('index_0' => 'foo'), $def->getArguments());
}
/**
* @expectedException \InvalidArgumentException
*/
public function testReplaceArgumentShouldRequireIntegerIndex()
{
$def = new DefinitionDecorator('foo');
$def->replaceArgument('0', 'foo');
}
public function testReplaceArgument()
{
$def = new DefinitionDecorator('foo');
$def->setArguments(array(0 => 'foo', 1 => 'bar'));
$this->assertEquals('foo', $def->getArgument(0));
$this->assertEquals('bar', $def->getArgument(1));
$this->assertSame($def, $def->replaceArgument(1, 'baz'));
$this->assertEquals('foo', $def->getArgument(0));
$this->assertEquals('baz', $def->getArgument(1));
$this->assertEquals(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments());
}
/**
* @expectedException \OutOfBoundsException
*/
public function testGetArgumentShouldCheckBounds()
{
$def = new DefinitionDecorator('foo');
$def->setArguments(array(0 => 'foo'));
$def->replaceArgument(0, 'foo');
$def->getArgument(1);
}
}

View file

@ -0,0 +1,330 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests;
use Symfony\Component\DependencyInjection\Definition;
class DefinitionTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Symfony\Component\DependencyInjection\Definition::__construct
*/
public function testConstructor()
{
$def = new Definition('stdClass');
$this->assertEquals('stdClass', $def->getClass(), '__construct() takes the class name as its first argument');
$def = new Definition('stdClass', array('foo'));
$this->assertEquals(array('foo'), $def->getArguments(), '__construct() takes an optional array of arguments as its second argument');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setFactory
* @covers Symfony\Component\DependencyInjection\Definition::getFactory
*/
public function testSetGetFactory()
{
$def = new Definition('stdClass');
$this->assertSame($def, $def->setFactory('foo'), '->setFactory() implements a fluent interface');
$this->assertEquals('foo', $def->getFactory(), '->getFactory() returns the factory');
$def->setFactory('Foo::bar');
$this->assertEquals(array('Foo', 'bar'), $def->getFactory(), '->setFactory() converts string static method call to the array');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setClass
* @covers Symfony\Component\DependencyInjection\Definition::getClass
*/
public function testSetGetClass()
{
$def = new Definition('stdClass');
$this->assertSame($def, $def->setClass('foo'), '->setClass() implements a fluent interface');
$this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
}
public function testSetGetDecoratedService()
{
$def = new Definition('stdClass');
$this->assertNull($def->getDecoratedService());
$def->setDecoratedService('foo', 'foo.renamed');
$this->assertEquals(array('foo', 'foo.renamed'), $def->getDecoratedService());
$def->setDecoratedService(null);
$this->assertNull($def->getDecoratedService());
$def = new Definition('stdClass');
$def->setDecoratedService('foo');
$this->assertEquals(array('foo', null), $def->getDecoratedService());
$def->setDecoratedService(null);
$this->assertNull($def->getDecoratedService());
$def = new Definition('stdClass');
$this->setExpectedException('InvalidArgumentException', 'The decorated service inner name for "foo" must be different than the service name itself.');
$def->setDecoratedService('foo', 'foo');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setArguments
* @covers Symfony\Component\DependencyInjection\Definition::getArguments
* @covers Symfony\Component\DependencyInjection\Definition::addArgument
*/
public function testArguments()
{
$def = new Definition('stdClass');
$this->assertSame($def, $def->setArguments(array('foo')), '->setArguments() implements a fluent interface');
$this->assertEquals(array('foo'), $def->getArguments(), '->getArguments() returns the arguments');
$this->assertSame($def, $def->addArgument('bar'), '->addArgument() implements a fluent interface');
$this->assertEquals(array('foo', 'bar'), $def->getArguments(), '->addArgument() adds an argument');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setMethodCalls
* @covers Symfony\Component\DependencyInjection\Definition::addMethodCall
* @covers Symfony\Component\DependencyInjection\Definition::hasMethodCall
* @covers Symfony\Component\DependencyInjection\Definition::removeMethodCall
*/
public function testMethodCalls()
{
$def = new Definition('stdClass');
$this->assertSame($def, $def->setMethodCalls(array(array('foo', array('foo')))), '->setMethodCalls() implements a fluent interface');
$this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->getMethodCalls() returns the methods to call');
$this->assertSame($def, $def->addMethodCall('bar', array('bar')), '->addMethodCall() implements a fluent interface');
$this->assertEquals(array(array('foo', array('foo')), array('bar', array('bar'))), $def->getMethodCalls(), '->addMethodCall() adds a method to call');
$this->assertTrue($def->hasMethodCall('bar'), '->hasMethodCall() returns true if first argument is a method to call registered');
$this->assertFalse($def->hasMethodCall('no_registered'), '->hasMethodCall() returns false if first argument is not a method to call registered');
$this->assertSame($def, $def->removeMethodCall('bar'), '->removeMethodCall() implements a fluent interface');
$this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->removeMethodCall() removes a method to call');
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Method name cannot be empty.
*/
public function testExceptionOnEmptyMethodCall()
{
$def = new Definition('stdClass');
$def->addMethodCall('');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setFile
* @covers Symfony\Component\DependencyInjection\Definition::getFile
*/
public function testSetGetFile()
{
$def = new Definition('stdClass');
$this->assertSame($def, $def->setFile('foo'), '->setFile() implements a fluent interface');
$this->assertEquals('foo', $def->getFile(), '->getFile() returns the file to include');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setScope
* @covers Symfony\Component\DependencyInjection\Definition::getScope
*/
public function testSetGetScope()
{
$def = new Definition('stdClass');
$this->assertEquals('container', $def->getScope());
$this->assertSame($def, $def->setScope('foo'));
$this->assertEquals('foo', $def->getScope());
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setPublic
* @covers Symfony\Component\DependencyInjection\Definition::isPublic
*/
public function testSetIsPublic()
{
$def = new Definition('stdClass');
$this->assertTrue($def->isPublic(), '->isPublic() returns true by default');
$this->assertSame($def, $def->setPublic(false), '->setPublic() implements a fluent interface');
$this->assertFalse($def->isPublic(), '->isPublic() returns false if the instance must not be public.');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setSynthetic
* @covers Symfony\Component\DependencyInjection\Definition::isSynthetic
*/
public function testSetIsSynthetic()
{
$def = new Definition('stdClass');
$this->assertFalse($def->isSynthetic(), '->isSynthetic() returns false by default');
$this->assertSame($def, $def->setSynthetic(true), '->setSynthetic() implements a fluent interface');
$this->assertTrue($def->isSynthetic(), '->isSynthetic() returns true if the service is synthetic.');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setSynchronized
* @covers Symfony\Component\DependencyInjection\Definition::isSynchronized
* @group legacy
*/
public function testLegacySetIsSynchronized()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$def = new Definition('stdClass');
$this->assertFalse($def->isSynchronized(), '->isSynchronized() returns false by default');
$this->assertSame($def, $def->setSynchronized(true), '->setSynchronized() implements a fluent interface');
$this->assertTrue($def->isSynchronized(), '->isSynchronized() returns true if the service is synchronized.');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setLazy
* @covers Symfony\Component\DependencyInjection\Definition::isLazy
*/
public function testSetIsLazy()
{
$def = new Definition('stdClass');
$this->assertFalse($def->isLazy(), '->isLazy() returns false by default');
$this->assertSame($def, $def->setLazy(true), '->setLazy() implements a fluent interface');
$this->assertTrue($def->isLazy(), '->isLazy() returns true if the service is lazy.');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setAbstract
* @covers Symfony\Component\DependencyInjection\Definition::isAbstract
*/
public function testSetIsAbstract()
{
$def = new Definition('stdClass');
$this->assertFalse($def->isAbstract(), '->isAbstract() returns false by default');
$this->assertSame($def, $def->setAbstract(true), '->setAbstract() implements a fluent interface');
$this->assertTrue($def->isAbstract(), '->isAbstract() returns true if the instance must not be public.');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::setConfigurator
* @covers Symfony\Component\DependencyInjection\Definition::getConfigurator
*/
public function testSetGetConfigurator()
{
$def = new Definition('stdClass');
$this->assertSame($def, $def->setConfigurator('foo'), '->setConfigurator() implements a fluent interface');
$this->assertEquals('foo', $def->getConfigurator(), '->getConfigurator() returns the configurator');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::clearTags
*/
public function testClearTags()
{
$def = new Definition('stdClass');
$this->assertSame($def, $def->clearTags(), '->clearTags() implements a fluent interface');
$def->addTag('foo', array('foo' => 'bar'));
$def->clearTags();
$this->assertEquals(array(), $def->getTags(), '->clearTags() removes all current tags');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::clearTags
*/
public function testClearTag()
{
$def = new Definition('stdClass');
$this->assertSame($def, $def->clearTags(), '->clearTags() implements a fluent interface');
$def->addTag('1foo1', array('foo1' => 'bar1'));
$def->addTag('2foo2', array('foo2' => 'bar2'));
$def->addTag('3foo3', array('foo3' => 'bar3'));
$def->clearTag('2foo2');
$this->assertTrue($def->hasTag('1foo1'));
$this->assertFalse($def->hasTag('2foo2'));
$this->assertTrue($def->hasTag('3foo3'));
$def->clearTag('1foo1');
$this->assertFalse($def->hasTag('1foo1'));
$this->assertTrue($def->hasTag('3foo3'));
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::addTag
* @covers Symfony\Component\DependencyInjection\Definition::getTag
* @covers Symfony\Component\DependencyInjection\Definition::getTags
* @covers Symfony\Component\DependencyInjection\Definition::hasTag
*/
public function testTags()
{
$def = new Definition('stdClass');
$this->assertEquals(array(), $def->getTag('foo'), '->getTag() returns an empty array if the tag is not defined');
$this->assertFalse($def->hasTag('foo'));
$this->assertSame($def, $def->addTag('foo'), '->addTag() implements a fluent interface');
$this->assertTrue($def->hasTag('foo'));
$this->assertEquals(array(array()), $def->getTag('foo'), '->getTag() returns attributes for a tag name');
$def->addTag('foo', array('foo' => 'bar'));
$this->assertEquals(array(array(), array('foo' => 'bar')), $def->getTag('foo'), '->addTag() can adds the same tag several times');
$def->addTag('bar', array('bar' => 'bar'));
$this->assertEquals($def->getTags(), array(
'foo' => array(array(), array('foo' => 'bar')),
'bar' => array(array('bar' => 'bar')),
), '->getTags() returns all tags');
}
/**
* @covers Symfony\Component\DependencyInjection\Definition::replaceArgument
*/
public function testSetArgument()
{
$def = new Definition('stdClass');
$def->addArgument('foo');
$this->assertSame(array('foo'), $def->getArguments());
$this->assertSame($def, $def->replaceArgument(0, 'moo'));
$this->assertSame(array('moo'), $def->getArguments());
$def->addArgument('moo');
$def
->replaceArgument(0, 'foo')
->replaceArgument(1, 'bar')
;
$this->assertSame(array('foo', 'bar'), $def->getArguments());
}
/**
* @expectedException \OutOfBoundsException
*/
public function testGetArgumentShouldCheckBounds()
{
$def = new Definition('stdClass');
$def->addArgument('foo');
$def->getArgument(1);
}
/**
* @expectedException \OutOfBoundsException
*/
public function testReplaceArgumentShouldCheckBounds()
{
$def = new Definition('stdClass');
$def->addArgument('foo');
$def->replaceArgument(1, 'bar');
}
public function testSetGetProperties()
{
$def = new Definition('stdClass');
$this->assertEquals(array(), $def->getProperties());
$this->assertSame($def, $def->setProperties(array('foo' => 'bar')));
$this->assertEquals(array('foo' => 'bar'), $def->getProperties());
}
public function testSetProperty()
{
$def = new Definition('stdClass');
$this->assertEquals(array(), $def->getProperties());
$this->assertSame($def, $def->setProperty('foo', 'bar'));
$this->assertEquals(array('foo' => 'bar'), $def->getProperties());
}
}

View file

@ -0,0 +1,92 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Dumper;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\GraphvizDumper;
class GraphvizDumperTest extends \PHPUnit_Framework_TestCase
{
protected static $fixturesPath;
public static function setUpBeforeClass()
{
self::$fixturesPath = __DIR__.'/../Fixtures/';
}
/**
* @group legacy
*/
public function testLegacyDump()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$container = include self::$fixturesPath.'/containers/legacy-container9.php';
$dumper = new GraphvizDumper($container);
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/legacy-services9.dot')), $dumper->dump(), '->dump() dumps services');
}
public function testDump()
{
$dumper = new GraphvizDumper($container = new ContainerBuilder());
$this->assertStringEqualsFile(self::$fixturesPath.'/graphviz/services1.dot', $dumper->dump(), '->dump() dumps an empty container as an empty dot file');
$container = include self::$fixturesPath.'/containers/container9.php';
$dumper = new GraphvizDumper($container);
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services9.dot')), $dumper->dump(), '->dump() dumps services');
$container = include self::$fixturesPath.'/containers/container10.php';
$dumper = new GraphvizDumper($container);
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10.dot')), $dumper->dump(), '->dump() dumps services');
$container = include self::$fixturesPath.'/containers/container10.php';
$dumper = new GraphvizDumper($container);
$this->assertEquals($dumper->dump(array(
'graph' => array('ratio' => 'normal'),
'node' => array('fontsize' => 13, 'fontname' => 'Verdana', 'shape' => 'square'),
'edge' => array('fontsize' => 12, 'fontname' => 'Verdana', 'color' => 'white', 'arrowhead' => 'closed', 'arrowsize' => 1),
'node.instance' => array('fillcolor' => 'green', 'style' => 'empty'),
'node.definition' => array('fillcolor' => 'grey'),
'node.missing' => array('fillcolor' => 'red', 'style' => 'empty'),
)), str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10-1.dot')), '->dump() dumps services');
}
public function testDumpWithFrozenContainer()
{
$container = include self::$fixturesPath.'/containers/container13.php';
$dumper = new GraphvizDumper($container);
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services13.dot')), $dumper->dump(), '->dump() dumps services');
}
public function testDumpWithFrozenCustomClassContainer()
{
$container = include self::$fixturesPath.'/containers/container14.php';
$dumper = new GraphvizDumper($container);
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services14.dot')), $dumper->dump(), '->dump() dumps services');
}
public function testDumpWithUnresolvedParameter()
{
$container = include self::$fixturesPath.'/containers/container17.php';
$dumper = new GraphvizDumper($container);
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services17.dot')), $dumper->dump(), '->dump() dumps services');
}
public function testDumpWithScopes()
{
$container = include self::$fixturesPath.'/containers/container18.php';
$dumper = new GraphvizDumper($container);
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services18.dot')), $dumper->dump(), '->dump() dumps services');
}
}

View file

@ -0,0 +1,223 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Dumper;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Definition;
class PhpDumperTest extends \PHPUnit_Framework_TestCase
{
protected static $fixturesPath;
public static function setUpBeforeClass()
{
self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
}
public function testDump()
{
$dumper = new PhpDumper($container = new ContainerBuilder());
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services1.php', $dumper->dump(), '->dump() dumps an empty container as an empty PHP class');
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services1-1.php', $dumper->dump(array('class' => 'Container', 'base_class' => 'AbstractContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Dump')), '->dump() takes a class and a base_class options');
$container = new ContainerBuilder();
new PhpDumper($container);
}
public function testDumpOptimizationString()
{
$definition = new Definition();
$definition->setClass('stdClass');
$definition->addArgument(array(
'only dot' => '.',
'concatenation as value' => '.\'\'.',
'concatenation from the start value' => '\'\'.',
'.' => 'dot as a key',
'.\'\'.' => 'concatenation as a key',
'\'\'.' => 'concatenation from the start key',
'optimize concatenation' => 'string1%some_string%string2',
'optimize concatenation with empty string' => 'string1%empty_value%string2',
'optimize concatenation from the start' => '%empty_value%start',
'optimize concatenation at the end' => 'end%empty_value%',
));
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->setDefinition('test', $definition);
$container->setParameter('empty_value', '');
$container->setParameter('some_string', '-');
$container->compile();
$dumper = new PhpDumper($container);
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services10.php', $dumper->dump(), '->dump() dumps an empty container as an empty PHP class');
}
public function testDumpRelativeDir()
{
$definition = new Definition();
$definition->setClass('stdClass');
$definition->addArgument('%foo%');
$definition->addArgument(array('%foo%' => '%buz%/'));
$container = new ContainerBuilder();
$container->setDefinition('test', $definition);
$container->setParameter('foo', 'wiz'.dirname(__DIR__));
$container->setParameter('bar', __DIR__);
$container->setParameter('baz', '%bar%/PhpDumperTest.php');
$container->setParameter('buz', dirname(dirname(__DIR__)));
$container->compile();
$dumper = new PhpDumper($container);
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services12.php', $dumper->dump(array('file' => __FILE__)), '->dump() dumps __DIR__ relative strings');
}
/**
* @expectedException \InvalidArgumentException
*/
public function testExportParameters()
{
$dumper = new PhpDumper(new ContainerBuilder(new ParameterBag(array('foo' => new Reference('foo')))));
$dumper->dump();
}
public function testAddParameters()
{
$container = include self::$fixturesPath.'/containers/container8.php';
$dumper = new PhpDumper($container);
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services8.php', $dumper->dump(), '->dump() dumps parameters');
}
public function testAddService()
{
// without compilation
$container = include self::$fixturesPath.'/containers/container9.php';
$dumper = new PhpDumper($container);
$this->assertEquals(str_replace('%path%', str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9.php')), $dumper->dump(), '->dump() dumps services');
// with compilation
$container = include self::$fixturesPath.'/containers/container9.php';
$container->compile();
$dumper = new PhpDumper($container);
$this->assertEquals(str_replace('%path%', str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9_compiled.php')), $dumper->dump(), '->dump() dumps services');
$dumper = new PhpDumper($container = new ContainerBuilder());
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
try {
$dumper->dump();
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (\Exception $e) {
$this->assertInstanceOf('\Symfony\Component\DependencyInjection\Exception\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
}
/**
* @group legacy
*/
public function testLegacySynchronizedServices()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$container = include self::$fixturesPath.'/containers/container20.php';
$dumper = new PhpDumper($container);
$this->assertEquals(str_replace('%path%', str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services20.php')), $dumper->dump(), '->dump() dumps services');
}
public function testServicesWithAnonymousFactories()
{
$container = include self::$fixturesPath.'/containers/container19.php';
$dumper = new PhpDumper($container);
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services19.php', $dumper->dump(), '->dump() dumps services with anonymous factories');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Service id "bar$" cannot be converted to a valid PHP method name.
*/
public function testAddServiceInvalidServiceId()
{
$container = new ContainerBuilder();
$container->register('bar$', 'FooClass');
$dumper = new PhpDumper($container);
$dumper->dump();
}
public function testAliases()
{
$container = include self::$fixturesPath.'/containers/container9.php';
$container->compile();
$dumper = new PhpDumper($container);
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Aliases')));
$container = new \Symfony_DI_PhpDumper_Test_Aliases();
$container->set('foo', $foo = new \stdClass());
$this->assertSame($foo, $container->get('foo'));
$this->assertSame($foo, $container->get('alias_for_foo'));
$this->assertSame($foo, $container->get('alias_for_alias'));
}
public function testFrozenContainerWithoutAliases()
{
$container = new ContainerBuilder();
$container->compile();
$dumper = new PhpDumper($container);
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Frozen_No_Aliases')));
$container = new \Symfony_DI_PhpDumper_Test_Frozen_No_Aliases();
$this->assertFalse($container->has('foo'));
}
public function testOverrideServiceWhenUsingADumpedContainer()
{
require_once self::$fixturesPath.'/php/services9.php';
require_once self::$fixturesPath.'/includes/foo.php';
$container = new \ProjectServiceContainer();
$container->set('bar', $bar = new \stdClass());
$container->setParameter('foo_bar', 'foo_bar');
$this->assertEquals($bar, $container->get('bar'), '->set() overrides an already defined service');
}
public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFromAnotherOne()
{
require_once self::$fixturesPath.'/php/services9.php';
require_once self::$fixturesPath.'/includes/foo.php';
require_once self::$fixturesPath.'/includes/classes.php';
$container = new \ProjectServiceContainer();
$container->set('bar', $bar = new \stdClass());
$this->assertSame($bar, $container->get('foo')->bar, '->set() overrides an already defined service');
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
*/
public function testCircularReference()
{
$container = new ContainerBuilder();
$container->register('foo', 'stdClass')->addArgument(new Reference('bar'));
$container->register('bar', 'stdClass')->setPublic(false)->addMethodCall('setA', array(new Reference('baz')));
$container->register('baz', 'stdClass')->addMethodCall('setA', array(new Reference('foo')));
$container->compile();
$dumper = new PhpDumper($container);
$dumper->dump();
}
}

View file

@ -0,0 +1,186 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Dumper;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
class XmlDumperTest extends \PHPUnit_Framework_TestCase
{
protected static $fixturesPath;
public static function setUpBeforeClass()
{
self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
}
public function testDump()
{
$dumper = new XmlDumper(new ContainerBuilder());
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/xml/services1.xml', $dumper->dump(), '->dump() dumps an empty container as an empty XML file');
}
public function testExportParameters()
{
$container = include self::$fixturesPath.'//containers/container8.php';
$dumper = new XmlDumper($container);
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/xml/services8.xml', $dumper->dump(), '->dump() dumps parameters');
}
public function testAddParameters()
{
$container = include self::$fixturesPath.'//containers/container8.php';
$dumper = new XmlDumper($container);
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/xml/services8.xml', $dumper->dump(), '->dump() dumps parameters');
}
/**
* @group legacy
*/
public function testLegacyAddService()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$container = include self::$fixturesPath.'/containers/legacy-container9.php';
$dumper = new XmlDumper($container);
$this->assertEquals(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/xml/legacy-services9.xml')), $dumper->dump(), '->dump() dumps services');
$dumper = new XmlDumper($container = new ContainerBuilder());
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
try {
$dumper->dump();
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
}
public function testAddService()
{
$container = include self::$fixturesPath.'/containers/container9.php';
$dumper = new XmlDumper($container);
$this->assertEquals(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/xml/services9.xml')), $dumper->dump(), '->dump() dumps services');
$dumper = new XmlDumper($container = new ContainerBuilder());
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
try {
$dumper->dump();
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
}
public function testDumpAnonymousServices()
{
$container = include self::$fixturesPath.'/containers/container11.php';
$dumper = new XmlDumper($container);
$this->assertEquals('<?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="foo" class="FooClass">
<argument type="service">
<service class="BarClass">
<argument type="service">
<service class="BazClass"/>
</argument>
</service>
</argument>
</service>
</services>
</container>
', $dumper->dump());
}
public function testDumpEntities()
{
$container = include self::$fixturesPath.'/containers/container12.php';
$dumper = new XmlDumper($container);
$this->assertEquals("<?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=\"foo\" class=\"FooClass\Foo\">
<tag name=\"foo&quot;bar\bar\" foo=\"foo&quot;barřž€\"/>
<argument>foo&lt;&gt;&amp;bar</argument>
</service>
</services>
</container>
", $dumper->dump());
}
/**
* @dataProvider provideDecoratedServicesData
*/
public function testDumpDecoratedServices($expectedXmlDump, $container)
{
$dumper = new XmlDumper($container);
$this->assertEquals($expectedXmlDump, $dumper->dump());
}
public function provideDecoratedServicesData()
{
$fixturesPath = realpath(__DIR__.'/../Fixtures/');
return array(
array("<?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=\"foo\" class=\"FooClass\Foo\" decorates=\"bar\" decoration-inner-name=\"bar.woozy\"/>
</services>
</container>
", include $fixturesPath.'/containers/container15.php'),
array("<?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=\"foo\" class=\"FooClass\Foo\" decorates=\"bar\"/>
</services>
</container>
", include $fixturesPath.'/containers/container16.php'),
);
}
/**
* @dataProvider provideCompiledContainerData
*/
public function testCompiledContainerCanBeDumped($containerFile)
{
$fixturesPath = __DIR__.'/../Fixtures';
$container = require $fixturesPath.'/containers/'.$containerFile.'.php';
$container->compile();
$dumper = new XmlDumper($container);
$dumper->dump();
}
public function provideCompiledContainerData()
{
return array(
array('container8'),
array('container9'),
array('container11'),
array('container12'),
array('container14'),
);
}
public function testDumpInlinedServices()
{
$container = include self::$fixturesPath.'/containers/container21.php';
$dumper = new XmlDumper($container);
$this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services21.xml'), $dumper->dump());
}
}

View file

@ -0,0 +1,82 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Dumper;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\YamlDumper;
class YamlDumperTest extends \PHPUnit_Framework_TestCase
{
protected static $fixturesPath;
public static function setUpBeforeClass()
{
self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
}
public function testDump()
{
$dumper = new YamlDumper($container = new ContainerBuilder());
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services1.yml', $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
$container = new ContainerBuilder();
$dumper = new YamlDumper($container);
}
public function testAddParameters()
{
$container = include self::$fixturesPath.'/containers/container8.php';
$dumper = new YamlDumper($container);
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services8.yml', $dumper->dump(), '->dump() dumps parameters');
}
/**
* @group legacy
*/
public function testLegacyAddService()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$container = include self::$fixturesPath.'/containers/legacy-container9.php';
$dumper = new YamlDumper($container);
$this->assertEquals(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/yaml/legacy-services9.yml')), $dumper->dump(), '->dump() dumps services');
$dumper = new YamlDumper($container = new ContainerBuilder());
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
try {
$dumper->dump();
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
}
public function testAddService()
{
$container = include self::$fixturesPath.'/containers/container9.php';
$dumper = new YamlDumper($container);
$this->assertEquals(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/yaml/services9.yml')), $dumper->dump(), '->dump() dumps services');
$dumper = new YamlDumper($container = new ContainerBuilder());
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
try {
$dumper->dump();
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
}
}

View file

@ -0,0 +1,81 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Extension;
class ExtensionTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getResolvedEnabledFixtures
*/
public function testIsConfigEnabledReturnsTheResolvedValue($enabled)
{
$pb = $this->getMockBuilder('Symfony\Component\DependencyInjection\ParameterBag\ParameterBag')
->setMethods(array('resolveValue'))
->getMock()
;
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
->setMethods(array('getParameterBag'))
->getMock()
;
$pb->expects($this->once())
->method('resolveValue')
->with($this->equalTo($enabled))
->will($this->returnValue($enabled))
;
$container->expects($this->once())
->method('getParameterBag')
->will($this->returnValue($pb))
;
$extension = $this->getMockBuilder('Symfony\Component\DependencyInjection\Extension\Extension')
->setMethods(array())
->getMockForAbstractClass()
;
$r = new \ReflectionMethod('Symfony\Component\DependencyInjection\Extension\Extension', 'isConfigEnabled');
$r->setAccessible(true);
$r->invoke($extension, $container, array('enabled' => $enabled));
}
public function getResolvedEnabledFixtures()
{
return array(
array(true),
array(false),
);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage The config array has no 'enabled' key.
*/
public function testIsConfigEnabledOnNonEnableableConfig()
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
->getMock()
;
$extension = $this->getMockBuilder('Symfony\Component\DependencyInjection\Extension\Extension')
->setMethods(array())
->getMockForAbstractClass()
;
$r = new \ReflectionMethod('Symfony\Component\DependencyInjection\Extension\Extension', 'isConfigEnabled');
$r->setAccessible(true);
$r->invoke($extension, $container, array());
}
}

View file

@ -0,0 +1,14 @@
<?php
require_once __DIR__.'/../includes/classes.php';
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
$container = new ContainerBuilder();
$container->
register('foo', 'FooClass')->
addArgument(new Reference('bar'))
;
return $container;

View file

@ -0,0 +1,12 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
$container = new ContainerBuilder();
$container->
register('foo', 'FooClass')->
addArgument(new Definition('BarClass', array(new Definition('BazClass'))))
;
return $container;

View file

@ -0,0 +1,12 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
$container = new ContainerBuilder();
$container->
register('foo', 'FooClass\\Foo')->
addArgument('foo<>&bar')->
addTag('foo"bar\\bar', array('foo' => 'foo"barřž€'))
;
return $container;

View file

@ -0,0 +1,16 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
$container = new ContainerBuilder();
$container->
register('foo', 'FooClass')->
addArgument(new Reference('bar'))
;
$container->
register('bar', 'BarClass')
;
$container->compile();
return $container;

View file

@ -0,0 +1,17 @@
<?php
namespace Container14;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* This file is included in Tests\Dumper\GraphvizDumperTest::testDumpWithFrozenCustomClassContainer
* and Tests\Dumper\XmlDumperTest::testCompiledContainerCanBeDumped.
*/
if (!class_exists('Container14\ProjectServiceContainer')) {
class ProjectServiceContainer extends ContainerBuilder
{
}
}
return new ProjectServiceContainer();

View file

@ -0,0 +1,11 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
$container = new ContainerBuilder();
$container
->register('foo', 'FooClass\\Foo')
->setDecoratedService('bar', 'bar.woozy')
;
return $container;

View file

@ -0,0 +1,11 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
$container = new ContainerBuilder();
$container
->register('foo', 'FooClass\\Foo')
->setDecoratedService('bar')
;
return $container;

View file

@ -0,0 +1,10 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
$container = new ContainerBuilder();
$container
->register('foo', '%foo.class%')
;
return $container;

View file

@ -0,0 +1,14 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Scope;
$container = new ContainerBuilder();
$container->addScope(new Scope('request'));
$container->
register('foo', 'FooClass')->
setScope('request')
;
$container->compile();
return $container;

View file

@ -0,0 +1,22 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
require_once __DIR__.'/../includes/classes.php';
$container = new ContainerBuilder();
$container
->register('service_from_anonymous_factory', 'Bar\FooClass')
->setFactory(array(new Definition('Bar\FooClass'), 'getInstance'))
;
$anonymousServiceWithFactory = new Definition('Bar\FooClass');
$anonymousServiceWithFactory->setFactory('Bar\FooClass::getInstance');
$container
->register('service_with_method_call_and_factory', 'Bar\FooClass')
->addMethodCall('setBar', array($anonymousServiceWithFactory))
;
return $container;

View file

@ -0,0 +1,19 @@
<?php
require_once __DIR__.'/../includes/classes.php';
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
$container = new ContainerBuilder();
$container
->register('request', 'Request')
->setSynchronized(true)
;
$container
->register('depends_on_request', 'stdClass')
->addMethodCall('setRequest', array(new Reference('request', ContainerInterface::NULL_ON_INVALID_REFERENCE, false)))
;
return $container;

View file

@ -0,0 +1,20 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
$container = new ContainerBuilder();
$bar = new Definition('Bar');
$bar->setConfigurator(array(new Definition('Baz'), 'configureBar'));
$fooFactory = new Definition('FooFactory');
$fooFactory->setFactory(array(new Definition('Foobar'), 'createFooFactory'));
$container
->register('foo', 'Foo')
->setFactory(array($fooFactory, 'createFoo'))
->setConfigurator(array($bar, 'configureFoo'))
;
return $container;

View file

@ -0,0 +1,14 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
$container = new ContainerBuilder(new ParameterBag(array(
'FOO' => '%baz%',
'baz' => 'bar',
'bar' => 'foo is %%foo bar',
'escape' => '@escapeme',
'values' => array(true, false, null, 0, 1000.3, 'true', 'false', 'null'),
)));
return $container;

View file

@ -0,0 +1,113 @@
<?php
require_once __DIR__.'/../includes/classes.php';
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\ExpressionLanguage\Expression;
$container = new ContainerBuilder();
$container
->register('foo', 'Bar\FooClass')
->addTag('foo', array('foo' => 'foo'))
->addTag('foo', array('bar' => 'bar', 'baz' => 'baz'))
->setFactory(array('Bar\\FooClass', 'getInstance'))
->setArguments(array('foo', new Reference('foo.baz'), array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%'), true, new Reference('service_container')))
->setProperties(array('foo' => 'bar', 'moo' => new Reference('foo.baz'), 'qux' => array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%')))
->addMethodCall('setBar', array(new Reference('bar')))
->addMethodCall('initialize')
->setConfigurator('sc_configure')
;
$container
->register('foo.baz', '%baz_class%')
->setFactory(array('%baz_class%', 'getInstance'))
->setConfigurator(array('%baz_class%', 'configureStatic1'))
;
$container
->register('bar', 'Bar\FooClass')
->setArguments(array('foo', new Reference('foo.baz'), new Parameter('foo_bar')))
->setScope('container')
->setConfigurator(array(new Reference('foo.baz'), 'configure'))
;
$container
->register('foo_bar', '%foo_class%')
->setScope('prototype')
;
$container->getParameterBag()->clear();
$container->getParameterBag()->add(array(
'baz_class' => 'BazClass',
'foo_class' => 'Bar\FooClass',
'foo' => 'bar',
));
$container->setAlias('alias_for_foo', 'foo');
$container->setAlias('alias_for_alias', 'alias_for_foo');
$container
->register('method_call1', 'Bar\FooClass')
->setFile(realpath(__DIR__.'/../includes/foo.php'))
->addMethodCall('setBar', array(new Reference('foo')))
->addMethodCall('setBar', array(new Reference('foo2', ContainerInterface::NULL_ON_INVALID_REFERENCE)))
->addMethodCall('setBar', array(new Reference('foo3', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))
->addMethodCall('setBar', array(new Reference('foobaz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))
->addMethodCall('setBar', array(new Expression('service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")')))
;
$container
->register('foo_with_inline', 'Foo')
->addMethodCall('setBar', array(new Reference('inlined')))
;
$container
->register('inlined', 'Bar')
->setProperty('pub', 'pub')
->addMethodCall('setBaz', array(new Reference('baz')))
->setPublic(false)
;
$container
->register('baz', 'Baz')
->addMethodCall('setFoo', array(new Reference('foo_with_inline')))
;
$container
->register('request', 'Request')
->setSynthetic(true)
;
$container
->register('configurator_service', 'ConfClass')
->setPublic(false)
->addMethodCall('setFoo', array(new Reference('baz')))
;
$container
->register('configured_service', 'stdClass')
->setConfigurator(array(new Reference('configurator_service'), 'configureStdClass'))
;
$container
->register('decorated', 'stdClass')
;
$container
->register('decorator_service', 'stdClass')
->setDecoratedService('decorated')
;
$container
->register('decorator_service_with_name', 'stdClass')
->setDecoratedService('decorated', 'decorated.pif-pouf')
;
$container
->register('new_factory', 'FactoryClass')
->setProperty('foo', 'bar')
->setScope('container')
->setPublic(false)
;
$container
->register('factory_service', 'Bar')
->setFactory(array(new Reference('foo.baz'), 'getInstance'))
;
$container
->register('new_factory_service', 'FooBarBaz')
->setProperty('foo', 'bar')
->setFactory(array(new Reference('new_factory'), 'getInstance'))
;
$container
->register('service_from_static_method', 'Bar\FooClass')
->setFactory(array('Bar\FooClass', 'getInstance'))
;
return $container;

View file

@ -0,0 +1,39 @@
<?php
require_once __DIR__.'/../includes/classes.php';
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ExpressionLanguage\Expression;
$container = new ContainerBuilder();
$container->
register('foo', 'Bar\FooClass')->
addTag('foo', array('foo' => 'foo'))->
addTag('foo', array('bar' => 'bar'))->
setFactoryClass('Bar\\FooClass')->
setFactoryMethod('getInstance')->
setArguments(array('foo', new Reference('foo.baz'), array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%'), true, new Reference('service_container')))->
setProperties(array('foo' => 'bar', 'moo' => new Reference('foo.baz'), 'qux' => array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%')))->
addMethodCall('setBar', array(new Reference('bar')))->
addMethodCall('initialize')->
setConfigurator('sc_configure')
;
$container->
register('foo.baz', '%baz_class%')->
setFactoryClass('%baz_class%')->
setFactoryMethod('getInstance')->
setConfigurator(array('%baz_class%', 'configureStatic1'))
;
$container->
register('factory_service', 'Bar')->
setFactoryService('foo.baz')->
setFactoryMethod('getInstance')
;
$container->getParameterBag()->clear();
$container->getParameterBag()->add(array(
'baz_class' => 'BazClass',
'foo' => 'bar',
));
return $container;

View file

@ -0,0 +1,15 @@
digraph sc {
ratio="compress"
node [fontsize="11" fontname="Arial" shape="record"];
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
node_foo [label="foo\nBar\\FooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_foo_baz [label="foo.baz\nBazClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_factory_service [label="factory_service\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
node_bar [label="bar\n\n", shape=record, fillcolor="#ff9999", style="filled"];
node_foo -> node_foo_baz [label="" style="filled"];
node_foo -> node_service_container [label="" style="filled"];
node_foo -> node_foo_baz [label="" style="dashed"];
node_foo -> node_bar [label="setBar()" style="dashed"];
}

View file

@ -0,0 +1,7 @@
digraph sc {
ratio="compress"
node [fontsize="11" fontname="Arial" shape="record"];
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
}

View file

@ -0,0 +1,10 @@
digraph sc {
ratio="normal"
node [fontsize="13" fontname="Verdana" shape="square"];
edge [fontsize="12" fontname="Verdana" color="white" arrowhead="closed" arrowsize="1"];
node_foo [label="foo\nFooClass\n", shape=square, fillcolor="grey", style="filled"];
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=square, fillcolor="green", style="empty"];
node_bar [label="bar\n\n", shape=square, fillcolor="red", style="empty"];
node_foo -> node_bar [label="" style="filled"];
}

View file

@ -0,0 +1,10 @@
digraph sc {
ratio="compress"
node [fontsize="11" fontname="Arial" shape="record"];
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
node_foo [label="foo\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
node_bar [label="bar\n\n", shape=record, fillcolor="#ff9999", style="filled"];
node_foo -> node_bar [label="" style="filled"];
}

View file

@ -0,0 +1,10 @@
digraph sc {
ratio="compress"
node [fontsize="11" fontname="Arial" shape="record"];
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
node_foo [label="foo\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_bar [label="bar\nBarClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
node_foo -> node_bar [label="" style="filled"];
}

View file

@ -0,0 +1,7 @@
digraph sc {
ratio="compress"
node [fontsize="11" fontname="Arial" shape="record"];
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
node_service_container [label="service_container\nContainer14\\ProjectServiceContainer\n", shape=record, fillcolor="#9999ff", style="filled"];
}

View file

@ -0,0 +1,8 @@
digraph sc {
ratio="compress"
node [fontsize="11" fontname="Arial" shape="record"];
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
node_foo [label="foo\n%foo.class%\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
}

View file

@ -0,0 +1,8 @@
digraph sc {
ratio="compress"
node [fontsize="11" fontname="Arial" shape="record"];
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
node_foo [label="foo\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
}

View file

@ -0,0 +1,41 @@
digraph sc {
ratio="compress"
node [fontsize="11" fontname="Arial" shape="record"];
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
node_foo [label="foo (alias_for_foo)\nBar\\FooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_foo_baz [label="foo.baz\nBazClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_bar [label="bar\nBar\\FooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_foo_bar [label="foo_bar\nBar\\FooClass\n", shape=record, fillcolor="#eeeeee", style="dotted"];
node_method_call1 [label="method_call1\nBar\\FooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_foo_with_inline [label="foo_with_inline\nFoo\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_inlined [label="inlined\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_baz [label="baz\nBaz\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_request [label="request\nRequest\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_configurator_service [label="configurator_service\nConfClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_configured_service [label="configured_service\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_decorated [label="decorated\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_decorator_service [label="decorator_service\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_decorator_service_with_name [label="decorator_service_with_name\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_new_factory [label="new_factory\nFactoryClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_factory_service [label="factory_service\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_new_factory_service [label="new_factory_service\nFooBarBaz\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_service_from_static_method [label="service_from_static_method\nBar\\FooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", 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"];
node_foo -> node_foo_baz [label="" style="filled"];
node_foo -> node_service_container [label="" style="filled"];
node_foo -> node_foo_baz [label="" style="dashed"];
node_foo -> node_bar [label="setBar()" style="dashed"];
node_bar -> node_foo_baz [label="" style="filled"];
node_method_call1 -> node_foo [label="setBar()" style="dashed"];
node_method_call1 -> node_foo2 [label="setBar()" style="dashed"];
node_method_call1 -> node_foo3 [label="setBar()" style="dashed"];
node_method_call1 -> node_foobaz [label="setBar()" style="dashed"];
node_foo_with_inline -> node_inlined [label="setBar()" style="dashed"];
node_inlined -> node_baz [label="setBaz()" style="dashed"];
node_baz -> node_foo_with_inline [label="setFoo()" style="dashed"];
node_configurator_service -> node_baz [label="setFoo()" style="dashed"];
}

View file

@ -0,0 +1,40 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
class ProjectExtension implements ExtensionInterface
{
public function load(array $configs, ContainerBuilder $configuration)
{
$config = call_user_func_array('array_merge', $configs);
$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;
}
public function getXsdValidationBasePath()
{
return false;
}
public function getNamespace()
{
return 'http://www.example.com/schema/project';
}
public function getAlias()
{
return 'project';
}
public function getConfiguration(array $config, ContainerBuilder $container)
{
}
}

View file

@ -0,0 +1,19 @@
<?php
class ProjectWithXsdExtension extends ProjectExtension
{
public function getXsdValidationBasePath()
{
return __DIR__.'/schema';
}
public function getNamespace()
{
return 'http://www.example.com/schema/projectwithxsd';
}
public function getAlias()
{
return 'projectwithxsd';
}
}

View file

@ -0,0 +1,61 @@
<?php
function sc_configure($instance)
{
$instance->configure();
}
class BarClass
{
protected $baz;
public $foo = 'foo';
public function setBaz(BazClass $baz)
{
$this->baz = $baz;
}
public function getBaz()
{
return $this->baz;
}
}
class BazClass
{
protected $foo;
public function setFoo(Foo $foo)
{
$this->foo = $foo;
}
public function configure($instance)
{
$instance->configure();
}
public static function getInstance()
{
return new self();
}
public static function configureStatic($instance)
{
$instance->configure();
}
public static function configureStatic1()
{
}
}
class BarUserClass
{
public $bar;
public function __construct(BarClass $bar)
{
$this->bar = $bar;
}
}

View file

@ -0,0 +1,47 @@
<?php
$file = __DIR__.'/ProjectWithXsdExtensionInPhar.phar';
if (is_file($file)) {
@unlink($file);
}
$phar = new Phar($file, 0, 'ProjectWithXsdExtensionInPhar.phar');
$phar->addFromString('ProjectWithXsdExtensionInPhar.php', <<<EOT
<?php
class ProjectWithXsdExtensionInPhar extends ProjectExtension
{
public function getXsdValidationBasePath()
{
return __DIR__.'/schema';
}
public function getNamespace()
{
return 'http://www.example.com/schema/projectwithxsdinphar';
}
public function getAlias()
{
return 'projectwithxsdinphar';
}
}
EOT
);
$phar->addFromString('schema/project-1.0.xsd', <<<EOT
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns="http://www.example.com/schema/projectwithxsdinphar"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/schema/projectwithxsdinphar"
elementFormDefault="qualified">
<xsd:element name="bar" type="bar" />
<xsd:complexType name="bar">
<xsd:attribute name="foo" type="xsd:string" />
</xsd:complexType>
</xsd:schema>
EOT
);
$phar->setStub('<?php require_once "phar://ProjectWithXsdExtensionInPhar.phar/ProjectWithXsdExtensionInPhar.php"; __HALT_COMPILER(); ?>');

View file

@ -0,0 +1,38 @@
<?php
namespace Bar;
class FooClass
{
public $foo, $moo;
public $bar = null, $initialized = false, $configured = false, $called = false, $arguments = array();
public function __construct($arguments = array())
{
$this->arguments = $arguments;
}
public static function getInstance($arguments = array())
{
$obj = new self($arguments);
$obj->called = true;
return $obj;
}
public function initialize()
{
$this->initialized = true;
}
public function configure()
{
$this->configured = true;
}
public function setBar($value = null)
{
$this->bar = $value;
}
}

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns="http://www.example.com/schema/projectwithxsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/schema/projectwithxsd"
elementFormDefault="qualified">
<xsd:element name="bar" type="bar" />
<xsd:complexType name="bar">
<xsd:attribute name="foo" type="xsd:string" />
</xsd:complexType>
</xsd:schema>

View file

@ -0,0 +1,2 @@
{NOT AN INI FILE}
{JUST A PLAIN TEXT FILE}

View file

@ -0,0 +1,3 @@
[parameters]
foo = bar
bar = %foo%

View file

@ -0,0 +1,3 @@
[parameters]
FOO = foo
baz = baz

View file

@ -0,0 +1,2 @@
[parameters]
imported_from_ini = true

View file

@ -0,0 +1,30 @@
<?php
namespace Symfony\Component\DependencyInjection\Dump;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
* Container.
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class Container extends AbstractContainer
{
private $parameters;
private $targetDirs = array();
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
}
}

View file

@ -0,0 +1,29 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
* ProjectServiceContainer.
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
}
}

View file

@ -0,0 +1,118 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
/**
* ProjectServiceContainer.
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();
/**
* Constructor.
*/
public function __construct()
{
$this->parameters = $this->getDefaultParameters();
$this->services =
$this->scopedServices =
$this->scopeStacks = array();
$this->scopes = array();
$this->scopeChildren = array();
$this->methodMap = array(
'test' => 'getTestService',
);
$this->aliases = array();
}
/**
* {@inheritdoc}
*/
public function compile()
{
throw new LogicException('You cannot compile a dumped frozen container.');
}
/**
* Gets the 'test' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance.
*/
protected function getTestService()
{
return $this->services['test'] = new \stdClass(array('only dot' => '.', 'concatenation as value' => '.\'\'.', 'concatenation from the start value' => '\'\'.', '.' => 'dot as a key', '.\'\'.' => 'concatenation as a key', '\'\'.' => 'concatenation from the start key', 'optimize concatenation' => 'string1-string2', 'optimize concatenation with empty string' => 'string1string2', 'optimize concatenation from the start' => 'start', 'optimize concatenation at the end' => 'end'));
}
/**
* {@inheritdoc}
*/
public function getParameter($name)
{
$name = strtolower($name);
if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
return $this->parameters[$name];
}
/**
* {@inheritdoc}
*/
public function hasParameter($name)
{
$name = strtolower($name);
return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters);
}
/**
* {@inheritdoc}
*/
public function setParameter($name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}
/**
* {@inheritdoc}
*/
public function getParameterBag()
{
if (null === $this->parameterBag) {
$this->parameterBag = new FrozenParameterBag($this->parameters);
}
return $this->parameterBag;
}
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return array(
'empty_value' => '',
'some_string' => '-',
);
}
}

View file

@ -0,0 +1,124 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
/**
* ProjectServiceContainer.
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();
/**
* Constructor.
*/
public function __construct()
{
$dir = __DIR__;
for ($i = 1; $i <= 5; ++$i) {
$this->targetDirs[$i] = $dir = dirname($dir);
}
$this->parameters = $this->getDefaultParameters();
$this->services =
$this->scopedServices =
$this->scopeStacks = array();
$this->scopes = array();
$this->scopeChildren = array();
$this->methodMap = array(
'test' => 'getTestService',
);
$this->aliases = array();
}
/**
* {@inheritdoc}
*/
public function compile()
{
throw new LogicException('You cannot compile a dumped frozen container.');
}
/**
* Gets the 'test' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance.
*/
protected function getTestService()
{
return $this->services['test'] = new \stdClass(('wiz'.$this->targetDirs[1]), array(('wiz'.$this->targetDirs[1]) => ($this->targetDirs[2].'/')));
}
/**
* {@inheritdoc}
*/
public function getParameter($name)
{
$name = strtolower($name);
if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
return $this->parameters[$name];
}
/**
* {@inheritdoc}
*/
public function hasParameter($name)
{
$name = strtolower($name);
return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters);
}
/**
* {@inheritdoc}
*/
public function setParameter($name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}
/**
* {@inheritdoc}
*/
public function getParameterBag()
{
if (null === $this->parameterBag) {
$this->parameterBag = new FrozenParameterBag($this->parameters);
}
return $this->parameterBag;
}
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return array(
'foo' => ('wiz'.$this->targetDirs[1]),
'bar' => __DIR__,
'baz' => (__DIR__.'/PhpDumperTest.php'),
'buz' => $this->targetDirs[2],
);
}
}

View file

@ -0,0 +1,63 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
* ProjectServiceContainer.
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
$this->methodMap = array(
'service_from_anonymous_factory' => 'getServiceFromAnonymousFactoryService',
'service_with_method_call_and_factory' => 'getServiceWithMethodCallAndFactoryService',
);
}
/**
* Gets the 'service_from_anonymous_factory' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar\FooClass A Bar\FooClass instance.
*/
protected function getServiceFromAnonymousFactoryService()
{
return $this->services['service_from_anonymous_factory'] = call_user_func(array(new \Bar\FooClass(), 'getInstance'));
}
/**
* Gets the 'service_with_method_call_and_factory' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar\FooClass A Bar\FooClass instance.
*/
protected function getServiceWithMethodCallAndFactoryService()
{
$this->services['service_with_method_call_and_factory'] = $instance = new \Bar\FooClass();
$instance->setBar(\Bar\FooClass::getInstance());
return $instance;
}
}

View file

@ -0,0 +1,73 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
* ProjectServiceContainer.
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
$this->methodMap = array(
'depends_on_request' => 'getDependsOnRequestService',
'request' => 'getRequestService',
);
}
/**
* Gets the 'depends_on_request' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance.
*/
protected function getDependsOnRequestService()
{
$this->services['depends_on_request'] = $instance = new \stdClass();
$instance->setRequest($this->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE));
return $instance;
}
/**
* Gets the 'request' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Request A Request instance.
*/
protected function getRequestService()
{
return $this->services['request'] = new \Request();
}
/**
* Updates the 'request' service.
*/
protected function synchronizeRequestService()
{
if ($this->initialized('depends_on_request')) {
$this->get('depends_on_request')->setRequest($this->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}
}
}

View file

@ -0,0 +1,54 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
* ProjectServiceContainer.
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();
/**
* Constructor.
*/
public function __construct()
{
parent::__construct(new ParameterBag($this->getDefaultParameters()));
}
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return array(
'foo' => '%baz%',
'baz' => 'bar',
'bar' => 'foo is %%foo bar',
'escape' => '@escapeme',
'values' => array(
0 => true,
1 => false,
2 => NULL,
3 => 0,
4 => 1000.3,
5 => 'true',
6 => 'false',
7 => 'null',
),
);
}
}

View file

@ -0,0 +1,376 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
* ProjectServiceContainer.
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();
/**
* Constructor.
*/
public function __construct()
{
parent::__construct(new ParameterBag($this->getDefaultParameters()));
$this->methodMap = array(
'bar' => 'getBarService',
'baz' => 'getBazService',
'configurator_service' => 'getConfiguratorServiceService',
'configured_service' => 'getConfiguredServiceService',
'decorated' => 'getDecoratedService',
'decorator_service' => 'getDecoratorServiceService',
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
'factory_service' => 'getFactoryServiceService',
'foo' => 'getFooService',
'foo.baz' => 'getFoo_BazService',
'foo_bar' => 'getFooBarService',
'foo_with_inline' => 'getFooWithInlineService',
'inlined' => 'getInlinedService',
'method_call1' => 'getMethodCall1Service',
'new_factory' => 'getNewFactoryService',
'new_factory_service' => 'getNewFactoryServiceService',
'request' => 'getRequestService',
'service_from_static_method' => 'getServiceFromStaticMethodService',
);
$this->aliases = array(
'alias_for_alias' => 'foo',
'alias_for_foo' => 'foo',
);
}
/**
* Gets the 'bar' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar\FooClass A Bar\FooClass instance.
*/
protected function getBarService()
{
$a = $this->get('foo.baz');
$this->services['bar'] = $instance = new \Bar\FooClass('foo', $a, $this->getParameter('foo_bar'));
$a->configure($instance);
return $instance;
}
/**
* Gets the 'baz' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Baz A Baz instance.
*/
protected function getBazService()
{
$this->services['baz'] = $instance = new \Baz();
$instance->setFoo($this->get('foo_with_inline'));
return $instance;
}
/**
* Gets the 'configured_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance.
*/
protected function getConfiguredServiceService()
{
$this->services['configured_service'] = $instance = new \stdClass();
$this->get('configurator_service')->configureStdClass($instance);
return $instance;
}
/**
* Gets the 'decorated' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance.
*/
protected function getDecoratedService()
{
return $this->services['decorated'] = new \stdClass();
}
/**
* Gets the 'decorator_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance.
*/
protected function getDecoratorServiceService()
{
return $this->services['decorator_service'] = new \stdClass();
}
/**
* Gets the 'decorator_service_with_name' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance.
*/
protected function getDecoratorServiceWithNameService()
{
return $this->services['decorator_service_with_name'] = new \stdClass();
}
/**
* Gets the 'factory_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar A Bar instance.
*/
protected function getFactoryServiceService()
{
return $this->services['factory_service'] = $this->get('foo.baz')->getInstance();
}
/**
* Gets the 'foo' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar\FooClass A Bar\FooClass instance.
*/
protected function getFooService()
{
$a = $this->get('foo.baz');
$this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo')), true, $this);
$instance->setBar($this->get('bar'));
$instance->initialize();
$instance->foo = 'bar';
$instance->moo = $a;
$instance->qux = array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo'));
sc_configure($instance);
return $instance;
}
/**
* Gets the 'foo.baz' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return object A %baz_class% instance.
*/
protected function getFoo_BazService()
{
$this->services['foo.baz'] = $instance = call_user_func(array($this->getParameter('baz_class'), 'getInstance'));
call_user_func(array($this->getParameter('baz_class'), 'configureStatic1'), $instance);
return $instance;
}
/**
* Gets the 'foo_bar' service.
*
* @return object A %foo_class% instance.
*/
protected function getFooBarService()
{
$class = $this->getParameter('foo_class');
return new $class();
}
/**
* Gets the 'foo_with_inline' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Foo A Foo instance.
*/
protected function getFooWithInlineService()
{
$this->services['foo_with_inline'] = $instance = new \Foo();
$instance->setBar($this->get('inlined'));
return $instance;
}
/**
* Gets the 'method_call1' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar\FooClass A Bar\FooClass instance.
*/
protected function getMethodCall1Service()
{
require_once '%path%foo.php';
$this->services['method_call1'] = $instance = new \Bar\FooClass();
$instance->setBar($this->get('foo'));
$instance->setBar($this->get('foo2', ContainerInterface::NULL_ON_INVALID_REFERENCE));
if ($this->has('foo3')) {
$instance->setBar($this->get('foo3', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}
if ($this->has('foobaz')) {
$instance->setBar($this->get('foobaz', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}
$instance->setBar(($this->get("foo")->foo() . (($this->hasparameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
return $instance;
}
/**
* Gets the 'new_factory_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \FooBarBaz A FooBarBaz instance.
*/
protected function getNewFactoryServiceService()
{
$this->services['new_factory_service'] = $instance = $this->get('new_factory')->getInstance();
$instance->foo = 'bar';
return $instance;
}
/**
* Gets the 'request' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @throws RuntimeException always since this service is expected to be injected dynamically
*/
protected function getRequestService()
{
throw new RuntimeException('You have requested a synthetic service ("request"). The DIC does not know how to construct this service.');
}
/**
* Gets the 'service_from_static_method' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar\FooClass A Bar\FooClass instance.
*/
protected function getServiceFromStaticMethodService()
{
return $this->services['service_from_static_method'] = \Bar\FooClass::getInstance();
}
/**
* Gets the 'configurator_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* This service is private.
* If you want to be able to request this service from the container directly,
* make it public, otherwise you might end up with broken code.
*
* @return \ConfClass A ConfClass instance.
*/
protected function getConfiguratorServiceService()
{
$this->services['configurator_service'] = $instance = new \ConfClass();
$instance->setFoo($this->get('baz'));
return $instance;
}
/**
* Gets the 'inlined' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* This service is private.
* If you want to be able to request this service from the container directly,
* make it public, otherwise you might end up with broken code.
*
* @return \Bar A Bar instance.
*/
protected function getInlinedService()
{
$this->services['inlined'] = $instance = new \Bar();
$instance->setBaz($this->get('baz'));
$instance->pub = 'pub';
return $instance;
}
/**
* Gets the 'new_factory' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* This service is private.
* If you want to be able to request this service from the container directly,
* make it public, otherwise you might end up with broken code.
*
* @return \FactoryClass A FactoryClass instance.
*/
protected function getNewFactoryService()
{
$this->services['new_factory'] = $instance = new \FactoryClass();
$instance->foo = 'bar';
return $instance;
}
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return array(
'baz_class' => 'BazClass',
'foo_class' => 'Bar\\FooClass',
'foo' => 'bar',
);
}
}

View file

@ -0,0 +1,357 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
/**
* ProjectServiceContainer.
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();
/**
* Constructor.
*/
public function __construct()
{
$this->parameters = $this->getDefaultParameters();
$this->services =
$this->scopedServices =
$this->scopeStacks = array();
$this->scopes = array();
$this->scopeChildren = array();
$this->methodMap = array(
'bar' => 'getBarService',
'baz' => 'getBazService',
'configured_service' => 'getConfiguredServiceService',
'decorator_service' => 'getDecoratorServiceService',
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
'factory_service' => 'getFactoryServiceService',
'foo' => 'getFooService',
'foo.baz' => 'getFoo_BazService',
'foo_bar' => 'getFooBarService',
'foo_with_inline' => 'getFooWithInlineService',
'method_call1' => 'getMethodCall1Service',
'new_factory_service' => 'getNewFactoryServiceService',
'request' => 'getRequestService',
'service_from_static_method' => 'getServiceFromStaticMethodService',
);
$this->aliases = array(
'alias_for_alias' => 'foo',
'alias_for_foo' => 'foo',
'decorated' => 'decorator_service_with_name',
);
}
/**
* {@inheritdoc}
*/
public function compile()
{
throw new LogicException('You cannot compile a dumped frozen container.');
}
/**
* Gets the 'bar' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar\FooClass A Bar\FooClass instance.
*/
protected function getBarService()
{
$a = $this->get('foo.baz');
$this->services['bar'] = $instance = new \Bar\FooClass('foo', $a, $this->getParameter('foo_bar'));
$a->configure($instance);
return $instance;
}
/**
* Gets the 'baz' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Baz A Baz instance.
*/
protected function getBazService()
{
$this->services['baz'] = $instance = new \Baz();
$instance->setFoo($this->get('foo_with_inline'));
return $instance;
}
/**
* Gets the 'configured_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance.
*/
protected function getConfiguredServiceService()
{
$a = new \ConfClass();
$a->setFoo($this->get('baz'));
$this->services['configured_service'] = $instance = new \stdClass();
$a->configureStdClass($instance);
return $instance;
}
/**
* Gets the 'decorator_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance.
*/
protected function getDecoratorServiceService()
{
return $this->services['decorator_service'] = new \stdClass();
}
/**
* Gets the 'decorator_service_with_name' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance.
*/
protected function getDecoratorServiceWithNameService()
{
return $this->services['decorator_service_with_name'] = new \stdClass();
}
/**
* Gets the 'factory_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar A Bar instance.
*/
protected function getFactoryServiceService()
{
return $this->services['factory_service'] = $this->get('foo.baz')->getInstance();
}
/**
* Gets the 'foo' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar\FooClass A Bar\FooClass instance.
*/
protected function getFooService()
{
$a = $this->get('foo.baz');
$this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, array('bar' => 'foo is bar', 'foobar' => 'bar'), true, $this);
$instance->setBar($this->get('bar'));
$instance->initialize();
$instance->foo = 'bar';
$instance->moo = $a;
$instance->qux = array('bar' => 'foo is bar', 'foobar' => 'bar');
sc_configure($instance);
return $instance;
}
/**
* Gets the 'foo.baz' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \BazClass A BazClass instance.
*/
protected function getFoo_BazService()
{
$this->services['foo.baz'] = $instance = \BazClass::getInstance();
\BazClass::configureStatic1($instance);
return $instance;
}
/**
* Gets the 'foo_bar' service.
*
* @return \Bar\FooClass A Bar\FooClass instance.
*/
protected function getFooBarService()
{
return new \Bar\FooClass();
}
/**
* Gets the 'foo_with_inline' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Foo A Foo instance.
*/
protected function getFooWithInlineService()
{
$a = new \Bar();
$this->services['foo_with_inline'] = $instance = new \Foo();
$a->setBaz($this->get('baz'));
$a->pub = 'pub';
$instance->setBar($a);
return $instance;
}
/**
* Gets the 'method_call1' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar\FooClass A Bar\FooClass instance.
*/
protected function getMethodCall1Service()
{
require_once '%path%foo.php';
$this->services['method_call1'] = $instance = new \Bar\FooClass();
$instance->setBar($this->get('foo'));
$instance->setBar(NULL);
$instance->setBar(($this->get("foo")->foo() . (($this->hasparameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
return $instance;
}
/**
* Gets the 'new_factory_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \FooBarBaz A FooBarBaz instance.
*/
protected function getNewFactoryServiceService()
{
$a = new \FactoryClass();
$a->foo = 'bar';
$this->services['new_factory_service'] = $instance = $a->getInstance();
$instance->foo = 'bar';
return $instance;
}
/**
* Gets the 'request' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @throws RuntimeException always since this service is expected to be injected dynamically
*/
protected function getRequestService()
{
throw new RuntimeException('You have requested a synthetic service ("request"). The DIC does not know how to construct this service.');
}
/**
* Gets the 'service_from_static_method' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Bar\FooClass A Bar\FooClass instance.
*/
protected function getServiceFromStaticMethodService()
{
return $this->services['service_from_static_method'] = \Bar\FooClass::getInstance();
}
/**
* {@inheritdoc}
*/
public function getParameter($name)
{
$name = strtolower($name);
if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
return $this->parameters[$name];
}
/**
* {@inheritdoc}
*/
public function hasParameter($name)
{
$name = strtolower($name);
return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters);
}
/**
* {@inheritdoc}
*/
public function setParameter($name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}
/**
* {@inheritdoc}
*/
public function getParameterBag()
{
if (null === $this->parameterBag) {
$this->parameterBag = new FrozenParameterBag($this->parameters);
}
return $this->parameterBag;
}
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return array(
'baz_class' => 'BazClass',
'foo_class' => 'Bar\\FooClass',
'foo' => 'bar',
);
}
}

View file

@ -0,0 +1,3 @@
<?php
$container->setParameter('foo', 'foo');

View file

@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<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="extension1.foo" class="FooClass1">
<argument type="service">
<service class="BarClass1">
</service>
</argument>
</service>
</services>
</container>

View file

@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<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="extension2.foo" class="FooClass2">
<argument type="service">
<service class="BarClass2">
</service>
</argument>
</service>
</services>
</container>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
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 babar="babar">
<another />
<another2>%project.parameter.foo%</another2>
</project:bar>
</container>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:project="http://www.example.com/schema/projectwithxsd"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://www.example.com/schema/projectwithxsd http://www.example.com/schema/projectwithxsd/project-1.0.xsd">
<parameters>
<parameter key="project.parameter.foo">BAR</parameter>
</parameters>
<services>
<service id="project.service.foo" class="BAR" />
</services>
<project:bar />
</container>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:project="http://www.example.com/schema/projectwithxsd"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://www.example.com/schema/projectwithxsd http://www.example.com/schema/projectwithxsd/project-1.0.xsd">
<parameters>
<parameter key="project.parameter.foo">BAR</parameter>
</parameters>
<services>
<service id="project.service.foo" class="BAR" />
</services>
<project:bar bar="bar" />
</container>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:project="http://www.example.com/schema/not_registered_extension">
<project:bar />
</container>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:project="http://www.example.com/schema/projectwithxsd"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://www.example.com/schema/projectwithxsd http://www.example.com/schema/projectwithxsd/project-1.0.xsd">
<project:foobar />
</container>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:project="http://www.example.com/schema/projectwithxsdinphar"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://www.example.com/schema/projectwithxsdinphar http://www.example.com/schema/projectwithxsdinphar/project-1.0.xsd">
<project:bar />
</container>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:project="http://www.example.com/schema/projectwithxsdinphar"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://www.example.com/schema/projectwithxsdinphar http://www.example.com/schema/projectwithxsdinphar/project-1.0.xsd">
<project:bar bar="foo" />
</container>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" ?>
<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="constructor" class="FooClass" factory-method="getInstance" />
<service id="factory_service" factory-method="getInstance" factory-service="baz_factory" />
</services>
</container>

View file

@ -0,0 +1,36 @@
<?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">
<parameters>
<parameter key="baz_class">BazClass</parameter>
<parameter key="foo">bar</parameter>
</parameters>
<services>
<service id="foo" class="Bar\FooClass" factory-method="getInstance" factory-class="Bar\FooClass">
<tag name="foo" foo="foo"/>
<tag name="foo" bar="bar"/>
<argument>foo</argument>
<argument type="service" id="foo.baz"/>
<argument type="collection">
<argument key="%foo%">foo is %foo%</argument>
<argument key="foobar">%foo%</argument>
</argument>
<argument>true</argument>
<argument type="service" id="service_container"/>
<property name="foo">bar</property>
<property name="moo" type="service" id="foo.baz"/>
<property name="qux" type="collection">
<property key="%foo%">foo is %foo%</property>
<property key="foobar">%foo%</property>
</property>
<call method="setBar">
<argument type="service" id="bar"/>
</call>
<call method="initialize"/>
<configurator function="sc_configure"/>
</service>
<service id="foo.baz" class="%baz_class%" factory-method="getInstance" factory-class="%baz_class%">
<configurator class="%baz_class%" method="configureStatic1"/>
</service>
<service id="factory_service" class="Bar" factory-method="getInstance" factory-service="foo.baz"/>
</services>
</container>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" ?>
<srv:container xmlns="http://symfony.com/schema/dic/doctrine"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
<srv:services>
<srv:service id="foo" class="FooClass">
<srv:tag name="foo.tag" />
<srv:call method="setBar">
<srv:argument>foo</srv:argument>
</srv:call>
</srv:service>
</srv:services>
</srv:container>

View file

@ -0,0 +1,3 @@
<?xml version="1.0" ?>
<nonvalid />

View file

@ -0,0 +1,2 @@
<?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"/>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" ?>
<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="foo" class="BarClass">
<tag name="foo_tag"
some-option="cat"
some_option="ciz"
other-option="lorem"
an_other-option="ipsum"
/>
</service>
</services>
</container>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" ?>
<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">
<parameters>
<parameter key="imported_from_xml">true</parameter>
</parameters>
</container>

View file

@ -0,0 +1,19 @@
<?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="monolog.logger" parent="monolog.logger_prototype" public="false">
<argument index="0">app</argument>
</service>
<service id="logger" alias="monolog.logger" />
<service id="monolog.logger" parent="monolog.logger_prototype" public="false">
<argument index="0">app</argument>
</service>
<service id="monolog.logger_prototype" class="Symfony\Bridge\Monolog\Logger" abstract="true">
<argument /><!-- Channel -->
</service>
</services>
</container>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" ?>
<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">
<parameters>
<parameter>a string</parameter>
<parameter key="FOO">bar</parameter>
<parameter key="values" type="collection">
<parameter>0</parameter>
<parameter key="integer">4</parameter>
<parameter key="100">null</parameter>
<parameter type="string">true</parameter>
<parameter>true</parameter>
<parameter>false</parameter>
<parameter>on</parameter>
<parameter>off</parameter>
<parameter key="float">1.3</parameter>
<parameter>1000.3</parameter>
<parameter>a string</parameter>
<parameter type="collection">
<parameter>foo</parameter>
<parameter>bar</parameter>
</parameter>
</parameter>
<parameter key="MixedCase" type="collection"> <!-- Should be lower cased -->
<parameter key="MixedCaseKey">value</parameter> <!-- Should stay mixed case -->
</parameter>
<parameter key="constant" type="constant">PHP_EOL</parameter>
</parameters>
</container>

View file

@ -0,0 +1,11 @@
<?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="request" class="Request" synthetic="true" synchronized="true"/>
<service id="depends_on_request" class="stdClass">
<call method="setRequest">
<argument type="service" id="request" on-invalid="null" strict="false"/>
</call>
</service>
</services>
</container>

View file

@ -0,0 +1,21 @@
<?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="foo" class="Foo">
<factory method="createFoo">
<service class="FooFactory">
<factory method="createFooFactory">
<service class="Foobar"/>
</factory>
</service>
</factory>
<configurator method="configureFoo">
<service class="Bar">
<configurator method="configureBar">
<service class="Baz"/>
</configurator>
</service>
</configurator>
</service>
</services>
</container>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<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">
<parameters>
<parameter key="foo">foo</parameter>
<parameter key="values" type="collection">
<parameter>true</parameter>
<parameter>false</parameter>
</parameter>
</parameters>
</container>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<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">
<imports>
<import resource="services2.xml" />
<import resource="services3.xml" />
<import resource="../ini/parameters.ini" />
<import resource="../ini/parameters2.ini" />
<import resource="../yaml/services13.yml" />
</imports>
</container>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" ?>
<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">
<imports>
<import resource="foo_fake.xml" ignore-errors="true" />
</imports>
</container>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" ?>
<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="foo" class="FooClass">
<argument type="service">
<service class="BarClass">
<argument type="service">
<service class="BazClass">
</service>
</argument>
</service>
</argument>
<property name="p" type="service">
<service class="BazClass" />
</property>
</service>
</services>
</container>

View file

@ -0,0 +1,63 @@
<?xml version="1.0" ?>
<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="foo" class="FooClass" />
<service id="baz" class="BazClass" />
<service id="scope.container" class="FooClass" scope="container" />
<service id="scope.custom" class="FooClass" scope="custom" />
<service id="scope.prototype" class="FooClass" scope="prototype" />
<service id="file" class="FooClass">
<file>%path%/foo.php</file>
</service>
<service id="arguments" class="FooClass">
<argument>foo</argument>
<argument type="service" id="foo" />
<argument type="collection">
<argument>true</argument>
<argument>false</argument>
</argument>
</service>
<service id="configurator1" class="FooClass">
<configurator function="sc_configure" />
</service>
<service id="configurator2" class="FooClass">
<configurator service="baz" method="configure" />
</service>
<service id="configurator3" class="FooClass">
<configurator class="BazClass" method="configureStatic" />
</service>
<service id="method_call1" class="FooClass">
<call method="setBar" />
<call method="setBar">
<argument type="expression">service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")</argument>
</call>
</service>
<service id="method_call2" class="FooClass">
<call method="setBar">
<argument>foo</argument>
<argument type="service" id="foo" />
<argument type="collection">
<argument>true</argument>
<argument>false</argument>
</argument>
</call>
</service>
<service id="alias_for_foo" alias="foo" />
<service id="another_alias_for_foo" alias="foo" public="false" />
<service id="request" class="Request" synthetic="true" synchronized="true" lazy="true"/>
<service id="decorator_service" decorates="decorated" />
<service id="decorator_service_with_name" decorates="decorated" decoration-inner-name="decorated.pif-pouf"/>
<service id="new_factory1" class="FooBarClass">
<factory function="factory" />
</service>
<service id="new_factory2" class="FooBarClass">
<factory service="baz" method="getClass" />
</service>
<service id="new_factory3" class="FooBarClass">
<factory class="BazClass" method="getInstance" />
</service>
</services>
</container>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" ?>
<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="foo" class="BarClass" />
</services>
</container>

View file

@ -0,0 +1,22 @@
<?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">
<parameters>
<parameter key="foo">%baz%</parameter>
<parameter key="baz">bar</parameter>
<parameter key="bar">foo is %%foo bar</parameter>
<parameter key="escape">@escapeme</parameter>
<parameter key="values" type="collection">
<parameter>true</parameter>
<parameter>false</parameter>
<parameter>null</parameter>
<parameter>0</parameter>
<parameter>1000.3</parameter>
<parameter type="string">true</parameter>
<parameter type="string">false</parameter>
<parameter type="string">null</parameter>
</parameter>
</parameters>
</container>

View file

@ -0,0 +1,106 @@
<?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">
<parameters>
<parameter key="baz_class">BazClass</parameter>
<parameter key="foo_class">Bar\FooClass</parameter>
<parameter key="foo">bar</parameter>
</parameters>
<services>
<service id="foo" class="Bar\FooClass">
<tag name="foo" foo="foo"/>
<tag name="foo" bar="bar" baz="baz"/>
<argument>foo</argument>
<argument type="service" id="foo.baz"/>
<argument type="collection">
<argument key="%foo%">foo is %foo%</argument>
<argument key="foobar">%foo%</argument>
</argument>
<argument>true</argument>
<argument type="service" id="service_container"/>
<property name="foo">bar</property>
<property name="moo" type="service" id="foo.baz"/>
<property name="qux" type="collection">
<property key="%foo%">foo is %foo%</property>
<property key="foobar">%foo%</property>
</property>
<call method="setBar">
<argument type="service" id="bar"/>
</call>
<call method="initialize"/>
<factory class="Bar\FooClass" method="getInstance"/>
<configurator function="sc_configure"/>
</service>
<service id="foo.baz" class="%baz_class%">
<factory class="%baz_class%" method="getInstance"/>
<configurator class="%baz_class%" method="configureStatic1"/>
</service>
<service id="bar" class="Bar\FooClass">
<argument>foo</argument>
<argument type="service" id="foo.baz"/>
<argument>%foo_bar%</argument>
<configurator service="foo.baz" method="configure"/>
</service>
<service id="foo_bar" class="%foo_class%" scope="prototype"/>
<service id="method_call1" class="Bar\FooClass">
<file>%path%foo.php</file>
<call method="setBar">
<argument type="service" id="foo"/>
</call>
<call method="setBar">
<argument type="service" id="foo2" on-invalid="null"/>
</call>
<call method="setBar">
<argument type="service" id="foo3" on-invalid="ignore"/>
</call>
<call method="setBar">
<argument type="service" id="foobaz" on-invalid="ignore"/>
</call>
<call method="setBar">
<argument type="expression">service("foo").foo() ~ (container.hasparameter("foo") ? parameter("foo") : "default")</argument>
</call>
</service>
<service id="foo_with_inline" class="Foo">
<call method="setBar">
<argument type="service" id="inlined"/>
</call>
</service>
<service id="inlined" class="Bar" public="false">
<property name="pub">pub</property>
<call method="setBaz">
<argument type="service" id="baz"/>
</call>
</service>
<service id="baz" class="Baz">
<call method="setFoo">
<argument type="service" id="foo_with_inline"/>
</call>
</service>
<service id="request" class="Request" synthetic="true"/>
<service id="configurator_service" class="ConfClass" public="false">
<call method="setFoo">
<argument type="service" id="baz"/>
</call>
</service>
<service id="configured_service" class="stdClass">
<configurator service="configurator_service" method="configureStdClass"/>
</service>
<service id="decorated" class="stdClass"/>
<service id="decorator_service" class="stdClass" decorates="decorated"/>
<service id="decorator_service_with_name" class="stdClass" decorates="decorated" decoration-inner-name="decorated.pif-pouf"/>
<service id="new_factory" class="FactoryClass" public="false">
<property name="foo">bar</property>
</service>
<service id="factory_service" class="Bar">
<factory service="foo.baz" method="getInstance"/>
</service>
<service id="new_factory_service" class="FooBarBaz">
<property name="foo">bar</property>
<factory service="new_factory" method="getInstance"/>
</service>
<service id="service_from_static_method" class="Bar\FooClass">
<factory class="Bar\FooClass" method="getInstance"/>
</service>
<service id="alias_for_foo" alias="foo"/>
<service id="alias_for_alias" alias="foo"/>
</services>
</container>

View file

@ -0,0 +1,3 @@
<?xml version="1.0"?>
<!DOCTYPE foo>
<foo></foo>

Some files were not shown because too many files have changed in this diff Show more