[Bridge] Pass 'queriedContext' as parameter to 'setInputs'

This makes clear that 'setInputs' depends on the 'queriedContext'
This commit is contained in:
logmanoriginal 2016-09-02 20:05:18 +02:00
parent d1ff23c7ba
commit a8883523f4

View file

@ -243,7 +243,8 @@ abstract class BridgeAbstract implements BridgeInterface {
return true; return true;
} }
protected function setInputs(array $inputs){ protected function setInputs(array $inputs, $queriedContext){
// Import and assign all inputs to their context
foreach($inputs as $name => $value){ foreach($inputs as $name => $value){
foreach(static::PARAMETERS as $context => $set){ foreach(static::PARAMETERS as $context => $set){
if(array_key_exists($name, static::PARAMETERS[$context])){ if(array_key_exists($name, static::PARAMETERS[$context])){
@ -253,21 +254,19 @@ abstract class BridgeAbstract implements BridgeInterface {
} }
// Apply default values to missing data // Apply default values to missing data
$contexts = array($this->queriedContext); $contexts = array($queriedContext);
if(array_key_exists('global', static::PARAMETERS)){ if(array_key_exists('global', static::PARAMETERS)){
$contexts[] = 'global'; $contexts[] = 'global';
} }
foreach($contexts as $context){ foreach($contexts as $context){
foreach(static::PARAMETERS[$context] as $name => $properties){ foreach(static::PARAMETERS[$context] as $name => $properties){
if(!isset($properties['type'])){
$type = 'text';
} else {
$type = $properties['type'];
}
if(isset($this->inputs[$context][$name]['value'])){ if(isset($this->inputs[$context][$name]['value'])){
continue; continue;
} }
$type = isset($properties['type']) ? $properties['type'] : 'text';
switch($type){ switch($type){
case 'checkbox': case 'checkbox':
if(!isset($properties['defaultValue'])){ if(!isset($properties['defaultValue'])){
@ -306,15 +305,16 @@ abstract class BridgeAbstract implements BridgeInterface {
} else { } else {
continue; continue;
} }
$this->inputs[$this->queriedContext][$name]['value'] = $value; $this->inputs[$queriedContext][$name]['value'] = $value;
} }
} }
// Only keep guessed context parameters values // Only keep guessed context parameters values
if(!isset($this->inputs[$this->queriedContext])){ if(isset($this->inputs[$queriedContext])){
$this->inputs[$this->queriedContext] = array(); $this->inputs = array($queriedContext => $this->inputs[$queriedContext]);
} else {
$this->inputs = array();
} }
$this->inputs = array($this->queriedContext=>$this->inputs[$this->queriedContext]);
} }
protected function getQueriedContext(array $inputs){ protected function getQueriedContext(array $inputs){
@ -390,7 +390,7 @@ abstract class BridgeAbstract implements BridgeInterface {
$this->returnClientError('Mixed context parameters'); $this->returnClientError('Mixed context parameters');
} }
$this->setInputs($inputs); $this->setInputs($inputs, $this->queriedContext);
$this->collectData(); $this->collectData();