-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
added Twig_Source to hold information about the original template #2182
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
Conversation
c762379
to
d57a59b
Compare
'source' => $source, | ||
'filename' => $filename, | ||
'source' => $source->getCode(), | ||
// to be renamed in 2.0 to name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then let's add name right now?
'source' => $source->getCode(), | ||
// to be renamed in 2.0 to name | ||
'filename' => $source->getName(), | ||
// to be renamed in 2.0 to filename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but that would be a hard break, no continuous upgrade path
@@ -14,7 +14,7 @@ | |||
* | |||
* @author Fabien Potencier <fabien@symfony.com> | |||
*/ | |||
class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface | |||
class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the chain loader should implement Twig_SourceContextLoaderInterface too, otherwise we loose the capabilities when using multiple loaders
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
*/ | ||
public function getSourceContext() | ||
{ | ||
return new Twig_Source(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->getTemplateName()
should be passed as second argument here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
private $name; | ||
private $filename; | ||
|
||
public function __construct($code, $name = null, $filename = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add phpdoc to document the variable types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
interface Twig_SourceContextLoaderInterface | ||
{ | ||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing phpdoc for the argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
if (null !== $filename || null !== $source) { | ||
@trigger_error(sprintf('Passing a string as the $filename argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); | ||
} | ||
$this->source = new Twig_Source($filename, $source); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is wrong. the first argument of Twig_Source
is the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add legacy tests covering the deprecated APIs. They would catch such mistakes (and forbid breaking BC by mistake)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, tests coming
@@ -39,7 +39,7 @@ public function parse(Twig_Token $token) | |||
} else { | |||
$expr = $this->parser->getExpressionParser()->parseExpression(); | |||
if (!$expr instanceof Twig_Node_Expression_Constant) { | |||
throw new Twig_Error_Syntax('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getFilename()); | |||
throw new Twig_Error_Syntax('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $this->parser->getFilename()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not using $stream->getSourceContext()->getName()
directly to avoid 1 level in the stack each time ? the parser will forward the call to the stream anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've deprecated Parser::getFilename()
as having a proxy does not make sense and because the method is wrong anyway, it returns the logical name, not the filename.
9a885eb
to
f63d882
Compare
I've extracted the deprecation of |
f63d882
to
b09c9ce
Compare
Rebased on top of #2183, reviewing the second commit only gives you less noise. Renamed |
5868aa5
to
8303f4a
Compare
This PR was merged into the 1.x branch. Discussion ---------- deprecated Parser::getFilename() The name is misleading as it returns the logical template name and not the proper filesystem path. In #2182, this is then replaced with a proper object. This PR simplifies the code review for #2182 by avoiding the pollution of all the changes in the token parser classes. Commits ------- d77f3dd deprecated Parser::getFilename()
a989b79
to
25495ef
Compare
Tests added, not WIP anymore |
25495ef
to
6c76583
Compare
This PR was merged into the 2.7 branch. Discussion ---------- [Twig] removed deprecations added in Twig 1.27 | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | see twigphp/Twig#2182 | License | MIT | Doc PR | n/a Commits ------- f0849d8 [TwigBridge] removed deprecations added in Twig 1.27
This PR was merged into the 2.7 branch. Discussion ---------- [Twig] removed deprecations added in Twig 1.27 | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | see twigphp/Twig#2182 | License | MIT | Doc PR | n/a Commits ------- f0849d8 [TwigBridge] removed deprecations added in Twig 1.27
$exceptions = array(); | ||
foreach ($this->loaders as $loader) { | ||
if (!$loader instanceof Twig_SourceContextLoaderInterface) { | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is broken in case this loader was the one loading the template, but a next loader could load a template with the same name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in #2192
Causes a BC break when upgrading from 1.26 and prior to twig 1.27 as described here: |
This addresses some issues with symfony that resulted in issues when open_basedir restrictions were enabled, as well as issues with JPEG images in fast-image-size. The phpBB class extending the twig lexer also had to be modified to ensure compatibility after BC was broken by the PR twigphp/Twig#2182 for twig 1.27. PHPBB3-14716
@stof But that doesn't mean that someone could have implemented the interface before which will no indeed break their code when updating to Twig 1.27. |
My reply to @stof 's comment: Should probably continue the discussion here as that's more accessible to other users than having the discussion in the commit. edit: Created issue as pointed out by stof |
This addresses some issues with symfony that resulted in issues when open_basedir restrictions were enabled, as well as issues with JPEG images in fast-image-size. The phpBB class extending the twig lexer also had to be modified to ensure compatibility after BC was broken by the PR twigphp/Twig#2182 for twig 1.27. PHPBB3-14716
This addresses some issues with symfony that resulted in issues when open_basedir restrictions were enabled, as well as issues with JPEG images in fast-image-size. The phpBB class extending the twig lexer also had to be modified to ensure compatibility after BC was broken by the PR twigphp/Twig#2182 for twig 1.27. PHPBB3-14716
Alternative to #2170