Skip to content

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

Merged
merged 1 commit into from
Sep 12, 2013

Conversation

wouterj
Copy link
Member

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

@stof
Copy link
Member

stof commented Sep 9, 2013

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 $view['stopwatch']->getStopwatch() is null or not). On the other hand, the Twig extension handles this case gracefully when compiling the template.

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

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.

@wouterj
Copy link
Member Author

wouterj commented Sep 10, 2013

@stof I've fixed it by using a proxy class, like you suggested.

@wouterj
Copy link
Member Author

wouterj commented Sep 10, 2013

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

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

@wouterj
Copy link
Member Author

wouterj commented Sep 11, 2013

@fabpot I fixed the comments

fabpot added a commit that referenced this pull request Sep 12, 2013
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
@fabpot fabpot merged commit 3ee2989 into symfony:master Sep 12, 2013
@wouterj wouterj deleted the stopwatch_php branch May 1, 2014 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants