[BridgeAbstract] use getParameters instead of static to allow overriding it from bridges (#3858)

This commit is contained in:
Florent V 2023-12-26 12:20:49 +01:00 committed by GitHub
parent 1938446385
commit ad2d4c7b1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 11 deletions

View File

@ -154,8 +154,8 @@ abstract class BridgeAbstract
{
// Import and assign all inputs to their context
foreach ($input as $name => $value) {
foreach (static::PARAMETERS as $context => $set) {
if (array_key_exists($name, static::PARAMETERS[$context])) {
foreach ($this->getParameters() as $context => $set) {
if (array_key_exists($name, $this->getParameters()[$context])) {
$this->inputs[$context][$name]['value'] = $value;
}
}
@ -163,16 +163,16 @@ abstract class BridgeAbstract
// Apply default values to missing data
$contexts = [$queriedContext];
if (array_key_exists('global', static::PARAMETERS)) {
if (array_key_exists('global', $this->getParameters())) {
$contexts[] = 'global';
}
foreach ($contexts as $context) {
if (!isset(static::PARAMETERS[$context])) {
if (!isset($this->getParameters()[$context])) {
// unknown context provided by client, throw exception here? or continue?
}
foreach (static::PARAMETERS[$context] as $name => $properties) {
foreach ($this->getParameters()[$context] as $name => $properties) {
if (isset($this->inputs[$context][$name]['value'])) {
continue;
}
@ -204,8 +204,8 @@ abstract class BridgeAbstract
}
// Copy global parameter values to the guessed context
if (array_key_exists('global', static::PARAMETERS)) {
foreach (static::PARAMETERS['global'] as $name => $properties) {
if (array_key_exists('global', $this->getParameters())) {
foreach ($this->getParameters()['global'] as $name => $properties) {
if (isset($input[$name])) {
$value = $input[$name];
} else {
@ -246,8 +246,8 @@ abstract class BridgeAbstract
if (!isset($this->inputs[$this->queriedContext][$input]['value'])) {
return null;
}
if (array_key_exists('global', static::PARAMETERS)) {
if (array_key_exists($input, static::PARAMETERS['global'])) {
if (array_key_exists('global', $this->getParameters())) {
if (array_key_exists($input, $this->getParameters()['global'])) {
$context = 'global';
}
}
@ -256,7 +256,7 @@ abstract class BridgeAbstract
}
$needle = $this->inputs[$this->queriedContext][$input]['value'];
foreach (static::PARAMETERS[$context][$input]['values'] as $first_level_key => $first_level_value) {
foreach ($this->getParameters()[$context][$input]['values'] as $first_level_key => $first_level_value) {
if (!is_array($first_level_value) && $needle === (string)$first_level_value) {
return $first_level_key;
} elseif (is_array($first_level_value)) {
@ -273,7 +273,7 @@ abstract class BridgeAbstract
{
$regex = '/^(https?:\/\/)?(www\.)?(.+?)(\/)?$/';
if (
empty(static::PARAMETERS)
empty($this->getParameters())
&& preg_match($regex, $url, $urlMatches) > 0
&& preg_match($regex, static::URI, $bridgeUriMatches) > 0
&& $urlMatches[3] === $bridgeUriMatches[3]