diff --git a/bootstrap/app.php b/bootstrap/app.php index 4ab84d8..189f815 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -1,43 +1,48 @@ load(); -} catch (Dotenv\Exception\InvalidPathException $e) { + (new Dotenv(__DIR__ . '/../'))->load(); +} catch (InvalidPathException $e) { // } $container = new DI\Container(); -Slim\Factory\AppFactory::setContainer($container); +AppFactory::setContainer($container); -$app = Slim\Factory\AppFactory::create(); +$app = AppFactory::create(); $container->set('settings', function () { return [ - 'displayErrorDetails' => getenv('APP_DEBUG') === 'true', - 'app' => [ 'name' => getenv('APP_NAME') - ], - - 'views' => [ - 'cache' => getenv('VIEW_CACHE_DISABLED') === 'true' ? false : __DIR__ . '/../storage/views' ] ]; }); -$twig = new Slim\Views\Twig(__DIR__ . '/../resources/views', [ - 'cache' => $container->get('settings')['views']['cache'] -]); +$container->set('view', function ($container) use ($app) { + $twig = new Twig(__DIR__ . '/../resources/views', [ + 'cache' => false + ]); -$twigMiddleware = new Slim\Views\TwigMiddleware( - $twig, - $container, - $app->getRouteCollector()->getRouteParser() -); + $twig->addExtension( + new TwigExtension( + $app->getRouteCollector()->getRouteParser(), + (new UriFactory)->createFromGlobals($_SERVER), + '/' + ) + ); -$app->add($twigMiddleware); + return $twig; +}); require_once __DIR__ . '/../routes/web.php'; diff --git a/composer.json b/composer.json index f606eb7..a66611e 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "type": "project", "require": { "php": ">=7.0.0", - "slim/slim": "4.3.0", + "slim/slim": "4.4.0", "slim/twig-view": "3.0.0-alpha", "symfony/var-dumper": "^3.2", "vlucas/phpdotenv": "^2.4", diff --git a/storage/views/.gitignore b/storage/views/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/storage/views/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore