Skip to content

Commit 5c7dfda

Browse files
committed
fix for #817
1 parent 4e6d5ad commit 5c7dfda

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

api.include.php

+13-6
Original file line numberDiff line numberDiff line change
@@ -11596,21 +11596,28 @@ private function getDriverDefaults(string $driver): array
1159611596
];
1159711597
}
1159811598

11599-
private function applyEnvironmentVariables(array $values): array
11599+
private function applyEnvironmentVariables(array $values, string $prefix = 'PHP_CRUD_API'): array
1160011600
{
11601-
$newValues = array();
11601+
$result = [];
1160211602
foreach ($values as $key => $value) {
11603-
$environmentKey = 'PHP_CRUD_API_' . strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
11604-
$newValues[$key] = getenv($environmentKey, true) ?: $value;
11603+
$suffix = strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
11604+
$newPrefix = $prefix . "_" . $suffix;
11605+
if (is_array($value)) {
11606+
$newPrefix = str_replace('PHP_CRUD_API_MIDDLEWARES_','PHP_CRUD_API_',$newPrefix);
11607+
$result[$key] = $this->applyEnvironmentVariables($value, $newPrefix);
11608+
} else {
11609+
$result[$key] = getenv($newPrefix, true) ?: $value;
11610+
}
1160511611
}
11606-
return $newValues;
11612+
return $result;
1160711613
}
11608-
11614+
1160911615
public function __construct(array $values)
1161011616
{
1161111617
$driver = $this->getDefaultDriver($values);
1161211618
$defaults = $this->getDriverDefaults($driver);
1161311619
$newValues = array_merge($this->values, $defaults, $values);
11620+
$newValues['middlewares'] = getenv('PHP_CRUD_API_MIDDLEWARES', true) ?: $newValues['middlewares'];
1161411621
$newValues = $this->parseMiddlewares($newValues);
1161511622
$diff = array_diff_key($newValues, $this->values);
1161611623
if (!empty($diff)) {

api.php

+13-6
Original file line numberDiff line numberDiff line change
@@ -11596,21 +11596,28 @@ private function getDriverDefaults(string $driver): array
1159611596
];
1159711597
}
1159811598

11599-
private function applyEnvironmentVariables(array $values): array
11599+
private function applyEnvironmentVariables(array $values, string $prefix = 'PHP_CRUD_API'): array
1160011600
{
11601-
$newValues = array();
11601+
$result = [];
1160211602
foreach ($values as $key => $value) {
11603-
$environmentKey = 'PHP_CRUD_API_' . strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
11604-
$newValues[$key] = getenv($environmentKey, true) ?: $value;
11603+
$suffix = strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
11604+
$newPrefix = $prefix . "_" . $suffix;
11605+
if (is_array($value)) {
11606+
$newPrefix = str_replace('PHP_CRUD_API_MIDDLEWARES_','PHP_CRUD_API_',$newPrefix);
11607+
$result[$key] = $this->applyEnvironmentVariables($value, $newPrefix);
11608+
} else {
11609+
$result[$key] = getenv($newPrefix, true) ?: $value;
11610+
}
1160511611
}
11606-
return $newValues;
11612+
return $result;
1160711613
}
11608-
11614+
1160911615
public function __construct(array $values)
1161011616
{
1161111617
$driver = $this->getDefaultDriver($values);
1161211618
$defaults = $this->getDriverDefaults($driver);
1161311619
$newValues = array_merge($this->values, $defaults, $values);
11620+
$newValues['middlewares'] = getenv('PHP_CRUD_API_MIDDLEWARES', true) ?: $newValues['middlewares'];
1161411621
$newValues = $this->parseMiddlewares($newValues);
1161511622
$diff = array_diff_key($newValues, $this->values);
1161611623
if (!empty($diff)) {

composer.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Tqdev/PhpCrudApi/Config.php

+13-6
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,28 @@ private function getDriverDefaults(string $driver): array
6969
];
7070
}
7171

72-
private function applyEnvironmentVariables(array $values): array
72+
private function applyEnvironmentVariables(array $values, string $prefix = 'PHP_CRUD_API'): array
7373
{
74-
$newValues = array();
74+
$result = [];
7575
foreach ($values as $key => $value) {
76-
$environmentKey = 'PHP_CRUD_API_' . strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
77-
$newValues[$key] = getenv($environmentKey, true) ?: $value;
76+
$suffix = strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('.', '_', $key)));
77+
$newPrefix = $prefix . "_" . $suffix;
78+
if (is_array($value)) {
79+
$newPrefix = str_replace('PHP_CRUD_API_MIDDLEWARES_','PHP_CRUD_API_',$newPrefix);
80+
$result[$key] = $this->applyEnvironmentVariables($value, $newPrefix);
81+
} else {
82+
$result[$key] = getenv($newPrefix, true) ?: $value;
83+
}
7884
}
79-
return $newValues;
85+
return $result;
8086
}
81-
87+
8288
public function __construct(array $values)
8389
{
8490
$driver = $this->getDefaultDriver($values);
8591
$defaults = $this->getDriverDefaults($driver);
8692
$newValues = array_merge($this->values, $defaults, $values);
93+
$newValues['middlewares'] = getenv('PHP_CRUD_API_MIDDLEWARES', true) ?: $newValues['middlewares'];
8794
$newValues = $this->parseMiddlewares($newValues);
8895
$diff = array_diff_key($newValues, $this->values);
8996
if (!empty($diff)) {

0 commit comments

Comments
 (0)