-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXDebugTraceExtension.php
62 lines (47 loc) · 1.6 KB
/
XDebugTraceExtension.php
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Panel;
use Nette\Framework,
Nette\Config\CompilerExtension,
Nette\DI\Container,
Nette\PhpGenerator\ClassType;
/**
* XDebug Trace panel extension for Nette framework.
*
* @author Miloslav Hůla
* @version $Format:%m$
* @see http://github.com/milo/XDebugTracePanel
* @licence LGPL
*/
class XDebugTraceExtension extends CompilerExtension
{
private $defaults = array(
'traceFile' => '%tempDir%/xdebugTrace.xt',
'onCreate' => NULL,
'statistics' => NULL,
);
public function afterCompile(ClassType $class)
{
$config = $this->getConfig($this->defaults);
$name = Container::getMethodName($this->name);
$class->addMethod($name);
$method = $class->methods[$name];
$method->setBody('');
$method->addBody('$service = new Panel\XDebugTrace(?);', array($config['traceFile']));
if (!empty($config['onCreate'])) {
$method->addBody('call_user_func(?, $service);', array($config['onCreate']));
}
if (!empty($config['statistics'])) {
$args = is_array($config['statistics']) ? ($config['statistics'] + array(TRUE, NULL)) : array($config['statistics'], NULL);
$method->addBody('$service->enableStatistics(?, ?);', $args);
}
$method->addBody('return $service;');
$method->documents = array('@return Panel\XDebugTrace');
foreach ($class->documents as $k => $v) {
if (preg_match('~@property.*\$' . preg_quote($this->name, '~') . '$~', $v)) {
$class->documents[$k] = '@property Panel\XDebugTrace $' . $this->name;
break;
}
}
$class->methods['initialize']->addBody('Nette\Diagnostics\Debugger::addPanel($this->getService(?));', array($this->name));
}
}