-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Added Stopwatch helper for PHP templates #8968
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
wouterj
commented
Sep 9, 2013
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | - |
License | MIT |
Doc PR | symfony/symfony-docs#2960 |
This implementation has a big drawback compared to the Twig extension: you must remove all stopwatch calls before going into prod, otherwise you get a fatal error when rendering your template calling stopwatch (or you need to check all the time in your template whether IMO, the templating helper should provide proxy methods for the Stopwatch features (being no-ops if there is no Stopwatch in the helper) instead of exposing the Stopwatch itself. |
@@ -101,6 +102,11 @@ | |||
<argument type="service" id="templating.form.renderer" /> | |||
</service> | |||
|
|||
<service id="templating.helper.stopwatch" class="%templating.helper.stopwatch.class%"> | |||
<tag name="templating.helper" alias="form" /> |
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.
alias="form"
is wrong, and it will break the form rendering (as it is registered after the real form helper, it will replace it in the engine)
@fabpot should we add a validation in the lazy PhpEngine to check that the alias is matching the real helper name (as done for form types as of Symfony 2.2) ? It would help debugging such issues. It would add 1 more check for the first retrieval of each helper only (as the instance itself is registered after that) so it would not have a huge overhead.
@stof I've fixed it by using a proxy class, like you suggested. |
After writing the docs I decided to do it different without a proxy class. |
if (null !== $this->stopwatch) { | ||
if (method_exists($this->stopwatch, $method)) { | ||
return call_user_func_array(array($this->stopwatch, $method), $arguments); | ||
} else { |
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.
no need for else
as the if
returns
@fabpot I fixed the comments |
This PR was merged into the master branch. Discussion ---------- Added Stopwatch helper for PHP templates | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | symfony/symfony-docs#2960 Commits ------- 3ee2989 Added Stopwatch Helper