diff --git a/composer.json b/composer.json index 3383551..5072091 100644 --- a/composer.json +++ b/composer.json @@ -16,9 +16,9 @@ "ext-posix": "*", "ext-xmlreader": "*", "ext-fileinfo": "*", - "league/route": "^5.0.0-dev", - "laminas/laminas-diactoros": "2.24.x-dev", - "laminas/laminas-httphandlerrunner": "2.5.x-dev", + "league/route": "^7.0.0-dev", + "laminas/laminas-diactoros": "3.9.x-dev", + "laminas/laminas-httphandlerrunner": "2.14.x-dev", "vlucas/phpdotenv": "^3.4@dev", "middlewares/whoops": "dev-master", "mcnd/storage": "dev-master", diff --git a/meta/definitions/event.php b/meta/definitions/event.php index 5cfa378..0d8ccec 100644 --- a/meta/definitions/event.php +++ b/meta/definitions/event.php @@ -37,7 +37,7 @@ return [ public function execute(Routing $routing, Route $attribute) : void { if (null !== ($name = $attribute->name ?? null)) { - $this->extension->registerRoute($name, $attribute->getRoute(), $attribute->class, $attribute->classMethod, (array) ( $attribute->method ?? $attribute->methods )); + $this->extension->registerRoute($name, $attribute->getRoute(), $attribute->class, $attribute->classMethod, (array) ( $attribute->method )); } } }, @@ -52,7 +52,6 @@ return [ { $class = $attribute->class; $method = $attribute->classMethod; - $object = $container->get($class); $request = $request->withAttribute('lean.route', $attribute); diff --git a/skeleton/meta/definitions/env/prod.php b/skeleton/meta/definitions/env/prod.php index dac8d18..097f571 100644 --- a/skeleton/meta/definitions/env/prod.php +++ b/skeleton/meta/definitions/env/prod.php @@ -13,7 +13,7 @@ use Psr\Http\Server\MiddlewareInterface, use function DI\{ create, get, autowire }; -error_reporting(getenv('ERROR_REPORTING') ?: ( E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE )); +error_reporting(getenv('ERROR_REPORTING') ?: ( E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_NOTICE )); return [ /* do nothing in production !*/ diff --git a/skeleton/public/index.php b/skeleton/public/index.php index f4f039a..dc51006 100644 --- a/skeleton/public/index.php +++ b/skeleton/public/index.php @@ -8,5 +8,7 @@ try { new class($projectPath) extends %NAMESPACE%\Kernel {}; } catch(\Throwable $t) { - echo sprintf("%s in %s
%s
", $t->getMessage(), $t->getFile() . ":" . $t->getLine(), $t->getTraceAsString()); + echo sprintf("%s in %s
%s
", $t->getMessage(), $t->getFile() . ":" . $t->getLine(), getenv('DEBUG') ? $t->getTraceAsString() : ""); + error_log($t->getMessage()); + header("HTTP/1.1 500 Internal Server Error"); } \ No newline at end of file diff --git a/src/File.php b/src/File.php index 9b217c9..a5875ab 100644 --- a/src/File.php +++ b/src/File.php @@ -58,4 +58,18 @@ class File return $path; } + public static function assertFileExists(string $filepath) : void + { + if (! is_file($filepath)) { + throw new \InvalidArgumentException("File does not exist: {$filepath}"); + } + } + + public static function assertFolderExists(string $path) : void + { + if (! is_dir($path)) { + throw new \InvalidArgumentException("Folder does not exist: {$path}"); + } + } + } \ No newline at end of file diff --git a/src/Kernel.php b/src/Kernel.php index 242cc96..6b340be 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -24,7 +24,9 @@ class Kernel public array $paths = []; - public int $errorReporting = E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_NOTICE; + public int $errorReportingDev = -1; + + public int $errorReportingProd = E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED /*& ~E_NOTICE*/; public array $definitionFilePaths; @@ -34,6 +36,8 @@ class Kernel public string $projectPath ) { + # Still not sure about adding a folder check each call just to add a basic project setup error ... + # File::assertFolderExists($this->projectPath); $this->setEnvironment(); $this->initializeEngine(); $this->setupContainer(); @@ -41,7 +45,7 @@ class Kernel $this->handleRequest(); } - public static function putenv($var, $value) + public static function putenv($var, $value) : void { putenv("$var=$value"); $_ENV[$var] = $value; @@ -96,13 +100,17 @@ class Kernel \Locale::setDefault($this->locale); } - ini_set("log_errors", "1"); ini_set("error_log", $this->errorLogPath ?? getenv("LOGS_PATH") . DIRECTORY_SEPARATOR. date("Y-m").".log"); - ini_set('display_errors', getenv("DEBUG") ? 'on' : 'on'); + ini_set("log_errors", true); + ini_set('display_errors', getenv("DEBUG") ? 'on' : 'off'); - error_reporting($this->errorReporting); + if (getenv("DEBUG")) { + error_reporting(getenv('ERROR_REPORTING_DEV') ?: $this->errorReportingDev); + } + else { + error_reporting(getenv('ERROR_REPORTING_PROD') ?: $this->errorReportingProd); + } - return $this; } @@ -114,7 +122,8 @@ class Kernel if (getenv("APP_ENV") === "prod") { if (getenv("CACHE_PATH")) { - # check if ACPU is there first, $containerBuilder->enableDefinitionCache(); + # check if ACPU is there first, + $containerBuilder->enableDefinitionCache(); $containerBuilder->enableCompilation(getenv("CACHE_PATH") . "/di/"); # No proxies yet... $containerBuilder->writeProxiesToFile(true, getenv("CACHE_PATH") . "/di/");