Skip to content

Commit 18d69a8

Browse files
committed
Merge branch '2.4'
* 2.4: removed unneeded use statements [DoctrineBridge] Fixed an issue with DoctrineParserCache removed unneeded use statements Prepend Child Bundle paths before the parent [Routing] add unit tests for Symfony\Component\Routing\RequestContext class
2 parents df6b0b8 + e10d9e9 commit 18d69a8

File tree

63 files changed

+160
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+160
-80
lines changed

src/Symfony/Bridge/Doctrine/ExpressionLanguage/DoctrineParserCache.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ public function __construct(Cache $cache)
3535
*/
3636
public function fetch($key)
3737
{
38-
return $this->cache->fetch($key);
38+
if (false === $value = $this->cache->fetch($key)) {
39+
return null;
40+
}
41+
42+
return $value;
3943
}
4044

4145
/**

src/Symfony/Bridge/Doctrine/Tests/ExpressionLanguage/DoctrineParserCacheTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ public function testFetch()
2929
$this->assertEquals('bar', $result);
3030
}
3131

32+
public function testFetchUnexisting()
33+
{
34+
$doctrineCacheMock = $this->getMock('Doctrine\Common\Cache\Cache');
35+
$parserCache = new DoctrineParserCache($doctrineCacheMock);
36+
37+
$doctrineCacheMock
38+
->expects($this->once())
39+
->method('fetch')
40+
->will($this->returnValue(false));
41+
42+
$this->assertNull($parserCache->fetch(''));
43+
}
44+
3245
public function testSave()
3346
{
3447
$doctrineCacheMock = $this->getMock('Doctrine\Common\Cache\Cache');

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1514
use Symfony\Component\Translation\Catalogue\DiffOperation;
1615
use Symfony\Component\Translation\Catalogue\MergeOperation;
1716
use Symfony\Component\Console\Input\InputInterface;

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Psr\Log\LoggerInterface;
1515
use Symfony\Component\HttpKernel\Controller\ControllerResolver as BaseControllerResolver;
1616
use Symfony\Component\DependencyInjection\ContainerInterface;
17-
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
1817
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
1918

2019
/**

src/Symfony/Bundle/FrameworkBundle/Templating/DelegatingEngine.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\Templating\DelegatingEngine as BaseDelegatingEngine;
1515
use Symfony\Component\DependencyInjection\ContainerInterface;
16-
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
1716
use Symfony\Component\HttpFoundation\Response;
1817

1918
/**

src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,26 @@ public function load(array $configs, ContainerBuilder $container)
6969
}
7070

7171
// register bundles as Twig namespaces
72-
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
72+
$bundles = $this->getBundlesByChildPriority($container);
73+
foreach ($bundles as $bundle => $bundleReflection) {
74+
/** @var \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundleInstance */
75+
$bundleInstance = $bundleReflection->newInstance();
76+
77+
if (null !== $parentBundle = $bundleInstance->getParent()) {
78+
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$bundle.'/views')) {
79+
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $parentBundle);
80+
}
81+
82+
if (is_dir($dir = $bundleInstance->getPath().'/Resources/views')) {
83+
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $parentBundle);
84+
}
85+
}
86+
7387
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$bundle.'/views')) {
7488
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
7589
}
7690

77-
$reflection = new \ReflectionClass($class);
78-
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/views')) {
91+
if (is_dir($dir = $bundleInstance->getPath().'/Resources/views')) {
7992
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
8093
}
8194
}
@@ -130,12 +143,36 @@ public function load(array $configs, ContainerBuilder $container)
130143
));
131144
}
132145

146+
/**
147+
* @param ContainerBuilder $container
148+
* @return array | \ReflectionClass[]
149+
*/
150+
private function getBundlesByChildPriority(ContainerBuilder $container)
151+
{
152+
$childBundles = array();
153+
$parentBundles = array();
154+
155+
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
156+
$reflection = new \ReflectionClass($class);
157+
158+
$bundleInstance = $reflection->newInstance();
159+
if (null === $bundleInstance->getParent()) {
160+
$parentBundles[$bundle] = $reflection;
161+
} else {
162+
$childBundles[$bundle] = $reflection;
163+
}
164+
}
165+
166+
return array_merge($childBundles, $parentBundles);
167+
}
168+
133169
private function addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle)
134170
{
135171
$name = $bundle;
136172
if ('Bundle' === substr($name, -6)) {
137173
$name = substr($name, 0, -6);
138174
}
175+
139176
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($dir, $name));
140177
}
141178

src/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Config\Definition\Builder;
1313

1414
use Symfony\Component\Config\Definition\EnumNode;
15-
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
1615

1716
/**
1817
* Enum Node Definition.

src/Symfony/Component/Config/Definition/EnumNode.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Config\Definition;
1313

1414
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
15-
use Symfony\Component\Config\Definition\ScalarNode;
1615

1716
/**
1817
* Node which only allows a finite set of values.

src/Symfony/Component/Config/Definition/ScalarNode.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Config\Definition;
1313

14-
use Symfony\Component\Config\Definition\VariableNode;
1514
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
1615

1716
/**

src/Symfony/Component/Console/Output/ConsoleOutput.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Console\Output;
1313

1414
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
15-
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1615

1716
/**
1817
* ConsoleOutput is the default class for all CLI output. It uses STDOUT.

0 commit comments

Comments
 (0)