diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php index 233b01fb43..e4a86dc6ef 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php @@ -36,7 +36,6 @@ class CachePoolPass implements CompilerPassInterface } $seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment'); - $aliases = $container->getAliases(); $attributes = array( 'provider', 'namespace', @@ -59,9 +58,9 @@ class CachePoolPass implements CompilerPassInterface $tags[0]['namespace'] = $this->getNamespace($seed, $id); } if (isset($tags[0]['clearer'])) { - $clearer = strtolower($tags[0]['clearer']); - while (isset($aliases[$clearer])) { - $clearer = (string) $aliases[$clearer]; + $clearer = $tags[0]['clearer']; + while ($container->hasAlias($clearer)) { + $clearer = (string) $container->getAlias($clearer); } } else { $clearer = null; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 7254ed34a7..8b9dd97f00 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -320,26 +320,26 @@ abstract class FrameworkExtensionTest extends TestCase $packages = $container->getDefinition('assets.packages'); // default package - $defaultPackage = $container->getDefinition($packages->getArgument(0)); + $defaultPackage = $container->getDefinition((string) $packages->getArgument(0)); $this->assertUrlPackage($container, $defaultPackage, array('http://cdn.example.com'), 'SomeVersionScheme', '%%s?version=%%s'); // packages $packages = $packages->getArgument(1); $this->assertCount(5, $packages); - $package = $container->getDefinition($packages['images_path']); + $package = $container->getDefinition((string) $packages['images_path']); $this->assertPathPackage($container, $package, '/foo', 'SomeVersionScheme', '%%s?version=%%s'); - $package = $container->getDefinition($packages['images']); + $package = $container->getDefinition((string) $packages['images']); $this->assertUrlPackage($container, $package, array('http://images1.example.com', 'http://images2.example.com'), '1.0.0', '%%s?version=%%s'); - $package = $container->getDefinition($packages['foo']); + $package = $container->getDefinition((string) $packages['foo']); $this->assertPathPackage($container, $package, '', '1.0.0', '%%s-%%s'); - $package = $container->getDefinition($packages['bar']); + $package = $container->getDefinition((string) $packages['bar']); $this->assertUrlPackage($container, $package, array('https://bar2.example.com'), 'SomeVersionScheme', '%%s?version=%%s'); - $package = $container->getDefinition($packages['bar_version_strategy']); + $package = $container->getDefinition((string) $packages['bar_version_strategy']); $this->assertEquals('assets.custom_version_strategy', (string) $package->getArgument(1)); } @@ -349,7 +349,7 @@ abstract class FrameworkExtensionTest extends TestCase $packages = $container->getDefinition('assets.packages'); // default package - $defaultPackage = $container->getDefinition($packages->getArgument(0)); + $defaultPackage = $container->getDefinition((string) $packages->getArgument(0)); $this->assertEquals('assets.custom_version_strategy', (string) $defaultPackage->getArgument(1)); } @@ -865,7 +865,7 @@ abstract class FrameworkExtensionTest extends TestCase private function assertVersionStrategy(ContainerBuilder $container, Reference $reference, $version, $format) { - $versionStrategy = $container->getDefinition($reference); + $versionStrategy = $container->getDefinition((string) $reference); if (null === $version) { $this->assertEquals('assets.empty_version_strategy', (string) $reference); } else { diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index 5595b08d30..51de15b215 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -407,7 +407,7 @@ class SecurityExtension extends Extension $config->replaceArgument(8, isset($firewall['access_denied_handler']) ? $firewall['access_denied_handler'] : null); $config->replaceArgument(9, isset($firewall['access_denied_url']) ? $firewall['access_denied_url'] : null); - $container->setAlias(new Alias('security.user_checker.'.$id, false), $firewall['user_checker']); + $container->setAlias('security.user_checker.'.$id, new Alias($firewall['user_checker'], false)); foreach ($this->factories as $position) { foreach ($position as $factory) { diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php index bbce61a758..cbdb6e8f0f 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php @@ -73,7 +73,7 @@ abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase $arguments = $contextDef->getArguments(); $listeners[] = array_map(function ($ref) { return (string) $ref; }, $arguments['index_0']); - $configDef = $container->getDefinition($arguments['index_2']); + $configDef = $container->getDefinition((string) $arguments['index_2']); $configs[] = array_values($configDef->getArguments()); } @@ -234,7 +234,7 @@ abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase ); } elseif (3 === $i) { $this->assertEquals('IS_AUTHENTICATED_ANONYMOUSLY', $attributes[0]); - $expression = $container->getDefinition($attributes[1])->getArgument(0); + $expression = $container->getDefinition((string) $attributes[1])->getArgument(0); $this->assertEquals("token.getUsername() matches '/^admin/'", $expression); } } diff --git a/src/Symfony/Bundle/TwigBundle/TwigEngine.php b/src/Symfony/Bundle/TwigBundle/TwigEngine.php index 76daad58a3..503c55f6af 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigEngine.php +++ b/src/Symfony/Bundle/TwigBundle/TwigEngine.php @@ -49,16 +49,12 @@ class TwigEngine extends BaseEngine implements EngineInterface try { return parent::render($name, $parameters); } catch (\Twig_Error $e) { - if ($name instanceof TemplateReference) { + if ($name instanceof TemplateReference && !method_exists($e, 'setSourceContext')) { try { // try to get the real name of the template where the error occurred $name = $e->getTemplateName(); $path = (string) $this->locator->locate($this->parser->parse($name)); - if (method_exists($e, 'setSourceContext')) { - $e->setSourceContext(new \Twig_Source('', $name, $path)); - } else { - $e->setTemplateName($path); - } + $e->setTemplateName($path); } catch (\Exception $e2) { } } diff --git a/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php b/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php index 15e3a5a822..0079e8a798 100644 --- a/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php +++ b/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php @@ -305,7 +305,13 @@ REGEX; */ private static function writeCacheFile($file, $content) { - $tmpFile = tempnam(dirname($file), basename($file)); + $dir = dirname($file); + if (!is_writable($dir)) { + throw new \RuntimeException(sprintf('Cache directory "%s" is not writable.', $dir)); + } + + $tmpFile = tempnam($dir, basename($file)); + if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) { @chmod($file, 0666 & ~umask()); diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 63206f5cad..044d72cb54 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -436,7 +436,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface } if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) { - return $this->get($this->aliasDefinitions[$id], $invalidBehavior); + return $this->get((string) $this->aliasDefinitions[$id], $invalidBehavior); } try { @@ -1240,14 +1240,14 @@ class ContainerBuilder extends Container implements TaggedContainerInterface /** * Shares a given service in the container. * - * @param Definition $definition - * @param mixed $service - * @param string $id + * @param Definition $definition + * @param mixed $service + * @param string|null $id */ private function shareService(Definition $definition, $service, $id) { - if ($definition->isShared()) { - $this->services[$lowerId = strtolower($id)] = $service; + if (null !== $id && $definition->isShared()) { + $this->services[strtolower($id)] = $service; } } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php index b8d936658f..b6c4e6639c 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -170,7 +170,7 @@ class YamlDumper extends Dumper return sprintf(" %s: '@%s'\n", $alias, $id); } - return sprintf(" %s:\n alias: %s\n public: false", $alias, $id); + return sprintf(" %s:\n alias: %s\n public: false\n", $alias, $id); } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index 0b8ab9374a..640bbbae91 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -213,13 +213,13 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase $this->assertCount(1, $container->getDefinition('coop_tilleuls')->getArguments()); $this->assertEquals('autowired.symfony\component\dependencyinjection\tests\compiler\dunglas', $container->getDefinition('coop_tilleuls')->getArgument(0)); - $dunglasDefinition = $container->getDefinition('autowired.symfony\component\dependencyinjection\tests\compiler\dunglas'); + $dunglasDefinition = $container->getDefinition('autowired.Symfony\Component\DependencyInjection\Tests\Compiler\Dunglas'); $this->assertEquals(__NAMESPACE__.'\Dunglas', $dunglasDefinition->getClass()); $this->assertFalse($dunglasDefinition->isPublic()); $this->assertCount(1, $dunglasDefinition->getArguments()); $this->assertEquals('autowired.symfony\component\dependencyinjection\tests\compiler\lille', $dunglasDefinition->getArgument(0)); - $lilleDefinition = $container->getDefinition('autowired.symfony\component\dependencyinjection\tests\compiler\lille'); + $lilleDefinition = $container->getDefinition('autowired.Symfony\Component\DependencyInjection\Tests\Compiler\Lille'); $this->assertEquals(__NAMESPACE__.'\Lille', $lilleDefinition->getClass()); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index 31e9e97c63..20c171c798 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -144,7 +144,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { $sc = new Container(); $sc->set('foo', $foo = new \stdClass()); - $this->assertEquals($foo, $sc->get('foo'), '->set() sets a service'); + $this->assertSame($foo, $sc->get('foo'), '->set() sets a service'); } public function testSetWithNullResetTheService() @@ -166,14 +166,14 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { $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->assertSame($foo, $sc->get('foo'), '->get() returns the service for the given id'); + $this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase'); + $this->assertSame($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id'); + $this->assertSame($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined'); + $this->assertSame($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()'); + $this->assertSame($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()'); try { $sc->get(''); @@ -196,15 +196,15 @@ class ContainerTest extends \PHPUnit_Framework_TestCase $sc = new LegacyProjectServiceContainer(); $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'); + $this->assertSame($foo, $sc->get('foo'), '->get() returns the service for the given id'); + $this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase'); + $this->assertSame($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id'); + $this->assertSame($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined'); + $this->assertSame($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined'); + $this->assertSame($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()'); + $this->assertSame($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()'); try { $sc->get(''); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index 9375129a4f..7e58f6e4c5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -272,7 +272,7 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase $container->set('bar', $bar = new \stdClass()); $container->setParameter('foo_bar', 'foo_bar'); - $this->assertEquals($bar, $container->get('bar'), '->set() overrides an already defined service'); + $this->assertSame($bar, $container->get('bar'), '->set() overrides an already defined service'); } public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFromAnotherOne() @@ -308,7 +308,7 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase $container->compile(); $dumper = new PhpDumper($container); - $this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services24.php'), $dumper->dump()); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services24.php', $dumper->dump()); } public function testEnvParameter() @@ -466,8 +466,7 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase $container->compile(); $dumper = new PhpDumper($container); - $dump = $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Closure_Proxy')); - $this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services31.php'), $dumper->dump()); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services31.php', $dumper->dump()); $res = $container->getResources(); $this->assertSame(realpath(self::$fixturesPath.'/containers/container31.php'), array_pop($res)->getResource()); } @@ -481,8 +480,7 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase $container->compile(); $dumper = new PhpDumper($container); - $dump = $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Closure_Proxy_Php71')); - $this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services32.php'), $dumper->dump()); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services32.php', $dumper->dump()); $res = $container->getResources(); $this->assertSame(realpath(self::$fixturesPath.'/containers/container32.php'), array_pop($res)->getResource()); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml index 5f22bc1cae..20ed7e315a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml @@ -18,8 +18,6 @@ services: calls: - [ setBar, [ foo, '@foo', [true, false] ] ] alias_for_foo: '@foo' - another_third_alias_for_foo: - alias: foo another_alias_for_foo: alias: foo public: false @@ -27,6 +25,8 @@ services: class: Request synthetic: true lazy: true + another_third_alias_for_foo: + alias: foo decorator_service: decorates: decorated decorator_service_with_name: diff --git a/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php index fe05fe8d44..a8b91453c6 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php @@ -57,7 +57,7 @@ class BundleTest extends \PHPUnit_Framework_TestCase public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices() { $container = new ContainerBuilder(); - $container->register('console.command.Symfony_Component_HttpKernel_Tests_Fixtures_ExtensionPresentBundle_Command_FooCommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand'); + $container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand'); $application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock(); // add() is never called when the found command classes are already registered as services