[core] code simplification
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
parent
de1b39c8e5
commit
701aff420d
1 changed files with 63 additions and 46 deletions
|
@ -256,56 +256,73 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
|
||||
if($time !== false && (time() - $this->getCacheDuration() < $time)){
|
||||
$this->items = $this->cache->loadData();
|
||||
} else {
|
||||
if($this->validateData($param)){
|
||||
return;
|
||||
}
|
||||
|
||||
if(empty($this->parameters) && !empty($param)){
|
||||
$this->returnClientError('Invalid parameters value(s)');
|
||||
};
|
||||
|
||||
if(!$this->validateData($param)){
|
||||
$this->returnClientError('Invalid parameters value(s)');
|
||||
}
|
||||
|
||||
// Populate BridgeAbstract::parameters with sanitized data
|
||||
foreach($param as $name=>$value){
|
||||
foreach($this->parameters as $context=>$set){
|
||||
if(isset($this->parameters[$context][$name]))
|
||||
$this->parameters[$context][$name]['value']=$value;
|
||||
}
|
||||
}
|
||||
if(!empty($this->parameters)){
|
||||
|
||||
// Guess the paramter context from input data
|
||||
$queriedContext=$this->getQueriedContext();
|
||||
if(is_null($queriedContext)){
|
||||
$this->returnClientError('Required parameter(s) missing');
|
||||
}else if($queriedContext===false){
|
||||
$this->returnClientError('Mixed context parameters');
|
||||
}else{
|
||||
}
|
||||
|
||||
$this->queriedContext=$queriedContext;
|
||||
|
||||
// Apply default values to missing data
|
||||
$contexts=array($this->queriedContext);
|
||||
if(isset($this->parameters['global'])){
|
||||
$contexts[]='global';
|
||||
}
|
||||
foreach($contexts as $context){
|
||||
foreach($this->parameters[$context] as $p=>$props){
|
||||
if(isset($props['type']) &&
|
||||
$props['type']==='checkbox' &&
|
||||
!isset($props['value'])){
|
||||
if(!isset($props['defaultValue'])){
|
||||
foreach($this->parameters[$context] as $p=>$properties){
|
||||
if(!isset($properties['type'])){
|
||||
$this->parameters[$context][$p]['type']='text';
|
||||
}
|
||||
if(isset($properties['value'])){
|
||||
continue;
|
||||
}
|
||||
switch($properties['type']){
|
||||
case 'checkbox':
|
||||
if(!isset($properties['defaultValue'])){
|
||||
$this->parameters[$context][$p]['value']=false;
|
||||
}else{
|
||||
$this->parameters[$context][$p]['value']=$props['defaultValue'];
|
||||
}
|
||||
$this->parameters[$context][$p]['value']=$properties['defaultValue'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy global parameter values to the guessed context
|
||||
foreach($param as $name=>$value){
|
||||
if(isset($this->parameters['global'][$name])){
|
||||
$this->parameters[$queriedContext][$name]['value']=$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$this->returnClientError('Invalid parameters value(s)');
|
||||
}
|
||||
|
||||
$this->collectData();
|
||||
|
||||
if(!is_null($this->cache)){
|
||||
$this->cache->saveData($this->getDatas());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
|
|
Loading…
Reference in a new issue