aboutsummaryrefslogtreecommitdiff
path: root/lib/BridgeAbstract.php
diff options
context:
space:
mode:
authorGravatar logmanoriginal <logmanoriginal@users.noreply.github.com> 2018-09-22 17:04:55 +0200
committerGravatar logmanoriginal <logmanoriginal@users.noreply.github.com> 2018-09-22 17:04:55 +0200
commit1d451610d62a2c4220e53f62c81777a452dadba3 (patch)
tree1265dbc618db1506decff110f5d0dbd748e2adc6 /lib/BridgeAbstract.php
parentf853ffc07ca5af02621922e33f92cb983dab1108 (diff)
downloadrss-bridge-1d451610d62a2c4220e53f62c81777a452dadba3.tar.gz
rss-bridge-1d451610d62a2c4220e53f62c81777a452dadba3.tar.zst
rss-bridge-1d451610d62a2c4220e53f62c81777a452dadba3.zip
[ParameterValidator] Move 'getQueriedContext' from BridgeAbstract
Diffstat (limited to 'lib/BridgeAbstract.php')
-rw-r--r--lib/BridgeAbstract.php49
1 files changed, 1 insertions, 48 deletions
diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php
index dd6e3ec7..c44d95da 100644
--- a/lib/BridgeAbstract.php
+++ b/lib/BridgeAbstract.php
@@ -117,53 +117,6 @@ abstract class BridgeAbstract implements BridgeInterface {
}
/**
- * Returns the name of the context matching the provided inputs
- *
- * @param array $inputs Associative array of inputs
- * @return mixed Returns the context name or null if no match was found
- */
- protected function getQueriedContext(array $inputs){
- $queriedContexts = array();
-
- // Detect matching context
- foreach(static::PARAMETERS as $context => $set) {
- $queriedContexts[$context] = null;
-
- // Check if all parameters of the context are satisfied
- foreach($set as $id => $properties) {
- if(isset($inputs[$id]) && !empty($inputs[$id])) {
- $queriedContexts[$context] = true;
- } elseif(isset($properties['required'])
- && $properties['required'] === true) {
- $queriedContexts[$context] = false;
- break;
- }
- }
-
- }
-
- // Abort if one of the globally required parameters is not satisfied
- if(array_key_exists('global', static::PARAMETERS)
- && $queriedContexts['global'] === false) {
- return null;
- }
- unset($queriedContexts['global']);
-
- switch(array_sum($queriedContexts)) {
- case 0: // Found no match, is there a context without parameters?
- foreach($queriedContexts as $context => $queried) {
- if(is_null($queried)) {
- return $context;
- }
- }
- return null;
- case 1: // Found unique match
- return array_search(true, $queriedContexts);
- default: return false;
- }
- }
-
- /**
* Defined datas with parameters depending choose bridge
* Note : you can define a cache with "setCache"
* @param array array with expected bridge paramters
@@ -210,7 +163,7 @@ abstract class BridgeAbstract implements BridgeInterface {
}
// Guess the paramter context from input data
- $this->queriedContext = $this->getQueriedContext($inputs);
+ $this->queriedContext = $validator->getQueriedContext($inputs, static::PARAMETERS);
if(is_null($this->queriedContext)) {
returnClientError('Required parameter(s) missing');
} elseif($this->queriedContext === false) {