-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Duplicated cache file after upgrade Twig to 1.30.x #21055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@lcobucci Could you please create a simple example project (best by forking the Symfony Standard Edition) that makes it possible to reproduc 8000 e the issue you experience? |
@xabbuh sure, will do that ASAP and link the fork here 😉 |
@xabbuh I managed to reproduce the issue on https://github.com/lcobucci/symfony-standard/tree/template-issues # bin/console cache:clear --no-debug --env=prod
# grep 'testing.html.twig' -r var/cache/prod/
var/cache/prod//templates.php:86: 'AppBundle::testing.html.twig' => __DIR__.'/../../../src/AppBundle/Resources/views/testing.html.twig',
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:3:/* @App/testing.html.twig */
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:11: $this->parent = $this->loadTemplate("AppBundle::base.html.twig", "@App/testing.html.twig", 1);
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:52: $this->loadTemplate("@App/testing.html.twig", "@App/testing.html.twig", 12, "155133146")->display($context);
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:57: return "@App/testing.html.twig";
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:80: return new Twig_Source("", "@App/testing.html.twig", "/Users/lcobucci/vms/symfony-standard/src/AppBundle/Resources/views/testing.html.twig");
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:85:/* @App/testing.html.twig */
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:100: return $this->loadTemplate(($context["template"] ?? null), "@App/testing.html.twig", 12);
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:128: return "@App/testing.html.twig";
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:151: return new Twig_Source("", "@App/testing.html.twig", "/Users/lcobucci/vms/symfony-standard/src/AppBundle/Resources/views/testing.html.twig");
var/cache/prod//twig/dc/dc5bbd702e150d2eacc80255a6a1616d6d5131cddfd195dc212b2262723affb3.php:3:/* AppBundle::testing.html.twig */
var/cache/prod//twig/dc/dc5bbd702e150d2eacc80255a6a1616d6d5131cddfd195dc212b2262723affb3.php:11: $this->parent = $this->loadTemplate("AppBundle::base.html.twig", "AppBundle::testing.html.twig", 1);
var/cache/prod//twig/dc/dc5bbd702e150d2eacc80255a6a1616d6d5131cddfd195dc212b2262723affb3.php:52: $this->loadTemplate("AppBundle::testing.html.twig", "AppBundle::testing.html.twig", 12, "834562958")->display($context);
var/cache/prod//twig/dc/dc5bbd702e150d2eacc80255a6a1616d6d5131cddfd195dc212b2262723affb3.php:57: return "AppBundle::testing.html.twig";
var/cache/prod//twig/dc/dc5bbd702e150d2eacc80255a6a1616d6d5131cddfd195dc212b2262723affb3.php:80: return new Twig_Source("", "AppBundle::testing.html.twig", "/Users/lcobucci/vms/symfony-standard/var/cache/prod/../../../src/AppBundle/Resources/views/testing.html.twig");
var/cache/prod//twig/dc/dc5bbd702e150d2eacc80255a6a1616d6d5131cddfd195dc212b2262723affb3.php:85:/* AppBundle::testing.html.twig */
var/cache/prod//twig/dc/dc5bbd702e150d2eacc80255a6a1616d6d5131cddfd195dc212b2262723affb3.php:100:
8000
return $this->loadTemplate(($context["template"] ?? null), "AppBundle::testing.html.twig", 12);
var/cache/prod//twig/dc/dc5bbd702e150d2eacc80255a6a1616d6d5131cddfd195dc212b2262723affb3.php:128: return "AppBundle::testing.html.twig";
var/cache/prod//twig/dc/dc5bbd702e150d2eacc80255a6a1616d6d5131cddfd195dc212b2262723affb3.php:151: return new Twig_Source("", "AppBundle::testing.html.twig", "/Users/lcobucci/vms/symfony-standard/var/cache/prod/../../../src/AppBundle/Resources/views/testing.html.twig"); After changing <?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Templating\TemplateReferenceInterface;
/**
* FilesystemLoader extends the default Twig filesystem loader
* to work with the Symfony paths and template references.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class FilesystemLoader extends \Twig_Loader_Filesystem
{
protected $locator;
protected $parser;
/**
* Constructor.
*
* @param FileLocatorInterface $locator A FileLocatorInterface instance
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
* @param string|null $rootPath The root path common to all relative paths (null for getcwd())
*/
public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser, $rootPath = null)
{
parent::__construct(array(), $rootPath);
$this->locator = $locator;
$this->parser = $parser;
}
/**
* {@inheritdoc}
*
* The name parameter might also be a TemplateReferenceInterface.
*/
public function exists($name)
{
return parent::exists((string) $name);
}
/**
* Returns the path to the template file.
*
* The file locator is used to locate the template when the naming convention
* is the symfony one (i.e. the name can be parsed).
* Otherwise the template is located using the locator from the twig library.
*
* @param string|TemplateReferenceInterface $template The template
* @param bool $throw When true, a \Twig_Error_Loader exception will be thrown if a template could not be found
*
* @return string The path to the template file
*
* @throws \Twig_Error_Loader if the template could not be found
*/
protected function findTemplate($template, $throw = true)
{
$logicalName = (string) $template;
if (isset($this->cache[$logicalName])) {
return $this->cache[$logicalName];
}
$file = null;
$previous = null;
try {
$file = parent::findTemplate($logicalName);
} catch (\Twig_Error_Loader $e) {
$twigLoaderException = $e;
// for BC
try {
$template = $this->parser->parse($template);
$file = $this->locator->locate($template);
if (false !== $realpath = realpath($file)) {
$file = $realpath;
}
} catch (\Exception $e) {
}
}
if (false === $file || null === $file) {
if ($throw) {
throw $twigLoaderException;
}
return false;
}
return $this->cache[$logicalName] = $file;
}
} I have this result: # bin/console cache:clear --no-debug --env=prod
# grep 'testing.html.twig' -r var/cache/prod/
var/cache/prod//templates.php:86: 'AppBundle::testing.html.twig' => __DIR__.'/../../../src/AppBundle/Resources/views/testing.html.twig',
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:3:/* @App/testing.html.twig */
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:11: $this->parent = $this->loadTemplate("AppBundle::base.html.twig", "@App/testing.html.twig", 1);
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:52: $this->loadTemplate("@App/testing.html.twig", "@App/testing.html.twig", 12, "2063719950")->display($context);
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:57: return "@App/testing.html.twig";
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:80: return new Twig_Source("", "@App/testing.html.twig", "/Users/lcobucci/vms/symfony-standard/src/AppBundle/Resources/views/testing.html.twig");
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:85:/* @App/testing.html.twig */
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:100: return $this->loadTemplate(($context["template"] ?? null), "@App/testing.html.twig", 12);
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:128: return "@App/testing.html.twig";
var/cache/prod//twig/60/60fbe9c12702aa8e1d6d51debf3d7b3f897cab33c2a20251ef6d89a0ceee3205.php:151: return new Twig_Source("", "@App/testing.html.twig", "/Users/lcobucci/vms/symfony-standard/src/AppBundle/Resources/views/testing.html.twig"); I just didn't manage to reproduce the fatal error I'm having with our application (trying to define the class twice). |
|
@mvrhov it would work inside a phar since it would behave the same way as We have a problem because the two behaviours are incompatible. |
@lcobucci Thank you for the example project. However, I do not see any usage of the native Twig namespace syntax to reference a template. Did I miss that? |
@xabbuh indeed, I forgot to mention that I was able to reproduce it even without using the twig namespace syntax by just doing the cache warmup |
I think my issue explains yours: #21130 |
Could you please check if the changes made in #21237 already fix your issue? |
@xabbuh yes it does 😉. Closing... |
Uh oh!
There was an error while loading. Please reload this page.
On our application we're using in some places the twig namespace syntax (
@namespace/folder1/template.html.twig
) and in templates that usesembed
twig uses the SFTemplateReference
to get the logical name which leads to the SF syntax (Bundle:folder1:template.html.twig
).What happens is that twig loader loads
@namespace/folder1/template.html.twig
but fails onBundle:folder1:template.html.twig
then SF filesystem loader is used as fallback. The problem is that twig loader usesrealpath()
sincev1.27
and SF loader doesn't.I've solved that on our application by overriding SF loader and using
realpath()
as well but although it works fine I'm not 100% sure if that's the way to go (that's why I didn't send a PR):The text was updated successfully, but these errors were encountered: