From a87320fe09dbc45bfc33615e79f1aa598f11b47a Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Thu, 12 Sep 2019 19:06:18 +0800 Subject: [PATCH] Clean up .env files --- .env.example | 61 ++++++------------------ .env.testing | 59 +++++++++++------------ app/Http/Controllers/SetupController.php | 14 +++--- tests/SetupControllerTest.php | 4 +- 4 files changed, 50 insertions(+), 88 deletions(-) diff --git a/.env.example b/.env.example index 4468bcf5..59e1c775 100644 --- a/.env.example +++ b/.env.example @@ -1,31 +1,14 @@ -################################### -# Blessing Skin Server # -# Configuration # -################################### +APP_DEBUG=false +APP_ENV=production +WEBPACK_ENV=production -# 本文件中各个配置项的详细说明 -# 请访问 http://t.cn/E9G4DTY 查看中文教程 - -# Be sure to disable debug at production environment! -APP_DEBUG = false -APP_ENV = production -WEBPACK_ENV = production - -# Database Configuration -DB_CONNECTION = mysql -DB_HOST = localhost -DB_PORT = 3306 -DB_DATABASE = blessingskin -DB_USERNAME = username -DB_PASSWORD = secret -# ========================= - -# Table Prefix -# -# Change if you want to install multiple BS instances into one database. -# The prefix may only contain letters, numbers, and underscores. -# -DB_PREFIX = null +DB_CONNECTION=mysql +DB_HOST=localhost +DB_PORT=3306 +DB_DATABASE=blessingskin +DB_USERNAME=username +DB_PASSWORD=secret +DB_PREFIX= # Hash Algorithm for Passwords # @@ -37,26 +20,10 @@ DB_PREFIX = null # # New sites are *highly* recommended to use BCRYPT. # -PWD_METHOD = BCRYPT +PWD_METHOD=BCRYPT +SALT=2c5ca184f017a9a1ffbd198ef69b0c0e +APP_KEY= -# Salt -# Change it to any random string to secure your passwords & tokens. -# -# You can run [php artisan salt:random] to generate a new salt. -# -SALT = 2c5ca184f017a9a1ffbd198ef69b0c0e - -# App Key should be setted to any random, *32 character* string, -# otherwise all the encrypted strings will not be safe. -# -# You can run [php artisan key:generate] to generate a new key. -# -APP_KEY=base64:gkb/zouNF6UOSfnr/o+izVMS57WQS3+62YqZBuDyBhU= - -# Mail Configuration -# -# Leave MAIL_DRIVER empty to disable features involving sending emails. -# MAIL_DRIVER = smtp MAIL_HOST = null MAIL_PORT = 465 @@ -64,11 +31,11 @@ MAIL_USERNAME = null MAIL_PASSWORD = null MAIL_ENCRYPTION = null -# Change below lines only if you know what they mean! CACHE_DRIVER = file SESSION_DRIVER = file QUEUE_DRIVER = sync +REDIS_CLIENT=predis REDIS_HOST = 127.0.0.1 REDIS_PASSWORD = null REDIS_PORT = 6379 diff --git a/.env.testing b/.env.testing index 4d4622cf..ecd5cf76 100644 --- a/.env.testing +++ b/.env.testing @@ -1,40 +1,35 @@ -################################### -# Blessing Skin Server # -# Configuration # -################################### +APP_DEBUG=false +APP_ENV=testing -APP_DEBUG = false -APP_ENV = testing +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=test +DB_USERNAME=root +DB_PASSWORD=root +DB_PREFIX= -DB_CONNECTION = mysql -DB_HOST = 127.0.0.1 -DB_PORT = 3306 -DB_DATABASE = test -DB_USERNAME = root -DB_PASSWORD = root -DB_PREFIX = null - -PWD_METHOD = BCRYPT -SALT = c67709dd8b7b733aca0d570681fe96cf +PWD_METHOD=BCRYPT +SALT=c67709dd8b7b733aca0d570681fe96cf APP_KEY=base64:eVX/xzF5NhpGB2luswliFx9XSBsbbAP21wOi68X/P34= -MAIL_DRIVER = smtp -MAIL_HOST = localhost -MAIL_PORT = 465 -MAIL_USERNAME = null -MAIL_PASSWORD = null -MAIL_ENCRYPTION = ssl +MAIL_DRIVER=smtp +MAIL_HOST=localhost +MAIL_PORT=465 +MAIL_USERNAME= +MAIL_PASSWORD= +MAIL_ENCRYPTION=ssl -CACHE_DRIVER = array -SESSION_DRIVER = array -QUEUE_DRIVER = sync -LOG_CHANNEL = black-hole +CACHE_DRIVER=array +SESSION_DRIVER=array +QUEUE_DRIVER=sync +LOG_CHANNEL=black-hole -REDIS_HOST = 127.0.0.1 -REDIS_PASSWORD = null -REDIS_PORT = 6379 +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD= +REDIS_PORT=6379 -PLUGINS_DIR = plugins -PLUGINS_URL = null +PLUGINS_DIR=plugins +PLUGINS_URL= -JWT_SECRET = 1tdM3gXarxYI4KlAHMBo238iC2tEb4I3EtBlZTQQXvInXIt7V2ix7hJ1KTvxCKZW +JWT_SECRET=1tdM3gXarxYI4KlAHMBo238iC2tEb4I3EtBlZTQQXvInXIt7V2ix7hJ1KTvxCKZW diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index 40fd3c04..3d15fc77 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -65,37 +65,37 @@ class SetupController extends Controller $content = $filesystem->get(base_path('.env')); $content = preg_replace( '/DB_CONNECTION.+/', - 'DB_CONNECTION = '.$request->input('type'), + 'DB_CONNECTION='.$request->input('type', ''), $content ); $content = preg_replace( '/DB_HOST.+/', - 'DB_HOST = '.$request->input('host'), + 'DB_HOST='.$request->input('host', ''), $content ); $content = preg_replace( '/DB_PORT.+/', - 'DB_PORT = '.$request->input('port'), + 'DB_PORT='.$request->input('port', ''), $content ); $content = preg_replace( '/DB_DATABASE.+/', - 'DB_DATABASE = '.$request->input('db'), + 'DB_DATABASE='.$request->input('db', ''), $content ); $content = preg_replace( '/DB_USERNAME.+/', - 'DB_USERNAME = '.$request->input('username'), + 'DB_USERNAME='.$request->input('username', ''), $content ); $content = preg_replace( '/DB_PASSWORD.+/', - 'DB_PASSWORD = '.$request->input('password'), + 'DB_PASSWORD='.$request->input('password', ''), $content ); $content = preg_replace( '/DB_PREFIX.+/', - 'DB_PREFIX = '.$request->input('prefix'), + 'DB_PREFIX='.$request->input('prefix', ''), $content ); $filesystem->put(base_path('.env'), $content); diff --git a/tests/SetupControllerTest.php b/tests/SetupControllerTest.php index e2d83820..7d44ea14 100644 --- a/tests/SetupControllerTest.php +++ b/tests/SetupControllerTest.php @@ -51,9 +51,9 @@ class SetupControllerTest extends TestCase $mock->shouldReceive('get') ->with(base_path('.env')) ->once() - ->andReturn('DB_CONNECTION = abc'); + ->andReturn('DB_CONNECTION=abc'); $mock->shouldReceive('put') - ->with(base_path('.env'), 'DB_CONNECTION = '.env('DB_CONNECTION')) + ->with(base_path('.env'), 'DB_CONNECTION='.env('DB_CONNECTION')) ->once() ->andReturn(true); });