Skip to content

Commit

Permalink
fix for #817
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Jan 31, 2022
1 parent 4e6d5ad commit 5c7dfda
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
19 changes: 13 additions & 6 deletions api.include.php
Expand Up @@ -11596,21 +11596,28 @@ private function getDriverDefaults(string $driver): array
];
}

private function applyEnvironmentVariables(array $values): array
private function applyEnvironmentVariables(array $values, string $prefix = 'PHP_CRUD_API'): array
{
$newValues = array();
$result = [];
foreach ($values as $key => $value) {
$environmentKey = 'PHP_CRUD_API_' . strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
$newValues[$key] = getenv($environmentKey, true) ?: $value;
$suffix = strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
$newPrefix = $prefix . "_" . $suffix;
if (is_array($value)) {
$newPrefix = str_replace('PHP_CRUD_API_MIDDLEWARES_','PHP_CRUD_API_',$newPrefix);
$result[$key] = $this->applyEnvironmentVariables($value, $newPrefix);
} else {
$result[$key] = getenv($newPrefix, true) ?: $value;
}
}
return $newValues;
return $result;
}

public function __construct(array $values)
{
$driver = $this->getDefaultDriver($values);
$defaults = $this->getDriverDefaults($driver);
$newValues = array_merge($this->values, $defaults, $values);
$newValues['middlewares'] = getenv('PHP_CRUD_API_MIDDLEWARES', true) ?: $newValues['middlewares'];
$newValues = $this->parseMiddlewares($newValues);
$diff = array_diff_key($newValues, $this->values);
if (!empty($diff)) {
Expand Down
19 changes: 13 additions & 6 deletions api.php
Expand Up @@ -11596,21 +11596,28 @@ private function getDriverDefaults(string $driver): array
];
}

private function applyEnvironmentVariables(array $values): array
private function applyEnvironmentVariables(array $values, string $prefix = 'PHP_CRUD_API'): array
{
$newValues = array();
$result = [];
foreach ($values as $key => $value) {
$environmentKey = 'PHP_CRUD_API_' . strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
$newValues[$key] = getenv($environmentKey, true) ?: $value;
$suffix = strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
$newPrefix = $prefix . "_" . $suffix;
if (is_array($value)) {
$newPrefix = str_replace('PHP_CRUD_API_MIDDLEWARES_','PHP_CRUD_API_',$newPrefix);
$result[$key] = $this->applyEnvironmentVariables($value, $newPrefix);
} else {
$result[$key] = getenv($newPrefix, true) ?: $value;
}
}
return $newValues;
return $result;
}

public function __construct(array $values)
{
$driver = $this->getDefaultDriver($values);
$defaults = $this->getDriverDefaults($driver);
$newValues = array_merge($this->values, $defaults, $values);
$newValues['middlewares'] = getenv('PHP_CRUD_API_MIDDLEWARES', true) ?: $newValues['middlewares'];
$newValues = $this->parseMiddlewares($newValues);
$diff = array_diff_key($newValues, $this->values);
if (!empty($diff)) {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions src/Tqdev/PhpCrudApi/Config.php
Expand Up @@ -69,21 +69,28 @@ private function getDriverDefaults(string $driver): array
];
}

private function applyEnvironmentVariables(array $values): array
private function applyEnvironmentVariables(array $values, string $prefix = 'PHP_CRUD_API'): array
{
$newValues = array();
$result = [];
foreach ($values as $key => $value) {
$environmentKey = 'PHP_CRUD_API_' . strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
$newValues[$key] = getenv($environmentKey, true) ?: $value;
$suffix = strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
$newPrefix = $prefix . "_" . $suffix;
if (is_array($value)) {
$newPrefix = str_replace('PHP_CRUD_API_MIDDLEWARES_','PHP_CRUD_API_',$newPrefix);
$result[$key] = $this->applyEnvironmentVariables($value, $newPrefix);
} else {
$result[$key] = getenv($newPrefix, true) ?: $value;
}
}
return $newValues;
return $result;
}

public function __construct(array $values)
{
$driver = $this->getDefaultDriver($values);
$defaults = $this->getDriverDefaults($driver);
$newValues = array_merge($this->values, $defaults, $values);
$newValues['middlewares'] = getenv('PHP_CRUD_API_MIDDLEWARES', true) ?: $newValues['middlewares'];
$newValues = $this->parseMiddlewares($newValues);
$diff = array_diff_key($newValues, $this->values);
if (!empty($diff)) {
Expand Down

0 comments on commit 5c7dfda

Please sign in to comment.