Skip to content

Commit

Permalink
ApplicationExtension, RoutingExtension: detects Tracy by presence of …
Browse files Browse the repository at this point in the history
…service [Closes nette/di#245]
  • Loading branch information
dg committed Oct 27, 2020
1 parent e10f6ce commit 872c143
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/Bridges/ApplicationDI/ApplicationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(bool $debugMode = false, array $scanDirs = null, str
public function getConfigSchema(): Nette\Schema\Schema
{
return Expect::structure([
'debugger' => Expect::bool(interface_exists(Tracy\IBarPanel::class)),
'debugger' => Expect::bool(),
'errorPresenter' => Expect::string('Nette:Error')->dynamic(),
'catchExceptions' => Expect::bool(!$this->debugMode)->dynamic(),
'mapping' => Expect::arrayOf('string|array'),
Expand All @@ -72,14 +72,11 @@ public function loadConfiguration()
? UI\Presenter::INVALID_LINK_TEXTUAL | ($config->silentLinks ? 0 : UI\Presenter::INVALID_LINK_WARNING)
: UI\Presenter::INVALID_LINK_WARNING;

$application = $builder->addDefinition($this->prefix('application'))
$builder->addDefinition($this->prefix('application'))
->setFactory(Nette\Application\Application::class)
->addSetup('$catchExceptions', [$config->catchExceptions])
->addSetup('$errorPresenter', [$config->errorPresenter]);

if ($config->debugger) {
$application->addSetup([Nette\Bridges\ApplicationTracy\RoutingPanel::class, 'initializePanel']);
}
$this->compiler->addExportedType(Nette\Application\Application::class);

if ($this->debugMode && ($config->scanDirs || $this->robotLoader) && $this->tempDir) {
Expand Down Expand Up @@ -112,6 +109,12 @@ public function loadConfiguration()
public function beforeCompile()
{
$builder = $this->getContainerBuilder();

if ($this->config->debugger ?? $builder->getByType(Tracy\BlueScreen::class)) {
$builder->getDefinition($this->prefix('application'))
->addSetup([Nette\Bridges\ApplicationTracy\RoutingPanel::class, 'initializePanel']);
}

$all = [];

foreach ($builder->findByType(Nette\Application\IPresenter::class) as $def) {
Expand Down
5 changes: 2 additions & 3 deletions src/Bridges/ApplicationDI/RoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(bool $debugMode = false)
$this->debugMode = $debugMode;

$this->config = new class {
/** @var bool */
/** @var ?bool */
public $debugger;
/** @var string[] */
public $routes = [];
Expand All @@ -37,7 +37,6 @@ public function __construct(bool $debugMode = false)
/** @var bool */
public $cache = false;
};
$this->config->debugger = interface_exists(Tracy\IBarPanel::class);
}


Expand Down Expand Up @@ -65,7 +64,7 @@ public function beforeCompile()

if (
$this->debugMode &&
$this->config->debugger &&
($this->config->debugger ?? $builder->getByType(Tracy\Bar::class)) &&
($name = $builder->getByType(Nette\Application\Application::class)) &&
($application = $builder->getDefinition($name)) instanceof Definitions\ServiceDefinition
) {
Expand Down

0 comments on commit 872c143

Please sign in to comment.