Skip to content

Commit

Permalink
[TwigBundle] Refresh twig paths when resources change.
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad authored and fabpot committed May 16, 2015
1 parent dd2fb85 commit cafb0d7
Showing 1 changed file with 5 additions and 0 deletions.
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\TwigBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Expand Down Expand Up @@ -66,22 +67,26 @@ public function load(array $configs, ContainerBuilder $container)
} else {
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace));
}
$container->addResource(new DirectoryResource($path));
}

// register bundles as Twig namespaces
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$bundle.'/views')) {
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
$container->addResource(new DirectoryResource($dir));
}

$reflection = new \ReflectionClass($class);
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/views')) {
$this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle);
$container->addResource(new DirectoryResource($dir));
}
}

if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/views')) {
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($dir));
$container->addResource(new DirectoryResource($dir));
}

if (!empty($config['globals'])) {
Expand Down

0 comments on commit cafb0d7

Please sign in to comment.