diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index b44dd2481c63..f117dd47bc4f 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\TwigBundle\DependencyInjection; use Symfony\Bridge\Twig\Extension\WebLinkExtension; +use Symfony\Bundle\TwigBundle\Loader\NativeFilesystemLoader; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Resource\FileExistenceResource; use Symfony\Component\Console\Application; @@ -92,6 +93,10 @@ public function load(array $configs, ContainerBuilder $container) $twigFilesystemLoaderDefinition = $container->getDefinition('twig.loader.native_filesystem'); + if ($container->getParameter('kernel.debug')) { + $twigFilesystemLoaderDefinition->setClass(NativeFilesystemLoader::class); + } + // register user-configured paths foreach ($config['paths'] as $path => $namespace) { if (!$namespace) { diff --git a/src/Symfony/Bundle/TwigBundle/Loader/NativeFilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/NativeFilesystemLoader.php new file mode 100644 index 000000000000..9ef58d7bdbbe --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Loader/NativeFilesystemLoader.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\TwigBundle\Loader; + +use Twig\Error\LoaderError; +use Twig\Loader\FilesystemLoader; + +/** + * @author Behnoush Norouzali + * + * @internal + */ +class NativeFilesystemLoader extends FilesystemLoader +{ + /** + * {@inheritdoc} + */ + protected function findTemplate($template, $throw = true) + { + try { + return parent::findTemplate($template, $throw); + } catch (LoaderError $e) { + if ('' === $template || '@' === $template[0] || !preg_match('/^(?P[^:]*?)(?:Bundle)?:(?P[^:]*+):(?P