diff options
author | 2023-03-02 13:25:57 +0100 | |
---|---|---|
committer | 2023-03-02 13:25:57 +0100 | |
commit | f3f98a117cf55be85e0078766fac6879e914256e (patch) | |
tree | fa065e56362e81ec7dd7d4e8b8dc3d7b335c4c2a /lib/BridgeAbstract.php | |
parent | f0d8cfd4d44477920cfc890cda7b0fab4d541dd7 (diff) | |
download | rss-bridge-f3f98a117cf55be85e0078766fac6879e914256e.tar.gz rss-bridge-f3f98a117cf55be85e0078766fac6879e914256e.tar.zst rss-bridge-f3f98a117cf55be85e0078766fac6879e914256e.zip |
[Core] Add getKey function (#3275)
* [Core] Add getKey function
Diffstat (limited to 'lib/BridgeAbstract.php')
-rw-r--r-- | lib/BridgeAbstract.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php index 5752f55b..ecbb2529 100644 --- a/lib/BridgeAbstract.php +++ b/lib/BridgeAbstract.php @@ -295,6 +295,32 @@ abstract class BridgeAbstract implements BridgeInterface } /** + * Get the key name of a given input + * Can process multilevel arrays with two levels, the max level a list can have + * + * @param string $input The input name + * @return string|null The accompaning key to a given input or null if the input is not defined + */ + public function getKey($input) + { + if (!isset($this->inputs[$this->queriedContext][$input]['value'])) { + return null; + } + $needle = $this->inputs[$this->queriedContext][$input]['value']; + foreach (static::PARAMETERS[$this->queriedContext][$input]['values'] as $first_level_key => $first_level_value) { + if ($needle === (string)$first_level_value) { + return $first_level_key; + } elseif (is_array($first_level_value)) { + foreach ($first_level_value as $second_level_key => $second_level_value) { + if ($needle === (string)$second_level_value) { + return $second_level_key; + } + } + } + } + } + + /** * Get bridge configuration value */ public function getOption($name) |