diff --git a/src/Kernel.php b/src/Kernel.php index 821d7b9..68ec786 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -11,16 +11,13 @@ use League\Route\Strategy\ApplicationStrategy; use Psr\Http\Message\ServerRequestInterface; -use Tell\I18n; -use Ulmus\Container\AdapterProxy; - use Laminas\Diactoros\ServerRequestFactory, Laminas\HttpHandlerRunner\Emitter\EmitterInterface; use Ulmus\Ulmus; -class Kernel { - +class Kernel +{ protected Container $container; protected string $locale; @@ -33,9 +30,11 @@ class Kernel { public string $errorLogPath; + public function __construct( public string $projectPath - ) { + ) + { $this->setEnvironment(); $this->initializeEngine(); $this->setupContainer(); @@ -49,15 +48,22 @@ class Kernel { $_ENV[$var] = $value; } - protected function setEnvironment() { + protected function setEnvironment() : void + { static::putenv('PROJECT_PATH', $this->projectPath); // Environment vars (accessible from \DI\env(), getenv(), $_ENV and $_SERVER) Dotenv::create(getenv("PROJECT_PATH"))->load(); // Override using headers - if ( ( $keys = getenv('KEYS') ) && ( $auth = $_SERVER["HTTP_X_DEV_AUTH"] ?? null ) && in_array($auth, explode(',', $keys)) ) { - foreach (['APP_ENV', 'DEBUG',] as $env) { + if (($keys = getenv('KEYS')) && ($auth = $_SERVER["HTTP_X_DEV_AUTH"] ?? null) && in_array($auth, explode(',', $keys))) { + unset($_SERVER["HTTP_X_DEV_AUTH"]); + + unset($_ENV[$name], $_SERVER[$name]); + putenv("KEYS="); + + + foreach(['APP_ENV', 'DEBUG',] as $env) { if (null !== $value = $_SERVER["HTTP_X_$env"] ?? null) { static::putenv($env, $value); } @@ -66,7 +72,7 @@ class Kernel { // Paths and directories foreach($this->paths as $name => $envkey) { - if ( ! getenv($name) ) { + if (!getenv($name)) { $path = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . getenv($envkey); if (getenv('DEBUG') && ! file_exists($path)) { @@ -88,7 +94,7 @@ class Kernel { setlocale(LC_ALL, $this->locale = getenv("DEFAULT_LOCAL")); setlocale(LC_TIME, getenv("DEFAULT_TIME"), getenv("DEFAULT_TIME_FALLBACK")); - if ( class_exists('Locale') ) { + if (class_exists('Locale')) { \Locale::setDefault($this->locale); } @@ -118,7 +124,7 @@ class Kernel { else { $compiled = getenv("CACHE_PATH") . "/di/CompiledContainer.php"; - if ( file_exists($compiled) ) { + if (file_exists($compiled)) { unlink($compiled); } } @@ -153,8 +159,7 @@ class Kernel { } # Must be removed from KERNEL ! - $this->container->has('ulmus.caching') and ( Ulmus::$cache = $this->container->get('ulmus.caching') ); - # $this->container->has(AdapterProxy::class) and ( $ ) + $this->container->has('ulmus.caching') and (Ulmus::$cache = $this->container->get('ulmus.caching')); return $this; } @@ -177,4 +182,4 @@ class Kernel { return $this; } -}; +} \ No newline at end of file