Skip to content
Snippets Groups Projects
Commit 21bedcd3 authored by jurgenhaas's avatar jurgenhaas
Browse files

docker/l3d#58 Move project settings out of composer.json

parent 1abca305
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,7 @@ final class Dotenv { ...@@ -41,7 +41,7 @@ final class Dotenv {
* @param \Composer\IO\IOInterface $io * @param \Composer\IO\IOInterface $io
* The input-output object of the composer session. * The input-output object of the composer session.
*/ */
public function __construct($name, IOInterface $io) { public function __construct(string $name, IOInterface $io) {
$this->name = strtoupper($name); $this->name = strtoupper($name);
$this->io = $io; $this->io = $io;
$this->dotenv = new SymfonyDotenv(); $this->dotenv = new SymfonyDotenv();
...@@ -67,7 +67,7 @@ final class Dotenv { ...@@ -67,7 +67,7 @@ final class Dotenv {
* @return string * @return string
* The value. * The value.
*/ */
public function receive($key, $prompt, $default = '') { public function receive(string $key, string $prompt, $default = ''): string {
return $this->receiveGlobal($this->name . '_' . $key, $prompt, $default); return $this->receiveGlobal($this->name . '_' . $key, $prompt, $default);
} }
...@@ -84,14 +84,14 @@ final class Dotenv { ...@@ -84,14 +84,14 @@ final class Dotenv {
* @return string * @return string
* The value. * The value.
*/ */
public function receiveGlobal($key, $prompt, $default = '') { public function receiveGlobal(string $key, string $prompt, $default = ''): string {
$key = strtoupper($key); $key = strtoupper($key);
$value = $_ENV[$key] ?? FALSE; $value = $_ENV[$key] ?? NULL;
if ($value === FALSE) { if ($value === NULL) {
if ($this->io->isInteractive()) { if ($this->io->isInteractive()) {
$value = $this->io->ask($prompt . ': '); $value = $this->io->ask($prompt . ': ');
} }
if ($value === FALSE) { if ($value === NULL) {
$value = $default; $value = $default;
} }
$this->put($key, $value, TRUE); $this->put($key, $value, TRUE);
...@@ -116,7 +116,7 @@ final class Dotenv { ...@@ -116,7 +116,7 @@ final class Dotenv {
* The value of the environment variable. * The value of the environment variable.
* @param bool $overwrite * @param bool $overwrite
*/ */
public function put($key, $value, $overwrite = FALSE) { public function put(string $key, string $value, $overwrite = FALSE): void {
$data = $this->parse(); $data = $this->parse();
$key = strtoupper($key); $key = strtoupper($key);
if (!$overwrite && isset($data[$key])) { if (!$overwrite && isset($data[$key])) {
...@@ -143,7 +143,7 @@ final class Dotenv { ...@@ -143,7 +143,7 @@ final class Dotenv {
* @return array * @return array
* The same data with environment variables being replaced. * The same data with environment variables being replaced.
*/ */
public function replaceEnvironmentVariables($data) { public function replaceEnvironmentVariables($data): array {
array_walk_recursive($data, array($this, 'findEnvironmentVariables')); array_walk_recursive($data, array($this, 'findEnvironmentVariables'));
return $data; return $data;
} }
...@@ -154,8 +154,8 @@ final class Dotenv { ...@@ -154,8 +154,8 @@ final class Dotenv {
* @param string $item * @param string $item
* @param string $key * @param string $key
*/ */
private function findEnvironmentVariables(&$item, &$key) { private function findEnvironmentVariables(string &$item, string &$key): void {
$pattern = '@\{\$env:([A-Za-z0-9_]*)\}@i'; $pattern = '@\{\$env:(\w)\}@i';
preg_match_all($pattern, $item, $item_matches); preg_match_all($pattern, $item, $item_matches);
preg_match_all($pattern, $key, $key_matches); preg_match_all($pattern, $key, $key_matches);
...@@ -175,10 +175,10 @@ final class Dotenv { ...@@ -175,10 +175,10 @@ final class Dotenv {
* *
* @return string * @return string
*/ */
private function replaceItemEnvironmentVariables($item, $matches) { private function replaceItemEnvironmentVariables(string $item, array $matches): string {
foreach ($matches as $var) { foreach ($matches as $var) {
$value = $_ENV[$var] ?? FALSE; $value = $_ENV[$var] ?? NULL;
if (!$value) { if ($value === NULL) {
$value = ''; $value = '';
} }
$item = str_replace( '{$env:' . $var . '}', $value, $item ); $item = str_replace( '{$env:' . $var . '}', $value, $item );
...@@ -191,7 +191,7 @@ final class Dotenv { ...@@ -191,7 +191,7 @@ final class Dotenv {
* *
* @return array * @return array
*/ */
private function parse() { private function parse(): array {
$envContent = file_exists('.env') ? file_get_contents('.env') : ''; $envContent = file_exists('.env') ? file_get_contents('.env') : '';
return $this->dotenv->parse($envContent); return $this->dotenv->parse($envContent);
} }
...@@ -199,7 +199,7 @@ final class Dotenv { ...@@ -199,7 +199,7 @@ final class Dotenv {
/** /**
* Load the local .env file. * Load the local .env file.
*/ */
private function load() { private function load(): void {
try { try {
foreach ($this->parse() as $key => $value) { foreach ($this->parse() as $key => $value) {
unset($_SERVER[$key]); unset($_SERVER[$key]);
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
}, },
"require": { "require": {
"php": ">=7.2", "php": ">=7.2",
"lakedrops/composer-json-utils": "^1.4.1", "lakedrops/composer-json-utils": "^1.7||dev-master",
"symfony/dotenv": "^3.4||^4.4||^5.0" "symfony/dotenv": "^3.4||^4.4||^5.0"
}, },
"require-dev": { "require-dev": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment