33namespace Barryvdh \Debugbar \Twig \Extension ;
44
55use DebugBar \Bridge \Twig \MeasureTwigExtension ;
6+ use DebugBar \Bridge \Twig \MeasureTwigTokenParser ;
67use Illuminate \Foundation \Application ;
78
89/**
@@ -23,28 +24,46 @@ class Stopwatch extends MeasureTwigExtension
2324 */
2425 public function __construct (Application $ app )
2526 {
26- $ timeCollector = null ;
2727 if ($ app ->bound ('debugbar ' )) {
2828 $ this ->debugbar = $ app ['debugbar ' ];
29-
30- if ($ app ['debugbar ' ]->hasCollector ('time ' )) {
31- $ timeCollector = $ app ['debugbar ' ]['time ' ];
32- }
3329 }
34-
35- parent ::__construct ($ timeCollector , 'stopwatch ' );
36- }
3730
38- /**
39- * {@inheritDoc}
40- */
41- public function getName ()
42- {
43- return static ::class;
31+ parent ::__construct (null , 'stopwatch ' );
4432 }
4533
34+
4635 public function getDebugbar ()
4736 {
4837 return $ this ->debugbar ;
4938 }
39+
40+ public function getTokenParsers ()
41+ {
42+ return [
43+ /*
44+ * {% measure foo %}
45+ * Some stuff which will be recorded on the timeline
46+ * {% endmeasure %}
47+ */
48+ new MeasureTwigTokenParser (!is_null ($ this ->debugbar ), $ this ->tagName , $ this ->getName ()),
49+ ];
50+ }
51+
52+ public function startMeasure (...$ arg )
53+ {
54+ if (!$ this ->debugbar || !$ this ->debugbar ->hasCollector ('time ' )) {
55+ return ;
56+ }
57+
58+ $ this ->debugbar ->getCollector ('time ' )->startMeasure (...$ arg );
59+ }
60+
61+ public function stopMeasure (...$ arg )
62+ {
63+ if (!$ this ->debugbar || !$ this ->debugbar ->hasCollector ('time ' )) {
64+ return ;
65+ }
66+
67+ $ this ->debugbar ->getCollector ('time ' )->stopMeasure (...$ arg );
68+ }
5069}
0 commit comments