forked from blallo/rss-bridge
[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)){
|
if($time !== false && (time() - $this->getCacheDuration() < $time)){
|
||||||
$this->items = $this->cache->loadData();
|
$this->items = $this->cache->loadData();
|
||||||
} else {
|
return;
|
||||||
if($this->validateData($param)){
|
}
|
||||||
|
|
||||||
|
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($param as $name=>$value){
|
||||||
foreach($this->parameters as $context=>$set){
|
foreach($this->parameters as $context=>$set){
|
||||||
if(isset($this->parameters[$context][$name]))
|
if(isset($this->parameters[$context][$name]))
|
||||||
$this->parameters[$context][$name]['value']=$value;
|
$this->parameters[$context][$name]['value']=$value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!empty($this->parameters)){
|
|
||||||
|
// Guess the paramter context from input data
|
||||||
$queriedContext=$this->getQueriedContext();
|
$queriedContext=$this->getQueriedContext();
|
||||||
if(is_null($queriedContext)){
|
if(is_null($queriedContext)){
|
||||||
$this->returnClientError('Required parameter(s) missing');
|
$this->returnClientError('Required parameter(s) missing');
|
||||||
}else if($queriedContext===false){
|
}else if($queriedContext===false){
|
||||||
$this->returnClientError('Mixed context parameters');
|
$this->returnClientError('Mixed context parameters');
|
||||||
}else{
|
}
|
||||||
|
|
||||||
$this->queriedContext=$queriedContext;
|
$this->queriedContext=$queriedContext;
|
||||||
|
|
||||||
|
// Apply default values to missing data
|
||||||
$contexts=array($this->queriedContext);
|
$contexts=array($this->queriedContext);
|
||||||
if(isset($this->parameters['global'])){
|
if(isset($this->parameters['global'])){
|
||||||
$contexts[]='global';
|
$contexts[]='global';
|
||||||
}
|
}
|
||||||
foreach($contexts as $context){
|
foreach($contexts as $context){
|
||||||
foreach($this->parameters[$context] as $p=>$props){
|
foreach($this->parameters[$context] as $p=>$properties){
|
||||||
if(isset($props['type']) &&
|
if(!isset($properties['type'])){
|
||||||
$props['type']==='checkbox' &&
|
$this->parameters[$context][$p]['type']='text';
|
||||||
!isset($props['value'])){
|
}
|
||||||
if(!isset($props['defaultValue'])){
|
if(isset($properties['value'])){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
switch($properties['type']){
|
||||||
|
case 'checkbox':
|
||||||
|
if(!isset($properties['defaultValue'])){
|
||||||
$this->parameters[$context][$p]['value']=false;
|
$this->parameters[$context][$p]['value']=false;
|
||||||
}else{
|
}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){
|
foreach($param as $name=>$value){
|
||||||
if(isset($this->parameters['global'][$name])){
|
if(isset($this->parameters['global'][$name])){
|
||||||
$this->parameters[$queriedContext][$name]['value']=$value;
|
$this->parameters[$queriedContext][$name]['value']=$value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
$this->returnClientError('Invalid parameters value(s)');
|
|
||||||
}
|
|
||||||
$this->collectData();
|
$this->collectData();
|
||||||
|
|
||||||
if(!is_null($this->cache)){
|
if(!is_null($this->cache)){
|
||||||
$this->cache->saveData($this->getDatas());
|
$this->cache->saveData($this->getDatas());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function getName(){
|
public function getName(){
|
||||||
return $this->name;
|
return $this->name;
|
||||||
|
|
Loading…
Reference in a new issue