-
Notifications
You must be signed in to change notification settings - Fork 10
/
SessionPanel.php
115 lines (103 loc) · 3.26 KB
/
SessionPanel.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* Session Nette Debug Panel
* @author Pavel Železný <[email protected]>
*/
class SessionPanel extends \Nette\Application\UI\Control implements \Nette\Diagnostics\IBarPanel
{
/** @var \Nette\Http\Session $session */
private $session;
/** @var array $hiddenSection */
private $hiddenSections = array();
/**
* Constructor
* @author Pavel Železný <[email protected]>
* @param \Nette\Application\Application $application
* @param \Nette\Http\Session $session
* @return void
*/
public function __construct(\Nette\Application\Application $application, \Nette\Http\Session $session)
{
parent::__construct($application->getPresenter(), $this->getId());
$this->session = $session;
}
/**
* Add section name in list of hidden
* @author Pavel Železný <[email protected]>
* @param string $sectionName
* @return void
*/
public function hideSection($sectionName)
{
$this->hiddenSections[] = $sectionName;
}
/**
* Return panel ID
* @author Pavel Železný <[email protected]>
* @return string
*/
public function getId()
{
return __CLASS__;
}
/**
* Html code for DebugerBar Tab
* @author Pavel Železný <[email protected]>
* @return string
*/
public function getTab()
{
$template = $this->getFileTemplate(__DIR__ . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'tab.latte');
return $template;
}
/**
* Html code for DebugerBar Panel
* @author Pavel Železný <[email protected]>
* @return string
*/
public function getPanel()
{
$template = $this->getFileTemplate(__DIR__ . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'panel.latte');
$template->session = $this->session;
$template->sessionMetaStore = $_SESSION['__NF']['META'];
$template->sessionMaxTime = ini_get('session.gc_maxlifetime');
$template->hiddenSections = $this->hiddenSections;
return $template;
}
/**
* Load template file path with aditional macros and variables
* @author Pavel Železný <[email protected]>
* @param string $templateFilePath
* @return \Nette\Templating\FileTemplate
* @throws \Nette\FileNotFoundException
*/
private function getFileTemplate($templateFilePath)
{
if (file_exists($templateFilePath))
{
$template = new \Nette\Templating\FileTemplate($templateFilePath);
$template->onPrepareFilters[] = callback($this, 'templatePrepareFilters');
$template->registerHelperLoader('\Nette\Templating\Helpers::loader');
$template->basePath = realpath(__DIR__);
return $template;
}
else
{
throw new \Nette\FileNotFoundException('Requested template file is not exist.');
}
}
/**
* Load latte and set aditional macros
* @author Pavel Železný <[email protected]>
* @param \Nette\Templating\Template $template
* @return void
*/
public function templatePrepareFilters($template)
{
$template->registerFilter($latte = new \Nette\Latte\Engine());
$set = \Nette\Latte\Macros\MacroSet::install($latte->getCompiler());
$set->addMacro('src', NULL, NULL, 'echo \'src="\'.\Nette\Templating\Helpers::dataStream(file_get_contents(%node.word)).\'"\'');
$set->addMacro('stylesheet','echo \'<style type="text/css">\'.file_get_contents(%node.word).\'</style>\'');
$set->addMacro('clickableDump','echo \Nette\Diagnostics\Helpers::clickableDump(%node.word)');
}
}