Skip to content
This repository was archived by the owner on Nov 24, 2019. It is now read-only.

Fixed overloading other twig extensions#2

Open
peschee wants to merge 4 commits into
RafalFilipek:masterfrom
peschee:master
Open

Fixed overloading other twig extensions#2
peschee wants to merge 4 commits into
RafalFilipek:masterfrom
peschee:master

Conversation

@peschee

@peschee peschee commented Oct 15, 2011

Copy link
Copy Markdown
Contributor

Hi

I also fixed the way you add your twig profiler extension to the application. Currently, there's no best practice yet for adding your own twig extensions (@see discussion here: https://github.com/fabpot/Silex/issues/160). I took guidance from the KnpMenu Silex extension (@see https://github.com/knplabs/KnpMenu/blob/master/src/Knp/Menu/Silex/KnpMenuServiceProvider.php) since that seems a reasonable approach.

Also, I added a check whether the Twig provider is registered. This might help with cases when it hasn't been setup yet. In that case, the profiler provider does nothing (bad).

Peter Siska added 3 commits October 15, 2011 21:41
… Other extensions should not be overloaded. Also, checking if twig extension is set, otherwise doing nothig.
@igorw

igorw commented Oct 15, 2011

Copy link
Copy Markdown

Why did you wrap it in an 'if twig'? If twig does not exist it will just fail silently.

@igorw

igorw commented Oct 15, 2011

Copy link
Copy Markdown

Not really related, but silex.after should not be set as a string. Silex\SilexEvents::BEFORE should be used instead.

@peschee

peschee commented Oct 15, 2011

Copy link
Copy Markdown
Contributor Author

True, if you don use the profiler twig tag, it will fail silently, so the ifset is indeed redundant. I still left it to skip the code block, as well as adding the twig extension if twig is not available anyway.

@RafalFilipek

Copy link
Copy Markdown
Owner

Thanks Igor i'll change it.
peschehimself - as Igo said there is no need to add this if. For now my extensions works only with Twig as its default template engine for Silex.

@peschee

peschee commented Oct 16, 2011

Copy link
Copy Markdown
Contributor Author

If you do not have the twig service provider registered, registering the profiler service will fail with a InvalidArgumentException, hence the checking for the twig identifier in $app.

@igorw

igorw commented Oct 16, 2011

Copy link
Copy Markdown

Well that's the point. If the user is missing the twig extension he wants to know why the ProfilerServiceProvider is not working. That exception is supposed to be thrown, to tell the user that he needs to add twig.

If you don't throw the exception, it will just fail silently and the user will be clueless as to why it's not working.

@peschee

peschee commented Oct 16, 2011

Copy link
Copy Markdown
Contributor Author

Fair enough, it's a point of view. I'd rather prefer to fail it silently without breaking the app, but I see what you mean.

Would you like me to adapt the PR and also incorporate the event-related change @RafalFilipek?

@RafalFilipek

Copy link
Copy Markdown
Owner

Yes :) Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants