From eb1cbef43b320f5ce57ae9a31830cdc49da27cac Mon Sep 17 00:00:00 2001 From: eater <=@eater.me> Date: Thu, 21 Nov 2019 00:06:51 +0100 Subject: [PATCH] setup cache before running tessts --- .drone.yml | 5 +++-- bin/setup | 8 ++++++++ composer.json | 5 +---- config/autoload_with_route.php | 3 +++ src/Main.php | 8 ++++---- src/Utils/RouteCompiler.php | 6 ++++++ 6 files changed, 25 insertions(+), 10 deletions(-) create mode 100755 bin/setup create mode 100644 config/autoload_with_route.php diff --git a/.drone.yml b/.drone.yml index 70ae716..22c6757 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,6 +6,7 @@ steps: - name: code checks image: composer commands: - - composer install + - composer install --no-ansi --no-interaction + - ./bin/setup - ./vendor/bin/php-cs-fixer fix --dry-run src - - ./vendor/bin/phpstan analyse src + - ./vendor/bin/phpstan analyse -a config/autoload_with_route.php src diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..20f42f0 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env php +env !== 'prod' || !file_exists($compiledRoutesFile)) { $routes = include(__DIR__ . '/../config/routes.php'); @@ -70,8 +69,9 @@ class Main $compiler->writeCache(); } - include(__DIR__ . '/../var/cache/routes.php'); - return new CompiledRoutes(); + include(__DIR__ . '/../var/cache/routes/CompiledRoutes.php'); + $x = "\CubiStore\Web\Cache\CompiledRoutes"; + return new $x(); } public function setupContainer(ICompiledRoutes $routes) diff --git a/src/Utils/RouteCompiler.php b/src/Utils/RouteCompiler.php index 1197ca2..53ce276 100644 --- a/src/Utils/RouteCompiler.php +++ b/src/Utils/RouteCompiler.php @@ -46,6 +46,12 @@ class RouteCompiler public function writeCache() { + $dirname = dirname($this->target); + + if (!is_dir($dirname)) { + mkdir($dirname, 0777, true); + } + file_put_contents($this->target, $this->compile()); }