File tree Expand file tree Collapse file tree 4 files changed +92
-0
lines changed Expand file tree Collapse file tree 4 files changed +92
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ CHANGELOG
5
5
-----
6
6
7
7
* allowed multiple IP addresses in profiler matcher settings
8
+ * added stopwatch helper to time templates with the WebProfilerBundle
8
9
9
10
2.3.0
10
11
-----
Original file line number Diff line number Diff line change 15
15
<parameter key =" templating.helper.code.class" >Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper</parameter >
16
16
<parameter key =" templating.helper.translator.class" >Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper</parameter >
17
17
<parameter key =" templating.helper.form.class" >Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper</parameter >
18
+ <parameter key =" templating.helper.stopwatch.class" >Symfony\Bundle\FrameworkBundle\Templating\Helper\StopwatchHelper</parameter >
18
19
<parameter key =" templating.form.engine.class" >Symfony\Component\Form\Extension\Templating\TemplatingRendererEngine</parameter >
19
20
<parameter key =" templating.form.renderer.class" >Symfony\Component\Form\FormRenderer</parameter >
20
21
<parameter key =" templating.globals.class" >Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables</parameter >
101
102
<argument type =" service" id =" templating.form.renderer" />
102
103
</service >
103
104
105
+ <service id =" templating.helper.stopwatch" class =" %templating.helper.stopwatch.class%" >
106
+ <tag name =" templating.helper" alias =" stopwatch" />
107
+ <argument type =" service" id =" debug.stopwatch" on-invalid =" ignore" />
108
+ </service >
109
+
104
110
<service id =" templating.form.engine" class =" %templating.form.engine.class%" public =" false" >
105
111
<argument type =" service" id =" templating.engine.php" />
106
112
<argument >%templating.helper.form.resources%</argument >
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Bundle \FrameworkBundle \Templating \Helper ;
13
+
14
+ use Symfony \Component \Stopwatch \Stopwatch ;
15
+ use Symfony \Component \Templating \Helper \Helper ;
16
+
17
+ /**
18
+ * StopwatchHelper provides methods time your PHP templates.
19
+ *
20
+ * @author Wouter J <wouter@wouterj.nl>
21
+ */
22
+ class StopwatchHelper extends Helper
23
+ {
24
+ private $ stopwatch ;
25
+
26
+ public function __construct (Stopwatch $ stopwatch = null )
27
+ {
28
+ $ this ->stopwatch = $ stopwatch ;
29
+ }
30
+
31
+ public function getName ()
32
+ {
33
+ return 'stopwatch ' ;
34
+ }
35
+
36
+ public function __call ($ method , $ arguments = array ())
37
+ {
38
+ if (null !== $ this ->stopwatch ) {
39
+ if (method_exists ($ this ->stopwatch , $ method )) {
40
+ return call_user_func_array (array ($ this ->stopwatch , $ method ), $ arguments );
41
+ }
42
+
43
+ throw new \BadMethodCallException (sprintf ('Method "%s" of Stopwatch does not exist ' , $ method ));
44
+ }
45
+ }
46
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Bundle \FrameworkBundle \Tests \Templating \Helper ;
13
+
14
+ use Symfony \Bundle \FrameworkBundle \Templating \Helper \StopwatchHelper ;
15
+
16
+ class StopwatchHelperTest extends \PHPUnit_Framework_TestCase
17
+ {
18
+ public function testDevEnvironment ()
19
+ {
20
+ $ stopwatch = $ this ->getMock ('Symfony\Component\Stopwatch\Stopwatch ' );
21
+ $ stopwatch ->expects ($ this ->once ())
22
+ ->method ('start ' )
23
+ ->with ('foo ' );
24
+
25
+ $ helper = new StopwatchHelper ($ stopwatch );
26
+ $ helper ->start ('foo ' );
27
+ }
28
+
29
+ public function testProdEnvironment ()
30
+ {
31
+ $ helper = new StopwatchHelper (null );
32
+
33
+ try {
34
+ $ helper ->start ('foo ' );
35
+ } catch (\BadMethodCallException $ e ) {
36
+ $ this ->fail ('Assumed stopwatch is not called when not provided ' );
37
+ }
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments