Skip to content

Commit 65c419a

Browse files
committed
LatteExtension: initializes Latte Panel, added option 'debugger'
1 parent 4a2d940 commit 65c419a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Bridges/ApplicationDI/LatteExtension.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Nette;
1414
use Nette\Bridges\ApplicationLatte;
1515
use Nette\Schema\Expect;
16+
use Tracy;
1617

1718

1819
/**
@@ -37,6 +38,7 @@ public function __construct(string $tempDir, bool $debugMode = false)
3738
public function getConfigSchema(): Nette\Schema\Schema
3839
{
3940
return Expect::structure([
41+
'debugger' => Expect::anyOf(true, false, 'all'),
4042
'xhtml' => Expect::bool(false),
4143
'macros' => Expect::arrayOf('string'),
4244
'templateClass' => Expect::string(),
@@ -83,6 +85,34 @@ public function loadConfiguration()
8385
}
8486

8587

88+
public function beforeCompile()
89+
{
90+
$builder = $this->getContainerBuilder();
91+
92+
if (
93+
$this->debugMode
94+
&& ($this->config->debugger ?? $builder->getByType(Tracy\Bar::class))
95+
&& class_exists(Latte\Bridges\Tracy\LattePanel::class)
96+
) {
97+
$factory = $builder->getDefinition($this->prefix('templateFactory'));
98+
$factory->addSetup([self::class, 'initLattePanel'], [$factory, 'all' => $this->config->debugger === 'all']);
99+
}
100+
}
101+
102+
103+
public static function initLattePanel(ApplicationLatte\TemplateFactory $factory, Tracy\Bar $bar, bool $all = false)
104+
{
105+
$factory->onCreate[] = function (ApplicationLatte\Template $template) use ($bar, $all) {
106+
if ($all || $template->control instanceof Nette\Application\UI\Presenter) {
107+
$bar->addPanel(new Latte\Bridges\Tracy\LattePanel(
108+
$template->getLatte(),
109+
$all ? (new \ReflectionObject($template->control))->getShortName() : null
110+
));
111+
}
112+
};
113+
}
114+
115+
86116
public function addMacro(string $macro): void
87117
{
88118
$builder = $this->getContainerBuilder();

0 commit comments

Comments
 (0)