Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use namespaced Twig #22962

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
Jun 2, 2017
Merged

Use namespaced Twig #22962

merged 1 commit into from
Jun 2, 2017

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? needs twigphp/Twig#2490 and twigphp/Twig#2491
Fixed tickets -
License MIT
Doc PR -

use Twig\Markup;
use Twig\Profiler\Dumper\HtmlDumper;
use Twig\Profiler\Profile;
use Twig\Source;
Copy link
Member Author

Choose a reason for hiding this comment

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

@keradus just wondering: this useis not used in the class - is it a php-cs-fixer bug that fabbot is still green?

Copy link
Contributor

@jvasseur jvasseur May 30, 2017

Choose a reason for hiding this comment

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

The NoUnusedImportsFixer is quite permissive (not removing an unsed import in better than removing an used one) particularly it check if the class in not referenced in a comment.

In this case it think it's the "source" word in the license header comment that make the fixer think that the class is still used.

Copy link
Member

Choose a reason for hiding this comment

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

that's exactly the case here.
Imported class name could be used in comment, even in different casing, which later is utilized by Doctrine or some annotation-parsers. that behaviour was added after fixer broke some code.
I would not focus here is it header comment or other comment actually.

One could bring configuration to fixer to ignore comments or non-docblock comments / be strict about casing !

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a way to make it more strict so that I can cleanup locally?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

go ahead @nicolas-grekas and contribute ;)

*/
public function setTwigEnvironment(\Twig_Environment $twig)
public function setTwigEnvironment(Environment $twig)
Copy link
Member

Choose a reason for hiding this comment

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

Reading this, I would rename Twig\Environment to Twig\Twig

Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to name it just Twig to avoid the Twig\Twig repetition?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep but you will have to import Twig\Twig anyway

Copy link
Member

Choose a reason for hiding this comment

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

We cannot use Twig only as all classes need to be under a namespace. That's PSR-4.

Copy link
Member

@GromNaN GromNaN May 30, 2017

Choose a reason for hiding this comment

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

@javiereguiluz PSR-4 doesn't allow top-level classes. In §2.2.1, "The fully qualified class name MUST have a top-level namespace name, also known as a “vendor namespace”.
http://www.php-fig.org/psr/psr-4/#specification

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed to Twig\Twig

@nicolas-grekas
Copy link
Member Author

Just fixed a few potential BC breaks related to the use of aliases type hints.
Should be ready, waiting for twigphp/Twig#2490

@@ -165,7 +161,7 @@ private function getMetadata($type, $entity)
return false;
}

return !$param->getClass() || $param->getClass()->getName() !== 'Twig_Environment';
return !$param->getClass() || !in_array($param->getClass()->getName(), array('Twig_Environment', 'Twig\Twig'));
Copy link
Member

Choose a reason for hiding this comment

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

Using class_alias, the ReflectionClass refers to the original class. Checking against Twig\Twig is not necessary.
https://3v4l.org/QH2KQ

Copy link
Member Author

Choose a reason for hiding this comment

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

True, until Twig moves to namespaces-first, which is why this code is here.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, this logic could be improved to avoid relying on typehints or param names (btw, the check on param name is wrong, as the name is not relevant). I will send a PR.

Copy link
Member

Choose a reason for hiding this comment

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

here you go: #22994

Copy link
Member

Choose a reason for hiding this comment

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

@nicolas-grekas please revert this change to avoid useless conflicts with my PR removing this code entirely 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

reverted, thanks

*
* @return array An array with the contexts the URL is safe
*
* To be made @final in 3.4, and the type-hint be changed to "\Twig\Node\Node" in 4.0.
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this trigger the warning already ? Or does DebugClassLoader check for beginning of lines ?

Copy link
Member Author

Choose a reason for hiding this comment

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

*
* @return array An array with the contexts the URL is safe
*
* To be made @final in 3.4, and the type-hint be changed to "\Twig\Node\Node" in 4.0.
*/
public function isUrlGenerationSafe(\Twig_Node $argsNode)
Copy link
Member

Choose a reason for hiding this comment

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

Can't we already change the typehint here (with the same class_exists call) ?

Copy link
Member Author

@nicolas-grekas nicolas-grekas May 31, 2017

Choose a reason for hiding this comment

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

We can, but that means loading Node, which in turn loads Compiler.
I preferred not, thus the current code.

@nicolas-grekas nicolas-grekas force-pushed the twig branch 3 times, most recently from 223b126 to 029377d Compare May 31, 2017 19:32
@nicolas-grekas
Copy link
Member Author

now green

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

You just need to revert the Twig\Environment => Twig\Twig change. Sorry about that :)

@nicolas-grekas
Copy link
Member Author

renaming done, now green

@nicolas-grekas nicolas-grekas merged commit c3d1262 into symfony:2.7 Jun 2, 2017
nicolas-grekas added a commit that referenced this pull request Jun 2, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

Use namespaced Twig

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | needs twigphp/Twig#2490 and twigphp/Twig#2491
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

c3d1262 Use namespaced Twig
@nicolas-grekas nicolas-grekas deleted the twig branch June 2, 2017 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.