Skip to content

Commit

Permalink
Merge branch '3.2'
Browse files Browse the repository at this point in the history
* 3.2:
  [DI] Add missing legacy group on testLegacy
  Minor tweaks
  Fix merge
  [DI] Dont share service when no id provided
  Fix Container and PhpDumper test inaccuracies
  [DI] Fix missing new line after private alias
  [ClassLoader] Throw an exception if the cache is not writeable
  Fixing regression in TwigEngine exception handling.
  • Loading branch information
nicolas-grekas committed Jan 10, 2017
2 parents 9e6d6ba + 1fcb66d commit 16d33e1
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 54 deletions.
Expand Up @@ -36,7 +36,6 @@ public function process(ContainerBuilder $container)
}
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment');

$aliases = $container->getAliases();
$attributes = array(
'provider',
'namespace',
Expand All @@ -59,9 +58,9 @@ public function process(ContainerBuilder $container)
$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;
Expand Down
Expand Up @@ -320,26 +320,26 @@ public function testAssets()
$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));
}

Expand All @@ -349,7 +349,7 @@ public function testAssetsDefaultVersionStrategyAsService()
$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));
}

Expand Down Expand Up @@ -865,7 +865,7 @@ private function assertUrlPackage(ContainerBuilder $container, ChildDefinition $

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 {
Expand Down
Expand Up @@ -407,7 +407,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
$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) {
Expand Down
Expand Up @@ -73,7 +73,7 @@ public function testFirewalls()
$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());
}

Expand Down Expand Up @@ -234,7 +234,7 @@ public function testAccess()
);
} 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);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Bundle/TwigBundle/TwigEngine.php
Expand Up @@ -49,16 +49,12 @@ public function render($name, array $parameters = array())
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) {
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Component/ClassLoader/ClassCollectionLoader.php
Expand Up @@ -305,7 +305,13 @@ private static function compressCode($code)
*/
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());

Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Expand Up @@ -436,7 +436,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
}

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 {
Expand Down Expand Up @@ -1240,14 +1240,14 @@ private function callMethod($service, $call)
/**
* 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;
}
}

Expand Down
Expand Up @@ -170,7 +170,7 @@ private function addServiceAlias($alias, $id)
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);
}

/**
Expand Down
Expand Up @@ -213,13 +213,13 @@ public function testCreateDefinition()
$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());
}

Expand Down
28 changes: 14 additions & 14 deletions src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php
Expand Up @@ -144,7 +144,7 @@ public function testSet()
{
$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()
Expand All @@ -166,14 +166,14 @@ 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->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('');
Expand All @@ -196,15 +196,15 @@ public function testLegacyGet()
$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('');
Expand Down
Expand Up @@ -272,7 +272,7 @@ public function testOverrideServiceWhenUsingADumpedContainer()
$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()
Expand Down Expand Up @@ -308,7 +308,7 @@ public function testDumpAutowireData()
$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()
Expand Down Expand Up @@ -466,8 +466,7 @@ public function testClosureProxy()
$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());
}
Expand All @@ -481,8 +480,7 @@ public function testClosureProxyPhp71()
$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());
}
Expand Down
Expand Up @@ -18,15 +18,15 @@ 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
request:
class: Request
synthetic: true
lazy: true
another_third_alias_for_foo:
alias: foo
decorator_service:
decorates: decorated
decorator_service_with_name:
Expand Down
Expand Up @@ -57,7 +57,7 @@ public function testGetContainerExtensionWithInvalidClass()
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
Expand Down

0 comments on commit 16d33e1

Please sign in to comment.