From 70537169245095d85b61e23f494af056b47943c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20P=C5=82aczek?= Date: Sun, 20 Oct 2024 12:57:16 +0200 Subject: [PATCH] Add dotenv package and .env file --- .env | 2 ++ .gitignore | 3 +- README.md | 3 +- composer.json | 3 +- composer.lock | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++- index.php | 4 ++- 6 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..98d2a5b --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +APP_ENV=prod +APP_DEBUG=false \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3fb42d8..e193325 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor/ .idea database.sqlite -var/cache/ \ No newline at end of file +var/cache/ +.env.local \ No newline at end of file diff --git a/README.md b/README.md index 2c53aab..e9fcf2a 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ 1. Cd into project directory 2. Run `git pull` -3. Start and build image in one go with command: `docker compose up -d --build --force-recreate` +3. Refresh cache on production by removing cache directory: `rm -rf var/cache` +4. Start and build image in one go with command: `docker compose up -d --build --force-recreate` ## Running Cron diff --git a/composer.json b/composer.json index f928372..4600aee 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "laravel/serializable-closure": "^1.3", "symfony/http-kernel": "^7.1", "symfony/framework-bundle": "^7.1", - "symfony/twig-bundle": "^7.1" + "symfony/twig-bundle": "^7.1", + "symfony/dotenv": "^7.1" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index be8565c..629c927 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9c0c7b968c4acc975c2de9bd993c6645", + "content-hash": "f2dfc64ddf11dc6a94b37f7eac9ffc0f", "packages": [ { "name": "brick/math", @@ -2176,6 +2176,80 @@ ], "time": "2024-04-18T09:32:20+00:00" }, + { + "name": "symfony/dotenv", + "version": "v7.1.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/dotenv.git", + "reference": "6d966200b399fa59759286f3fc7c919f0677c449" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dotenv/zipball/6d966200b399fa59759286f3fc7c919f0677c449", + "reference": "6d966200b399fa59759286f3fc7c919f0677c449", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "conflict": { + "symfony/console": "<6.4", + "symfony/process": "<6.4" + }, + "require-dev": { + "symfony/console": "^6.4|^7.0", + "symfony/process": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Dotenv\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Registers environment variables from a .env file", + "homepage": "https://symfony.com", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "support": { + "source": "https://github.com/symfony/dotenv/tree/v7.1.5" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-17T09:16:35+00:00" + }, { "name": "symfony/error-handler", "version": "v7.1.3", diff --git a/index.php b/index.php index 6872a3c..005d203 100644 --- a/index.php +++ b/index.php @@ -2,6 +2,7 @@ use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Kernel as BaseKernel; use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; @@ -37,8 +38,9 @@ class Kernel extends BaseKernel $routes->import(__DIR__.'/src/Controller/', 'attribute'); } } +(new Dotenv())->bootEnv(__DIR__.'/.env'); -$kernel = new Kernel('prod', false); +$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send();