From bad3627fa391f6d30465e002b75c6684be24a0a5 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Sun, 2 Sep 2018 21:08:01 +0200 Subject: [PATCH 1/3] Remove dev entrypoint and use environment variables to load environment --- .env.dist | 2 ++ .gitignore | 1 + .travis.yml | 2 +- bin/console | 13 +++++++++++-- web/app.php | 18 +++++++++++++++++- web/app_dev.php | 39 --------------------------------------- 6 files changed, 32 insertions(+), 43 deletions(-) create mode 100644 .env.dist delete mode 100755 web/app_dev.php diff --git a/.env.dist b/.env.dist new file mode 100644 index 000000000..1b925a802 --- /dev/null +++ b/.env.dist @@ -0,0 +1,2 @@ +SOLIDINVOICE_ENV=dev +SOLIDINVOICE_DEBUG=1 \ No newline at end of file diff --git a/.gitignore b/.gitignore index a6aa94308..899c16af9 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ app/config/parameters.yml node_modules .rules .php_cs.cache +.env \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 257167a97..33b06399e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ dist: trusty env: global: - - SYMFONY_ENV=test + - SOLIDINVOICE_ENV=test cache: yarn: true diff --git a/bin/console b/bin/console index bcd9600da..7b61704ae 100755 --- a/bin/console +++ b/bin/console @@ -4,6 +4,7 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Debug\Debug; +use Symfony\Component\Dotenv\Dotenv; // if you don't want to setup permissions the proper way, just uncomment the following PHP line // read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information @@ -16,9 +17,17 @@ set_time_limit(0); */ $loader = require __DIR__.'/../app/autoload.php'; +if (!getenv('SOLIDINVOICE_ENV') && file_exists($file = dirname(__DIR__).'/.env')) { + (new Dotenv)->load($file); +} + +if (!getenv('SOLIDINVOICE_ENV')) { + throw new \RuntimeException('Environment is not set up correctly. "SOLIDINVOICE_ENV" environment variable is missing.'); +} + $input = new ArgvInput(); -$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev'); -$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod'; +$env = $input->getParameterOption(['--env', '-e'], getenv('SOLIDINVOICE_ENV')); +$debug = (bool) getenv('SOLIDINVOICE_DEBUG') && !$input->hasParameterOption(['--no-debug', '']); if ($debug) { Debug::enable(); diff --git a/web/app.php b/web/app.php index 143219e30..990f1c5c9 100644 --- a/web/app.php +++ b/web/app.php @@ -9,6 +9,8 @@ * with this source code in the file LICENSE. */ +use Symfony\Component\Debug\Debug; +use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\HttpFoundation\Request; /* @@ -17,7 +19,21 @@ $loader = require __DIR__.'/../app/autoload.php'; include_once __DIR__.'/../var/bootstrap.php.cache'; -$kernel = new AppKernel('prod', false); +if (!getenv('SOLIDINVOICE_ENV') && file_exists($file = dirname(__DIR__).'/.env')) { + (new Dotenv)->load($file); +} + +if (!getenv('SOLIDINVOICE_ENV')) { + throw new \RuntimeException('Environment is not set up correctly. "SOLIDINVOICE_ENV" environment variable is missing.'); +} + +$debug = (bool) getenv('SOLIDINVOICE_DEBUG'); + +if ($debug) { + Debug::enable(); +} + +$kernel = new AppKernel(getenv('SOLIDINVOICE_ENV'), $debug); //$kernel = new AppCache($kernel); // When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter //Request::enableHttpMethodParameterOverride(); diff --git a/web/app_dev.php b/web/app_dev.php deleted file mode 100755 index d5b7acd28..000000000 --- a/web/app_dev.php +++ /dev/null @@ -1,39 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Debug\Debug; - -// If you don't want to setup permissions the proper way, just uncomment the following PHP line -// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information -//umask(0000); - -// This check prevents access to debug front controllers that are deployed by accident to production servers. -// Feel free to remove this, extend it, or make something more sophisticated. -/*if (isset($_SERVER['HTTP_CLIENT_IP']) - || isset($_SERVER['HTTP_X_FORWARDED_FOR']) - || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1']) || php_sapi_name() === 'cli-server') -) { - header('HTTP/1.0 403 Forbidden'); - exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.'); -}*/ - -/** - * @var Composer\Autoload\ClassLoader - */ -$loader = require __DIR__.'/../app/autoload.php'; -Debug::enable(); - -$kernel = new AppKernel('dev', true); -$request = Request::createFromGlobals(); -$response = $kernel->handle($request); -$response->send(); -$kernel->terminate($request, $response); From e7beb942615b201964a300d872824fa462e99f39 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 3 Sep 2018 08:52:28 +0200 Subject: [PATCH 2/3] Fix Routing script --- src/CoreBundle/Resources/config/requirejs.yml | 3 --- src/CoreBundle/Resources/public/js/extend/routing.js | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/CoreBundle/Resources/config/requirejs.yml b/src/CoreBundle/Resources/config/requirejs.yml index bbd98b1ea..d8b3716fe 100644 --- a/src/CoreBundle/Resources/config/requirejs.yml +++ b/src/CoreBundle/Resources/config/requirejs.yml @@ -38,8 +38,6 @@ config: material.ripples: deps: - jquery - fos_router: - exports: fos.Router paths: # External dependencies loaded through NPM/Yarn backbone: ../assets/backbone.js @@ -75,7 +73,6 @@ config: core/view: solidinvoicecore/js/itemview.js util/form/collection: solidinvoicecore/js/util/form/collection.js template: ../js/hbs-templates.js - fos_routing_data: ../js/fos_js_routes.js map: '*': translator: solidinvoicecore/js/extend/translator diff --git a/src/CoreBundle/Resources/public/js/extend/routing.js b/src/CoreBundle/Resources/public/js/extend/routing.js index eb78e1d48..18ca34076 100644 --- a/src/CoreBundle/Resources/public/js/extend/routing.js +++ b/src/CoreBundle/Resources/public/js/extend/routing.js @@ -1,8 +1,8 @@ define(['lodash', 'fos_router', 'fos_routing_data'], function(_, Router, data) { if (!_.isUndefined(data)) { - Router.setData(data); + Router.setRoutingData(data); } - return Routing; + return Router; }); \ No newline at end of file From 227284b19fdad4ebbf47c3f630b08cf02ed53021 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 3 Sep 2018 08:52:42 +0200 Subject: [PATCH 3/3] Fix CS --- bin/console | 2 +- web/app.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/console b/bin/console index 7b61704ae..6fcf3495e 100755 --- a/bin/console +++ b/bin/console @@ -18,7 +18,7 @@ set_time_limit(0); $loader = require __DIR__.'/../app/autoload.php'; if (!getenv('SOLIDINVOICE_ENV') && file_exists($file = dirname(__DIR__).'/.env')) { - (new Dotenv)->load($file); + (new Dotenv())->load($file); } if (!getenv('SOLIDINVOICE_ENV')) { diff --git a/web/app.php b/web/app.php index 990f1c5c9..4b803549c 100644 --- a/web/app.php +++ b/web/app.php @@ -20,7 +20,7 @@ include_once __DIR__.'/../var/bootstrap.php.cache'; if (!getenv('SOLIDINVOICE_ENV') && file_exists($file = dirname(__DIR__).'/.env')) { - (new Dotenv)->load($file); + (new Dotenv())->load($file); } if (!getenv('SOLIDINVOICE_ENV')) {