clock-work
This commit is contained in:
		| @@ -10,7 +10,7 @@ use Twig_SimpleFunction; | ||||
| /** | ||||
|  * Access Laravels auth class in your Twig templates. | ||||
|  */ | ||||
| class Debug extends Twig_Extension | ||||
| class Debug extends Extension | ||||
| { | ||||
|     /** | ||||
|      * @var \Barryvdh\Debugbar\LaravelDebugbar | ||||
| @@ -44,8 +44,15 @@ class Debug extends Twig_Extension | ||||
|      */ | ||||
|     public function getFunctions() | ||||
|     { | ||||
|         // Maintain compatibility with Twig 2 and 3. | ||||
|         $simpleFunction = 'Twig_SimpleFunction'; | ||||
|  | ||||
|         if (!class_exists($simpleFunction)) { | ||||
|             $simpleFunction = '\Twig\TwigFunction'; | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|             new Twig_SimpleFunction( | ||||
|             new $simpleFunction( | ||||
|                 'debug', | ||||
|                 [$this, 'debug'], | ||||
|                 ['needs_context' => true, 'needs_environment' => true] | ||||
| @@ -57,10 +64,10 @@ class Debug extends Twig_Extension | ||||
|      * Based on Twig_Extension_Debug / twig_var_dump | ||||
|      * (c) 2011 Fabien Potencier | ||||
|      * | ||||
|      * @param Twig_Environment $env | ||||
|      * @param \Twig_Environment|\Twig\Environment $env | ||||
|      * @param $context | ||||
|      */ | ||||
|     public function debug(Twig_Environment $env, $context) | ||||
|     public function debug($env, $context) | ||||
|     { | ||||
|         if (!$env->isDebug() || !$this->debugbar) { | ||||
|             return; | ||||
|   | ||||
| @@ -3,14 +3,11 @@ | ||||
| namespace Barryvdh\Debugbar\Twig\Extension; | ||||
|  | ||||
| use DebugBar\DataFormatter\DataFormatterInterface; | ||||
| use Twig_Environment; | ||||
| use Twig_Extension; | ||||
| use Twig_SimpleFunction; | ||||
|  | ||||
| /** | ||||
|  * Dump variables using the DataFormatter | ||||
|  */ | ||||
| class Dump extends Twig_Extension | ||||
| class Dump extends Extension | ||||
| { | ||||
|     /** | ||||
|      * @var \DebugBar\DataFormatter\DataFormatter | ||||
| @@ -40,8 +37,15 @@ class Dump extends Twig_Extension | ||||
|      */ | ||||
|     public function getFunctions() | ||||
|     { | ||||
|         // Maintain compatibility with Twig 2 and 3. | ||||
|         $simpleFunction = '\Twig_SimpleFunction'; | ||||
|  | ||||
|         if (!class_exists($simpleFunction)) { | ||||
|             $simpleFunction = '\Twig\TwigFunction'; | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|             new Twig_SimpleFunction( | ||||
|             new $simpleFunction( | ||||
|                 'dump', | ||||
|                 [$this, 'dump'], | ||||
|                 ['is_safe' => ['html'], 'needs_context' => true, 'needs_environment' => true] | ||||
| @@ -53,12 +57,12 @@ class Dump extends Twig_Extension | ||||
|      * Based on Twig_Extension_Debug / twig_var_dump | ||||
|      * (c) 2011 Fabien Potencier | ||||
|      * | ||||
|      * @param Twig_Environment $env | ||||
|      * @param \Twig_Environment|\Twig\Environment $env | ||||
|      * @param $context | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function dump(Twig_Environment $env, $context) | ||||
|     public function dump($env, $context) | ||||
|     { | ||||
|         $output = ''; | ||||
|  | ||||
|   | ||||
							
								
								
									
										14
									
								
								vendor/barryvdh/laravel-debugbar/src/Twig/Extension/Extension.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								vendor/barryvdh/laravel-debugbar/src/Twig/Extension/Extension.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Barryvdh\Debugbar\Twig\Extension; | ||||
|  | ||||
| // Maintain compatibility with Twig 2 and 3. | ||||
| if (class_exists('\Twig_Extension')) { | ||||
|     abstract class Extension extends \Twig_Extension | ||||
|     { | ||||
|     } | ||||
| } else { | ||||
|     abstract class Extension extends \Twig\Extension\AbstractExtension | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -4,13 +4,12 @@ namespace Barryvdh\Debugbar\Twig\Extension; | ||||
|  | ||||
| use Barryvdh\Debugbar\Twig\TokenParser\StopwatchTokenParser; | ||||
| use Illuminate\Foundation\Application; | ||||
| use Twig_Extension; | ||||
|  | ||||
| /** | ||||
|  * Access Laravels auth class in your Twig templates. | ||||
|  * Based on Symfony\Bridge\Twig\Extension\StopwatchExtension | ||||
|  */ | ||||
| class Stopwatch extends Twig_Extension | ||||
| class Stopwatch extends Extension | ||||
| { | ||||
|     /** | ||||
|      * @var \Barryvdh\Debugbar\LaravelDebugbar | ||||
|   | ||||
							
								
								
									
										14
									
								
								vendor/barryvdh/laravel-debugbar/src/Twig/Node/Node.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								vendor/barryvdh/laravel-debugbar/src/Twig/Node/Node.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Barryvdh\Debugbar\Twig\Node; | ||||
|  | ||||
| // Maintain compatibility with Twig 2 and 3. | ||||
| if (class_exists('\Twig_Node')) { | ||||
|     abstract class Node extends \Twig_Node | ||||
|     { | ||||
|     } | ||||
| } else { | ||||
|     abstract class Node extends \Twig\Node\Node | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -7,20 +7,37 @@ namespace Barryvdh\Debugbar\Twig\Node; | ||||
|  * | ||||
|  * @author Wouter J <wouter@wouterj.nl> | ||||
|  */ | ||||
| class StopwatchNode extends \Twig_Node | ||||
| class StopwatchNode extends Node | ||||
| { | ||||
|     /** | ||||
|      * @param \Twig_NodeInterface|\Twig\Node\Node $name | ||||
|      * @param $body | ||||
|      * @param \Twig_Node_Expression_AssignName|\Twig\Node\Expression\AssignNameExpression $var | ||||
|      * @param $lineno | ||||
|      * @param $tag | ||||
|      */ | ||||
|     public function __construct( | ||||
|         \Twig_NodeInterface $name, | ||||
|         $name, | ||||
|         $body, | ||||
|         \Twig_Node_Expression_AssignName $var, | ||||
|         $var, | ||||
|         $lineno = 0, | ||||
|         $tag = null | ||||
|     ) { | ||||
|         parent::__construct(['body' => $body, 'name' => $name, 'var' => $var], [], $lineno, $tag); | ||||
|     } | ||||
|  | ||||
|     public function compile(\Twig_Compiler $compiler) | ||||
|     /** | ||||
|      * @param \Twig_Compiler|\Twig\Compiler $env | ||||
|      * @return void | ||||
|      */ | ||||
|     public function compile($compiler) | ||||
|     { | ||||
|         // Maintain compatibility with Twig 2 and 3. | ||||
|         $extension = \Barryvdh\Debugbar\Twig\Extension\Stopwatch::class; | ||||
|         if (class_exists('\Twig_Node')) { | ||||
|             $extension = 'stopwatch'; | ||||
|         } | ||||
|  | ||||
|         $compiler | ||||
|             ->addDebugInfo($this) | ||||
|             ->write('') | ||||
| @@ -28,11 +45,11 @@ class StopwatchNode extends \Twig_Node | ||||
|             ->raw(' = ') | ||||
|             ->subcompile($this->getNode('name')) | ||||
|             ->write(";\n") | ||||
|             ->write("\$this->env->getExtension('stopwatch')->getDebugbar()->startMeasure(") | ||||
|             ->write(sprintf("\$this->env->getExtension('%s')->getDebugbar()->startMeasure(", $extension)) | ||||
|             ->subcompile($this->getNode('var')) | ||||
|             ->raw(");\n") | ||||
|             ->subcompile($this->getNode('body')) | ||||
|             ->write("\$this->env->getExtension('stopwatch')->getDebugbar()->stopMeasure(") | ||||
|             ->write(sprintf("\$this->env->getExtension('%s')->getDebugbar()->stopMeasure(", $extension)) | ||||
|             ->subcompile($this->getNode('var')) | ||||
|             ->raw(");\n"); | ||||
|     } | ||||
|   | ||||
| @@ -9,7 +9,7 @@ use Barryvdh\Debugbar\Twig\Node\StopwatchNode; | ||||
|  * | ||||
|  * @author Wouter J <wouter@wouterj.nl> | ||||
|  */ | ||||
| class StopwatchTokenParser extends \Twig_TokenParser | ||||
| class StopwatchTokenParser extends TokenParser | ||||
| { | ||||
|     protected $debugbarAvailable; | ||||
|  | ||||
| @@ -18,7 +18,10 @@ class StopwatchTokenParser extends \Twig_TokenParser | ||||
|         $this->debugbarAvailable = $debugbarAvailable; | ||||
|     } | ||||
|  | ||||
|     public function parse(\Twig_Token $token) | ||||
|     /** | ||||
|      * @param \Twig_Token|\Twig\Token $token | ||||
|      */ | ||||
|     public function parse($token) | ||||
|     { | ||||
|         $lineno = $token->getLine(); | ||||
|         $stream = $this->parser->getStream(); | ||||
| @@ -26,17 +29,31 @@ class StopwatchTokenParser extends \Twig_TokenParser | ||||
|         // {% stopwatch 'bar' %} | ||||
|         $name = $this->parser->getExpressionParser()->parseExpression(); | ||||
|  | ||||
|         $stream->expect(\Twig_Token::BLOCK_END_TYPE); | ||||
|         // Maintain compatibility with Twig 2 and 3. | ||||
|         if (class_exists("\Twig_Token")) { | ||||
|             $blockEndType = \Twig_Token::BLOCK_END_TYPE; | ||||
|         } else { | ||||
|             $blockEndType = \Twig\Token::BLOCK_END_TYPE; | ||||
|         } | ||||
|  | ||||
|         $stream->expect($blockEndType); | ||||
|  | ||||
|         // {% endstopwatch %} | ||||
|         $body = $this->parser->subparse([$this, 'decideStopwatchEnd'], true); | ||||
|         $stream->expect(\Twig_Token::BLOCK_END_TYPE); | ||||
|         $stream->expect($blockEndType); | ||||
|  | ||||
|         // Maintain compatibility with Twig 2 and 3. | ||||
|         if (class_exists("\Twig_Node_Expression_AssignName")) { | ||||
|             $assignNameExpression = new \Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()); | ||||
|         } else { | ||||
|             $assignNameExpression = new \Twig\Node\Expression\AssignNameExpression($this->parser->getVarName(), $token->getLine()); | ||||
|         } | ||||
|  | ||||
|         if ($this->debugbarAvailable) { | ||||
|             return new StopwatchNode( | ||||
|                 $name, | ||||
|                 $body, | ||||
|                 new \Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), | ||||
|                 $assignNameExpression, | ||||
|                 $lineno, | ||||
|                 $this->getTag() | ||||
|             ); | ||||
| @@ -50,7 +67,10 @@ class StopwatchTokenParser extends \Twig_TokenParser | ||||
|         return 'stopwatch'; | ||||
|     } | ||||
|  | ||||
|     public function decideStopwatchEnd(\Twig_Token $token) | ||||
|     /** | ||||
|      * @param \Twig_Token|\Twig\Token $token | ||||
|      */ | ||||
|     public function decideStopwatchEnd($token) | ||||
|     { | ||||
|         return $token->test('endstopwatch'); | ||||
|     } | ||||
|   | ||||
							
								
								
									
										14
									
								
								vendor/barryvdh/laravel-debugbar/src/Twig/TokenParser/TokenParser.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								vendor/barryvdh/laravel-debugbar/src/Twig/TokenParser/TokenParser.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Barryvdh\Debugbar\Twig\TokenParser; | ||||
|  | ||||
| // Maintain compatibility with Twig 2 and 3. | ||||
| if (class_exists('\Twig_TokenParser')) { | ||||
|     abstract class TokenParser extends \Twig_TokenParser | ||||
|     { | ||||
|     } | ||||
| } else { | ||||
|     abstract class TokenParser extends \Twig\TokenParser\AbstractTokenParser | ||||
|     { | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 noor
					noor