This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
1 addition
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +0,0 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
$params = getParams(); | ||
|
||
function getParams() | ||
{ | ||
$rawParams = []; | ||
if (isset($_SERVER['argv'])) { | ||
$rawParams = $_SERVER['argv']; | ||
array_shift($rawParams); | ||
} | ||
|
||
$params = []; | ||
foreach ($rawParams as $param) { | ||
if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) { | ||
$name = $matches[1]; | ||
$params[$name] = isset($matches[3]) ? $matches[3] : true; | ||
} else { | ||
$params[] = $param; | ||
} | ||
} | ||
|
||
return $params; | ||
} | ||
|
||
function changeEnv($data = []) | ||
{ | ||
if (count($data) > 0) { | ||
|
||
// Read .env-file | ||
$filePath = __DIR__ . '/../.env' | ||
$env = file_get_contents($filePath); | ||
|
||
// Split string on every " " and write into array | ||
$env = preg_split('/\s+/', $env);; | ||
|
||
// Loop through given data | ||
foreach ((array)$data as $key => $value) { | ||
|
||
// Loop through .env-data | ||
foreach ($env as $env_key => $env_value) { | ||
|
||
// Turn the value into an array and stop after the first split | ||
// So it's not possible to split e.g. the App-Key by accident | ||
$entry = explode("=", $env_value, 2); | ||
|
||
// Check, if new key fits the actual .env-key | ||
if ($entry[0] == $key) { | ||
// If yes, overwrite it with the new one | ||
$env[$env_key] = $key . "=" . $value; | ||
} else { | ||
// If not, keep the old one | ||
$env[$env_key] = $env_value; | ||
} | ||
} | ||
} | ||
|
||
// Turn the array back to an String | ||
$env = implode("\n", $env); | ||
|
||
// And overwrite the .env with the new data | ||
file_put_contents($filePath, $env); | ||
|
||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +0,0 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
$params = getParams(); | ||
|
||
function getParams() | ||
{ | ||
$rawParams = []; | ||
if (isset($_SERVER['argv'])) { | ||
$rawParams = $_SERVER['argv']; | ||
array_shift($rawParams); | ||
} | ||
|
||
$params = []; | ||
foreach ($rawParams as $param) { | ||
if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) { | ||
$name = $matches[1]; | ||
$params[$name] = isset($matches[3]) ? $matches[3] : true; | ||
} else { | ||
$params[] = $param; | ||
} | ||
} | ||
|
||
return $params; | ||
} | ||
|
||
function changeEnv($data = []) | ||
{ | ||
if (count($data) > 0) { | ||
|
||
// Read .env-file | ||
$filePath = __DIR__ . '/../.env' | ||
$env = file_get_contents($filePath); | ||
|
||
// Split string on every " " and write into array | ||
$env = preg_split('/\s+/', $env);; | ||
|
||
// Loop through given data | ||
foreach ((array)$data as $key => $value) { | ||
|
||
// Loop through .env-data | ||
foreach ($env as $env_key => $env_value) { | ||
|
||
// Turn the value into an array and stop after the first split | ||
// So it's not possible to split e.g. the App-Key by accident | ||
$entry = explode("=", $env_value, 2); | ||
|
||
// Check, if new key fits the actual .env-key | ||
if ($entry[0] == $key) { | ||
// If yes, overwrite it with the new one | ||
$env[$env_key] = $key . "=" . $value; | ||
} else { | ||
// If not, keep the old one | ||
$env[$env_key] = $env_value; | ||
} | ||
} | ||
} | ||
|
||
// Turn the array back to an String | ||
$env = implode("\n", $env); | ||
|
||
// And overwrite the .env with the new data | ||
file_put_contents($filePath, $env); | ||
|
||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +0,0 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
$params = getParams(); | ||
|
||
function getParams() | ||
{ | ||
$rawParams = []; | ||
if (isset($_SERVER['argv'])) { | ||
$rawParams = $_SERVER['argv']; | ||
array_shift($rawParams); | ||
} | ||
|
||
$params = []; | ||
foreach ($rawParams as $param) { | ||
if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) { | ||
$name = $matches[1]; | ||
$params[$name] = isset($matches[3]) ? $matches[3] : true; | ||
} else { | ||
$params[] = $param; | ||
} | ||
} | ||
|
||
return $params; | ||
} | ||
|
||
function changeEnv($data = []) | ||
{ | ||
if (count($data) > 0) { | ||
|
||
// Read .env-file | ||
$filePath = __DIR__ . '/../.env' | ||
$env = file_get_contents($filePath); | ||
|
||
// Split string on every " " and write into array | ||
$env = preg_split('/\s+/', $env);; | ||
|
||
// Loop through given data | ||
foreach ((array)$data as $key => $value) { | ||
|
||
// Loop through .env-data | ||
foreach ($env as $env_key => $env_value) { | ||
|
||
// Turn the value into an array and stop after the first split | ||
// So it's not possible to split e.g. the App-Key by accident | ||
$entry = explode("=", $env_value, 2); | ||
|
||
// Check, if new key fits the actual .env-key | ||
if ($entry[0] == $key) { | ||
// If yes, overwrite it with the new one | ||
$env[$env_key] = $key . "=" . $value; | ||
} else { | ||
// If not, keep the old one | ||
$env[$env_key] = $env_value; | ||
} | ||
} | ||
} | ||
|
||
// Turn the array back to an String | ||
$env = implode("\n", $env); | ||
|
||
// And overwrite the .env with the new data | ||
file_put_contents($filePath, $env); | ||
|
||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters