Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Configurator: add default parameter resolution so appDir is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
Radovan Kepák committed Sep 7, 2021
1 parent 81beb26 commit 14dfc00
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Bootstrap/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Mallgroup\Bootstrap;

use Composer\Autoload\ClassLoader;
use Mallgroup\DI\Config\Adapters\EnvironmentAdapter;
use Nette\Bootstrap;
use Nette\DI\Config\Loader;
Expand All @@ -15,4 +16,22 @@ protected function createLoader(): Loader
$loader->addAdapter('env', EnvironmentAdapter::class);
return $loader;
}

protected function getDefaultParameters(): array
{
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$last = end($trace);
$debugMode = static::detectDebugMode();
$loaderRc = class_exists(ClassLoader::class)
? new \ReflectionClass(ClassLoader::class)
: null;
return [
'appDir' => isset($trace[2]['file']) ? dirname($trace[2]['file']) : null,
'wwwDir' => isset($last['file']) ? dirname($last['file']) : null,
'vendorDir' => $loaderRc ? dirname($loaderRc->getFileName(), 2) : null,
'debugMode' => $debugMode,
'productionMode' => !$debugMode,
'consoleMode' => PHP_SAPI === 'cli',
];
}
}

0 comments on commit 14dfc00

Please sign in to comment.