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 {
* @param \Composer\IO\IOInterface $io
* 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->io = $io;
$this->dotenv = new SymfonyDotenv();
......@@ -67,7 +67,7 @@ final class Dotenv {
* @return string
* 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);
}
......@@ -84,14 +84,14 @@ final class Dotenv {
* @return string
* The value.
*/
public function receiveGlobal($key, $prompt, $default = '') {
public function receiveGlobal(string $key, string $prompt, $default = ''): string {
$key = strtoupper($key);
$value = $_ENV[$key] ?? FALSE;
if ($value === FALSE) {
$value = $_ENV[$key] ?? NULL;
if ($value === NULL) {
if ($this->io->isInteractive()) {
$value = $this->io->ask($prompt . ': ');
}
if ($value === FALSE) {
if ($value === NULL) {
$value = $default;
}
$this->put($key, $value, TRUE);
......@@ -116,7 +116,7 @@ final class Dotenv {
* The value of the environment variable.
* @param bool $overwrite
*/
public function put($key, $value, $overwrite = FALSE) {
public function put(string $key, string $value, $overwrite = FALSE): void {
$data = $this->parse();
$key = strtoupper($key);
if (!$overwrite && isset($data[$key])) {
......@@ -143,7 +143,7 @@ final class Dotenv {
* @return array
* The same data with environment variables being replaced.
*/
public function replaceEnvironmentVariables($data) {
public function replaceEnvironmentVariables($data): array {
array_walk_recursive($data, array($this, 'findEnvironmentVariables'));
return $data;
}
......@@ -154,8 +154,8 @@ final class Dotenv {
* @param string $item
* @param string $key
*/
private function findEnvironmentVariables(&$item, &$key) {
$pattern = '@\{\$env:([A-Za-z0-9_]*)\}@i';
private function findEnvironmentVariables(string &$item, string &$key): void {
$pattern = '@\{\$env:(\w)\}@i';
preg_match_all($pattern, $item, $item_matches);
preg_match_all($pattern, $key, $key_matches);
......@@ -175,10 +175,10 @@ final class Dotenv {
*
* @return string
*/
private function replaceItemEnvironmentVariables($item, $matches) {
private function replaceItemEnvironmentVariables(string $item, array $matches): string {
foreach ($matches as $var) {
$value = $_ENV[$var] ?? FALSE;
if (!$value) {
$value = $_ENV[$var] ?? NULL;
if ($value === NULL) {
$value = '';
}
$item = str_replace( '{$env:' . $var . '}', $value, $item );
......@@ -191,7 +191,7 @@ final class Dotenv {
*
* @return array
*/
private function parse() {
private function parse(): array {
$envContent = file_exists('.env') ? file_get_contents('.env') : '';
return $this->dotenv->parse($envContent);
}
......@@ -199,7 +199,7 @@ final class Dotenv {
/**
* Load the local .env file.
*/
private function load() {
private function load(): void {
try {
foreach ($this->parse() as $key => $value) {
unset($_SERVER[$key]);
......
......@@ -25,7 +25,7 @@
},
"require": {
"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"
},
"require-dev": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment