8000 added Twig_Source to hold information about the original template by fabpot · Pull Request #2182 · twigphp/Twig · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 1 commit into from
Oct 17, 2016

Conversation

fabpot
Copy link
Contributor
@fabpot fabpot commented Oct 15, 2016

Alternative to #2170

'source' => $source,
'filename' => $filename,
'source' => $source->getCode(),
// to be renamed in 2.0 to name
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Member

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

Copy link
Contributor Author

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('');
Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


interface Twig_SourceContextLoaderInterface
{
/**
Copy link
Member

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

Copy link
Contributor Author

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);
Copy link
Member

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

Copy link
Member

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)

Copy link
Contributor Author

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());
Copy link
Member

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

Copy link
Contributor Author

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.

@fabpot
Copy link
Contributor Author
fabpot commented Oct 17, 2016

I've extracted the deprecation of Parser::getFilename() in #2183 to make code review easier. I'm also going to drop filename and use path or filepath instead. So, name is the logical template name and path its filesystem path. That should avoid any confusion.

@fabpot fabpot force-pushed the filename-debuginfo branch from f63d882 to b09c9ce Compare October 17, 2016 18:46
@fabpot
Copy link
Contributor Author
fabpot commented Oct 17, 2016

Rebased on top of #2183, reviewing the second commit only gives you less noise. Renamed getFilename() to get getPath(). I think it's much better that way.

@fabpot fabpot force-pushed the filename-debuginfo branch 5 times, most recently from 5868aa5 to 8303f4a Compare October 17, 2016 19:04
fabpot added a commit that referenced this pull request Oct 17, 2016
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()
@fabpot fabpot force-pushed the filename-debuginfo branch 2 times, most recently from a989b79 to 25495ef Compare October 17, 2016 19:29
@fabpot
Copy link
Contributor Author
fabpot commented Oct 17, 2016

Tests added, not WIP anymore

@fabpot fabpot force-pushed the filename-debuginfo branch from 25495ef to 6c76583 Compare October 17, 2016 20:33
@fabpot fabpot merged commit 6c76583 into twigphp:1.x Oct 17, 2016
fabpot added a commit that referenced this pull request Oct 17, 2016
…l template (fabpot)

This PR was merged into the 1.x branch.

Discussion
----------

added Twig_Source to hold information about the original template

Alternative to #2170

Commits
-------

6c76583 added Twig_Source to hold information about the original template
@fabpot fabpot deleted the filename-debuginfo branch October 17, 2016 21:14
fabpot added a commit to symfony/symfony that referenced this pull request Oct 18, 2016
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
symfony-splitter pushed a commit to symfony/twig-bundle that referenced this pull request Oct 18, 2016
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;
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #2192

@marc1706
Copy link
marc1706 commented Nov 3, 2016

Causes a BC break when upgrading from 1.26 and prior to twig 1.27 as described here:
6c76583#commitcomment-19686237

marc1706 added a commit to marc1706/phpbb that referenced this pull request Nov 3, 2016
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
@xabbuh
Copy link
Contributor
xabbuh commented Nov 4, 2016

@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.

@marc1706
Copy link
marc1706 commented Nov 4, 2016

My reply to @stof 's comment:
6c76583#commitcomment-19693147

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

symfony-splitter pushed a commit to phpbb/phpbb-app that referenced this pull request Nov 14, 2016
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
symfony-splitter pushed a commit to phpbb/phpbb-core that referenced this pull request Nov 14, 2016
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0