aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/BridgeAbstract.php49
-rw-r--r--lib/ParameterValidator.php48
2 files changed, 49 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) {
diff --git a/lib/ParameterValidator.php b/lib/ParameterValidator.php
index 47f0c604..c278e4d1 100644
--- a/lib/ParameterValidator.php
+++ b/lib/ParameterValidator.php
@@ -120,4 +120,52 @@ class ParameterValidator {
return empty($this->invalid);
}
+
+ /**
+ * Returns the name of the context matching the provided inputs
+ *
+ * @param array $data Associative array of user data
+ * @param array $parameters Array of bridge parameters
+ * @return mixed Returns the context name or null if no match was found
+ */
+ public function getQueriedContext($data, $parameters){
+ $queriedContexts = array();
+
+ // Detect matching context
+ foreach($parameters as $context => $set) {
+ $queriedContexts[$context] = null;
+
+ // Check if all parameters of the context are satisfied
+ foreach($set as $id => $properties) {
+ if(isset($data[$id]) && !empty($data[$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', $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;
+ }
+ }
}