core: Use methods to access bridge information

Bridge information were exposed and accessed via public constants
which doesn't work if you want to generate bridges dynamically as
discussed in #402
This commit is contained in:
logmanoriginal 2017-02-13 20:56:19 +01:00
parent c44fb25845
commit d93d491d8e
3 changed files with 47 additions and 17 deletions

View File

@ -21,7 +21,7 @@ abstract class BridgeAbstract implements BridgeInterface {
*/ */
public function getCachable(){ public function getCachable(){
return array( return array(
'items' => $this->getItems(), 'items' => $this->getItems(),
'extraInfos' => $this->getExtraInfos() 'extraInfos' => $this->getExtraInfos()
); );
} }
@ -35,7 +35,7 @@ abstract class BridgeAbstract implements BridgeInterface {
} }
/** /**
* Sets the input values for a given context. Existing values are * Sets the input values for a given context. Existing values are
* overwritten. * overwritten.
* *
* @param array $inputs Associative array of inputs * @param array $inputs Associative array of inputs
@ -228,17 +228,29 @@ abstract class BridgeAbstract implements BridgeInterface {
return $this->inputs[$this->queriedContext][$input]['value']; return $this->inputs[$this->queriedContext][$input]['value'];
} }
public function getDescription(){
return static::DESCRIPTION;
}
public function getMaintainer(){
return static::MAINTAINER;
}
public function getName(){ public function getName(){
return static::NAME; return static::NAME;
} }
public function getParameters(){
return static::PARAMETERS;
}
public function getURI(){ public function getURI(){
return static::URI; return static::URI;
} }
public function getExtraInfos(){ public function getExtraInfos(){
return array( return array(
'name' => $this->getName(), 'name' => $this->getName(),
'uri' => $this->getURI() 'uri' => $this->getURI()
); );
} }

View File

@ -13,6 +13,13 @@ interface BridgeInterface {
*/ */
public function getCachable(); public function getCachable();
/**
* Returns the description
*
* @return string Description
*/
public function getDescription();
/** /**
* Return an array of extra information * Return an array of extra information
* *
@ -27,6 +34,13 @@ interface BridgeInterface {
*/ */
public function getItems(); public function getItems();
/**
* Returns the bridge maintainer
*
* @return string Bridge maintainer
*/
public function getMaintainer();
/** /**
* Returns the bridge name * Returns the bridge name
* *
@ -34,6 +48,13 @@ interface BridgeInterface {
*/ */
public function getName(); public function getName();
/**
* Returns the bridge parameters
*
* @return array Bridge parameters
*/
public function getParameters();
/** /**
* Returns the bridge URI * Returns the bridge URI
* *

View File

@ -15,22 +15,21 @@ function displayBridgeCard($bridgeName, $formats, $isActive = true){
return $buttons; return $buttons;
}; };
$getFormHeader = function($bridge){ $getFormHeader = function($bridgeName){
return <<<EOD return <<<EOD
<form method="GET" action="?"> <form method="GET" action="?">
<input type="hidden" name="action" value="display" /> <input type="hidden" name="action" value="display" />
<input type="hidden" name="bridge" value="{$bridge}" /> <input type="hidden" name="bridge" value="{$bridgeName}" />
EOD; EOD;
}; };
$bridgeElement = Bridge::create($bridgeName); $bridge = Bridge::create($bridgeName);
$bridgeClass = $bridgeName . 'Bridge';
if($bridgeElement == false) if($bridge == false)
return ""; return "";
$name = '<a href="' . $bridgeClass::URI . '">' . $bridgeClass::NAME . '</a>'; $name = '<a href="' . $bridge->getURI() . '">' . $bridge->getName() . '</a>';
$description = $bridgeClass::DESCRIPTION; $description = $bridge->getDescription();
$card = <<<CARD $card = <<<CARD
<section id="bridge-{$bridgeName}" data-ref="{$bridgeName}"> <section id="bridge-{$bridgeName}" data-ref="{$bridgeName}">
@ -43,7 +42,7 @@ EOD;
CARD; CARD;
// If we don't have any parameter for the bridge, we print a generic form to load it. // If we don't have any parameter for the bridge, we print a generic form to load it.
if(count($bridgeClass::PARAMETERS) == 0){ if(count($bridge->getParameters()) == 0){
$card .= $getFormHeader($bridgeName); $card .= $getFormHeader($bridgeName);
@ -77,13 +76,13 @@ CARD;
$card .= '</form>' . PHP_EOL; $card .= '</form>' . PHP_EOL;
} }
$hasGlobalParameter = array_key_exists('global', $bridgeClass::PARAMETERS); $hasGlobalParameter = array_key_exists('global', $bridge->getParameters());
if($hasGlobalParameter){ if($hasGlobalParameter){
$globalParameters = $bridgeClass::PARAMETERS['global']; $globalParameters = $bridge->getParameters()['global'];
} }
foreach($bridgeClass::PARAMETERS as $parameterName => $parameter){ foreach($bridge->getParameters() as $parameterName => $parameter){
if(!is_numeric($parameterName) && $parameterName == 'global') if(!is_numeric($parameterName) && $parameterName == 'global')
continue; continue;
@ -251,7 +250,7 @@ CARD;
} }
$card .= '<label class="showless" for="showmore-' . $bridgeName . '">Show less</label>'; $card .= '<label class="showless" for="showmore-' . $bridgeName . '">Show less</label>';
$card .= '<p class="maintainer">' . $bridgeClass::MAINTAINER . '</p>'; $card .= '<p class="maintainer">' . $bridge->getMaintainer() . '</p>';
$card .= '</section>'; $card .= '</section>';
return $card; return $card;
@ -288,5 +287,3 @@ function defaultImageSrcTo($content, $server){
} }
return $content; return $content;
} }
?>