update v1.0.7.9 R.C.
This is a Release Candidate. We are still testing.
This commit is contained in:
88
vendor/barryvdh/laravel-debugbar/src/Twig/Extension/Debug.php
vendored
Normal file
88
vendor/barryvdh/laravel-debugbar/src/Twig/Extension/Debug.php
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php namespace Barryvdh\Debugbar\Twig\Extension;
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
use Twig_Environment;
|
||||
use Twig_Extension;
|
||||
use Twig_SimpleFunction;
|
||||
|
||||
/**
|
||||
* Access Laravels auth class in your Twig templates.
|
||||
*/
|
||||
class Debug extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* @var \Barryvdh\Debugbar\LaravelDebugbar
|
||||
*/
|
||||
protected $debugbar;
|
||||
|
||||
/**
|
||||
* Create a new auth extension.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
*/
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
if ($app->bound('debugbar')) {
|
||||
$this->debugbar = $app['debugbar'];
|
||||
} else {
|
||||
$this->debugbar = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Laravel_Debugbar_Debug';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new Twig_SimpleFunction(
|
||||
'debug', [$this, 'debug'], array('needs_context' => true, 'needs_environment' => true)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on Twig_Extension_Debug / twig_var_dump
|
||||
* (c) 2011 Fabien Potencier
|
||||
*
|
||||
* @param Twig_Environment $env
|
||||
* @param $context
|
||||
*/
|
||||
public function debug(Twig_Environment $env, $context)
|
||||
{
|
||||
if (!$env->isDebug() || !$this->debugbar) {
|
||||
return;
|
||||
}
|
||||
|
||||
$count = func_num_args();
|
||||
if (2 === $count) {
|
||||
$data = array();
|
||||
foreach ($context as $key => $value) {
|
||||
if (is_object($value)) {
|
||||
if (method_exists($value, 'toArray')) {
|
||||
$data[$key] = $value->toArray();
|
||||
} else {
|
||||
$data[$key] = "Object (" . get_class($value) . ")";
|
||||
}
|
||||
} else {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
}
|
||||
$this->debugbar->addMessage($data);
|
||||
} else {
|
||||
for ($i = 2; $i < $count; $i++) {
|
||||
$this->debugbar->addMessage(func_get_arg($i));
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
84
vendor/barryvdh/laravel-debugbar/src/Twig/Extension/Dump.php
vendored
Normal file
84
vendor/barryvdh/laravel-debugbar/src/Twig/Extension/Dump.php
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php 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
|
||||
{
|
||||
/**
|
||||
* @var \DebugBar\DataFormatter\DataFormatter
|
||||
*/
|
||||
protected $formatter;
|
||||
|
||||
/**
|
||||
* Create a new auth extension.
|
||||
*
|
||||
* @param \DebugBar\DataFormatter\DataFormatterInterface $formatter
|
||||
*/
|
||||
public function __construct(DataFormatterInterface $formatter)
|
||||
{
|
||||
$this->formatter = $formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Laravel_Debugbar_Dump';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new Twig_SimpleFunction(
|
||||
'dump', [$this, 'dump'], array('is_safe' => ['html'], 'needs_context' => true, 'needs_environment' => true)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on Twig_Extension_Debug / twig_var_dump
|
||||
* (c) 2011 Fabien Potencier
|
||||
*
|
||||
* @param Twig_Environment $env
|
||||
* @param $context
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function dump(Twig_Environment $env, $context)
|
||||
{
|
||||
$output = '';
|
||||
|
||||
$count = func_num_args();
|
||||
if (2 === $count) {
|
||||
$data = array();
|
||||
foreach ($context as $key => $value) {
|
||||
if (is_object($value)) {
|
||||
if (method_exists($value, 'toArray')) {
|
||||
$data[$key] = $value->toArray();
|
||||
} else {
|
||||
$data[$key] = "Object (" . get_class($value) . ")";
|
||||
}
|
||||
} else {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
}
|
||||
$output .= $this->formatter->formatVar($data);
|
||||
} else {
|
||||
for ($i = 2; $i < $count; $i++) {
|
||||
$output .= $this->formatter->formatVar(func_get_arg($i));
|
||||
}
|
||||
}
|
||||
|
||||
return '<pre>'.$output.'</pre>';
|
||||
}
|
||||
}
|
||||
56
vendor/barryvdh/laravel-debugbar/src/Twig/Extension/Stopwatch.php
vendored
Normal file
56
vendor/barryvdh/laravel-debugbar/src/Twig/Extension/Stopwatch.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php 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
|
||||
{
|
||||
/**
|
||||
* @var \Barryvdh\Debugbar\LaravelDebugbar
|
||||
*/
|
||||
protected $debugbar;
|
||||
|
||||
/**
|
||||
* Create a new auth extension.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
*/
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
if ($app->bound('debugbar')) {
|
||||
$this->debugbar = $app['debugbar'];
|
||||
} else {
|
||||
$this->debugbar = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'stopwatch';
|
||||
}
|
||||
|
||||
public function getTokenParsers()
|
||||
{
|
||||
return array(
|
||||
/*
|
||||
* {% stopwatch foo %}
|
||||
* Some stuff which will be recorded on the timeline
|
||||
* {% endstopwatch %}
|
||||
*/
|
||||
new StopwatchTokenParser($this->debugbar !== null),
|
||||
);
|
||||
}
|
||||
|
||||
public function getDebugbar()
|
||||
{
|
||||
return $this->debugbar;
|
||||
}
|
||||
}
|
||||
37
vendor/barryvdh/laravel-debugbar/src/Twig/Node/StopwatchNode.php
vendored
Normal file
37
vendor/barryvdh/laravel-debugbar/src/Twig/Node/StopwatchNode.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php namespace Barryvdh\Debugbar\Twig\Node;
|
||||
|
||||
/**
|
||||
* Represents a stopwatch node. Based on Symfony\Bridge\Twig\Node\StopwatchNode
|
||||
*
|
||||
* @author Wouter J <wouter@wouterj.nl>
|
||||
*/
|
||||
class StopwatchNode extends \Twig_Node
|
||||
{
|
||||
public function __construct(
|
||||
\Twig_NodeInterface $name,
|
||||
$body,
|
||||
\Twig_Node_Expression_AssignName $var,
|
||||
$lineno = 0,
|
||||
$tag = null
|
||||
) {
|
||||
parent::__construct(array('body' => $body, 'name' => $name, 'var' => $var), array(), $lineno, $tag);
|
||||
}
|
||||
|
||||
public function compile(\Twig_Compiler $compiler)
|
||||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write('')
|
||||
->subcompile($this->getNode('var'))
|
||||
->raw(' = ')
|
||||
->subcompile($this->getNode('name'))
|
||||
->write(";\n")
|
||||
->write("\$this->env->getExtension('stopwatch')->getDebugbar()->startMeasure(")
|
||||
->subcompile($this->getNode('var'))
|
||||
->raw(");\n")
|
||||
->subcompile($this->getNode('body'))
|
||||
->write("\$this->env->getExtension('stopwatch')->getDebugbar()->stopMeasure(")
|
||||
->subcompile($this->getNode('var'))
|
||||
->raw(");\n");
|
||||
}
|
||||
}
|
||||
55
vendor/barryvdh/laravel-debugbar/src/Twig/TokenParser/StopwatchTokenParser.php
vendored
Normal file
55
vendor/barryvdh/laravel-debugbar/src/Twig/TokenParser/StopwatchTokenParser.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php namespace Barryvdh\Debugbar\Twig\TokenParser;
|
||||
|
||||
use Barryvdh\Debugbar\Twig\Node\StopwatchNode;
|
||||
|
||||
/**
|
||||
* Token Parser for the stopwatch tag. Based on Symfony\Bridge\Twig\TokenParser\StopwatchTokenParser;
|
||||
*
|
||||
* @author Wouter J <wouter@wouterj.nl>
|
||||
*/
|
||||
class StopwatchTokenParser extends \Twig_TokenParser
|
||||
{
|
||||
protected $debugbarAvailable;
|
||||
|
||||
public function __construct($debugbarAvailable)
|
||||
{
|
||||
$this->debugbarAvailable = $debugbarAvailable;
|
||||
}
|
||||
|
||||
public function parse(\Twig_Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
// {% stopwatch 'bar' %}
|
||||
$name = $this->parser->getExpressionParser()->parseExpression();
|
||||
|
||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
// {% endstopwatch %}
|
||||
$body = $this->parser->subparse(array($this, 'decideStopwatchEnd'), true);
|
||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
if ($this->debugbarAvailable) {
|
||||
return new StopwatchNode(
|
||||
$name,
|
||||
$body,
|
||||
new \Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()),
|
||||
$lineno,
|
||||
$this->getTag()
|
||||
);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'stopwatch';
|
||||
}
|
||||
|
||||
public function decideStopwatchEnd(\Twig_Token $token)
|
||||
{
|
||||
return $token->test('endstopwatch');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user