Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

.env file saving proccess abstractization #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Controllers/EnvironmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ public function environmentClassic()
*/
public function saveClassic(Request $input, Redirector $redirect)
{
$message = $this->EnvironmentManager->saveFileClassic($input);
$saveFile = $this->EnvironmentManager->saveFileClassic($input);

if ($saveFile) {
$message = trans('installer_messages.environment.success');
} else {
$message = trans('installer_messages.environment.errors');
pricop marked this conversation as resolved.
Show resolved Hide resolved
}

event(new EnvironmentSaved($input));

Expand Down Expand Up @@ -103,7 +109,13 @@ public function saveWizard(Request $request, Redirector $redirect)
]);
}

$results = $this->EnvironmentManager->saveFileWizard($request);
$saveFile = $this->EnvironmentManager->saveFileWizard($request);

if ($saveFile) {
$results = trans('installer_messages.environment.success');
} else {
$results = trans('installer_messages.environment.errors');
pricop marked this conversation as resolved.
Show resolved Hide resolved
}

event(new EnvironmentSaved($request));

Expand Down
16 changes: 6 additions & 10 deletions src/Helpers/EnvironmentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,27 @@ public function getEnvExamplePath()
* Save the edited content to the .env file.
*
* @param Request $input
* @return string
* @return bool
*/
public function saveFileClassic(Request $input)
{
$message = trans('installer_messages.environment.success');

try {
file_put_contents($this->envPath, $input->get('envConfig'));
} catch (Exception $e) {
$message = trans('installer_messages.environment.errors');
return false;
}

return $message;
return true;
}

/**
* Save the form content to the .env file.
*
* @param Request $request
* @return string
* @return bool
*/
public function saveFileWizard(Request $request)
{
$results = trans('installer_messages.environment.success');

$envFileData =
'APP_NAME=\''.$request->app_name."'\n".
'APP_ENV='.$request->environment."\n".
Expand Down Expand Up @@ -127,9 +123,9 @@ public function saveFileWizard(Request $request)
try {
file_put_contents($this->envPath, $envFileData);
} catch (Exception $e) {
$results = trans('installer_messages.environment.errors');
return false;
}

return $results;
return true;
}
}