Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[TwigBundle] Enhance the twig not found exception#27535

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@behnoushnorouzi
Copy link
Contributor

@behnoushnorouzibehnoushnorouzi commentedJun 7, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#27468
LicenseMIT
Doc PR-

Improve error message to make it clear to developers what mistake they have made.

yceruto, fbourigault, sstok, theofidry, javiereguiluz, artjomsimon, TomasVotruba, gquemener, dmaicher, AlessandroMinoccheri, and Isinlor reacted with thumbs up emojicgrandval, sstok, theofidry, yceruto, HeahDude, and Isinlor reacted with heart emoji
try {
return parent::findTemplate($template, $throw);
} catch (LoaderError $e) {
if ($e instanceof \Twig_Error_Loader && preg_match('/^([^:]*?)(?:Bundle)?:([^:]*+):(.+\.[^\.]+\.[^\.]+)$/', $template, $m) && 0 !== strpos($template, '@')) {
Copy link
Member

Choose a reason for hiding this comment

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

theinstanceof will always be true.Twig\Error\LoaderError is a class alias ofTwig_Error_Loader.

try {
return parent::findTemplate($template, $throw);
} catch (LoaderError $e) {
if ($e instanceof \Twig_Error_Loader && preg_match('/^([^:]*?)(?:Bundle)?:([^:]*+):(.+\.[^\.]+\.[^\.]+)$/', $template, $m) && 0 !== strpos($template, '@')) {
Copy link
Member

Choose a reason for hiding this comment

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

You should switch the regex match in thestrpos. Checking the first char is faster.

Btw, you could optimize it even more:

if ('' !==$template &&'@' !==$template[0] &&preg_match(...)) {

Using strpos to check only the first char is not the fastest way.

@behnoushnorouzibehnoushnorouziforce-pushed thetwig-enhance-not-found-exception branch 2 times, most recently fromc832758 to82d1db4CompareJune 7, 2018 15:11
@nicolas-grekasnicolas-grekas added this to thenext milestoneJun 7, 2018

class NativeFilesystemLoaderTest extends TestCase
{
const DS = DIRECTORY_SEPARATOR;
Copy link
Member

Choose a reason for hiding this comment

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

I would remove this const and use the PHP one instead.

jvasseur reacted with thumbs up emoji
try {
return parent::findTemplate($template, $throw);
} catch (LoaderError $e) {
if ('' === $template || '@' === $template[0] || !preg_match('/^([^:]*?)(?:Bundle)?:([^:]*+):(.+\.[^\.]+\.[^\.]+)$/', $template, $m)) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use named patterns to make the code using$m more easily understandable?

@behnoushnorouzi
Copy link
ContributorAuthor

behnoushnorouzi commentedJun 8, 2018
edited
Loading

Thank you for the review it's done.

Status: needs review

use Twig\Error\LoaderError;
use Twig\Loader\FilesystemLoader;

class NativeFilesystemLoader extends FilesystemLoader
Copy link
Member

Choose a reason for hiding this comment

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

you may want to add yourself as the author of this class :)

tgalopin and karousn reacted with heart emoji
@behnoushnorouzibehnoushnorouziforce-pushed thetwig-enhance-not-found-exception branch froma3b665c toa5a4d48CompareJune 8, 2018 13:07
@Lewiscowles1986
Copy link

Should this emit a notice or warning if used in production?

It seems like a development pattern, and can be switched out for the extended class. Once the suggestion is implemented it seems like switching to the standard class might be more helpful.

@nicolas-grekasnicolas-grekas changed the titleEnhance the twig not found exception[TwigBundle] Enhance the twig not found exceptionJun 9, 2018
@nicolas-grekas
Copy link
Member

nicolas-grekas commentedJun 9, 2018
edited
Loading

@Lewiscowles1986 good idea, we could use the new class only in debug mode. Could be done inExtensionPass based on thekernel.debug parameter. I'd also suggest marking the class@internal.

Lewiscowles1986 reacted with thumbs up emoji

@stof
Copy link
Member

We don't even need to do it in a compiler pass. The debug parameter can be accessed in the DI extension (thekernel.* params can be accessed there safely, as they are set early)

@behnoushnorouzibehnoushnorouziforce-pushed thetwig-enhance-not-found-exception branch 2 times, most recently froma5e0738 to554b0b1CompareJune 14, 2018 12:18
Enhance the twig not found exception
@behnoushnorouzibehnoushnorouziforce-pushed thetwig-enhance-not-found-exception branch from554b0b1 to32988b4CompareJune 14, 2018 12:22
@behnoushnorouzi
Copy link
ContributorAuthor

Thank you for the review it's done.
Status: needs review

@nicolas-grekas
Copy link
Member

Thank you@behnoushnorouzi.

behnoushnorouzi reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas merged commit32988b4 intosymfony:masterJun 19, 2018
nicolas-grekas added a commit that referenced this pull requestJun 19, 2018
…noushnorouzi)This PR was merged into the 4.2-dev branch.Discussion----------[TwigBundle] Enhance the twig not found exception| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#27468| License       | MIT| Doc PR        | -Improve error message to make it clear to developers what mistake they have made.Commits-------32988b4 Enhance the twig not found exception
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
This was referencedNov 3, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@fabpotfabpotfabpot requested changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@xabbuhxabbuhxabbuh approved these changes

+2 more reviewers

@sstoksstoksstok approved these changes

@20uf20uf20uf approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

9 participants

@behnoushnorouzi@Lewiscowles1986@nicolas-grekas@stof@fabpot@sstok@xabbuh@20uf@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp