BreakpointExtension.php
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/*
* AJGL Breakpoint Twig Extension Component
*
* Copyright (C) Antonio J. García Lagar <aj@garcialagar.es>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Ajgl\Twig\Extension;
use Twig_Environment;
use Twig_Extension;
use Twig_SimpleFunction;
/**
* @author Antonio J. García Lagar <aj@garcialagar.es>
*/
class BreakpointExtension extends Twig_Extension
{
public function getName()
{
return 'breakpoint';
}
public function getFunctions()
{
return array(
new Twig_SimpleFunction('breakpoint', array($this, 'setBreakpoint'), array('needs_environment' => true, 'needs_context' => true)),
);
}
/**
* If Xdebug is detected, makes the debugger break.
*
* @param Twig_Environment $environment the environment instance
* @param mixed $context variables from the Twig template
*/
public function setBreakpoint(Twig_Environment $environment, $context)
{
if (function_exists('xdebug_break')) {
$arguments = array_slice(func_get_args(), 2);
xdebug_break();
}
}
}