Use package for .env editing

The solution provided by this package is similar to what was previously implemented (see #1), but it's nicely packaged and made available in a Facade.
This commit is contained in:
Miguel Nogueira 2020-07-10 05:00:41 +01:00
parent 4deb882d23
commit 0f126886f5
4 changed files with 64 additions and 28 deletions

View File

@ -110,7 +110,7 @@ class Install extends Command
foreach($settings as $keyname => $value)
{
$this->callSilent('environment:modify', [
$this->call('environment:modify', [
'key' => $keyname,
'value' => $value
]);

View File

@ -3,6 +3,7 @@
namespace App\Console\Commands;
use Illuminate\Console\Command;
use GeoSot\EnvEditor\Facades\EnvEditor;
class SetEnv extends Command
{
@ -38,43 +39,18 @@ class SetEnv extends Command
{
$path = base_path('/.env');
$key = $this->argument('key');
$value = $this->argument('value');
$originalValue = env($key);
if (is_null($originalValue))
{
// Attempt to silently fix issue
$this->callSilent('cache:clear');
$originalValue = env($key);
// Still fails? Let the user know
if (is_null($originalValue))
{
$this->error('[!!] Cannot update requested configuration value! This is a known Laravel issue. If you report a bug, keep that in mind.');
return false;
}
}
if (file_exists($path))
{
$file = file_get_contents($path);
$newConfig = str_replace($key . '=' . $originalValue, $key . '=' . $value, $file);
file_put_contents(
$path,
$newConfig
);
EnvEditor::editKey($key, $value);
}
else
{
$this->error('Cannot update a file that doesn\'t exist! Please create .env first.');
return false;
}
$this->info('>> Changed value! It may now be accessed via env() or config() if there\'s a file for it.');
}
}

View File

@ -14,6 +14,7 @@
"doctrine/dbal": "^2.10",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"geo-sot/laravel-env-editor": "^0.9.9",
"guzzlehttp/guzzle": "^6.5",
"jeroennoten/laravel-adminlte": "^3.2",
"laravel/framework": "^7.0",

61
composer.lock generated
View File

@ -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": "fd14fa762c6ac8136b171abd8437e7d7",
"content-hash": "16e8efbacd91ef3417b21bd2648e1629",
"packages": [
{
"name": "almasaeed2010/adminlte",
@ -1032,6 +1032,65 @@
],
"time": "2020-04-28T08:47:37+00:00"
},
{
"name": "geo-sot/laravel-env-editor",
"version": "v0.9.9",
"source": {
"type": "git",
"url": "https://github.com/GeoSot/Laravel-EnvEditor.git",
"reference": "e828d3d3310890286d0b53045de9381187258605"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/GeoSot/Laravel-EnvEditor/zipball/e828d3d3310890286d0b53045de9381187258605",
"reference": "e828d3d3310890286d0b53045de9381187258605",
"shasum": ""
},
"require": {
"laravel/framework": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0|~7.0",
"php": "^7.1"
},
"require-dev": {
"orchestra/testbench": "^3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.9.*-dev"
},
"laravel": {
"providers": [
"GeoSot\\EnvEditor\\ServiceProvider"
],
"aliases": {
"EnvEditor": "GeoSot\\EnvEditor\\Facades\\EnvEditor"
}
}
},
"autoload": {
"psr-4": {
"GeoSot\\EnvEditor\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Geo Sot",
"email": "geo.sotis@gmail.com"
}
],
"description": "A laravel Package that Supports .Env File editing and backup ",
"keywords": [
"EnvEditor",
"geo-sot",
"laravel",
"laravel-env-editor"
],
"time": "2020-04-17T23:33:36+00:00"
},
{
"name": "guzzlehttp/guzzle",
"version": "6.5.4",