[core] Add configuration for bridges, allowing private bridges (#1343)
This commit is contained in:
parent
56b2c516e4
commit
810a2503c9
4 changed files with 70 additions and 6 deletions
|
@ -131,6 +131,7 @@ class DisplayAction extends ActionAbstract {
|
|||
|
||||
try {
|
||||
$bridge->setDatas($bridge_params);
|
||||
$bridge->loadConfiguration();
|
||||
$bridge->collectData();
|
||||
|
||||
$items = $bridge->getItems();
|
||||
|
|
|
@ -61,6 +61,13 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
*/
|
||||
const CACHE_TIMEOUT = 3600;
|
||||
|
||||
/**
|
||||
* Configuration for the bridge
|
||||
*
|
||||
* Use {@see BridgeAbstract::getConfiguration()} to read this parameter
|
||||
*/
|
||||
const CONFIGURATION = array();
|
||||
|
||||
/**
|
||||
* Parameters for the bridge
|
||||
*
|
||||
|
@ -238,6 +245,36 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads configuration for the bridge
|
||||
*
|
||||
* Returns errors and aborts execution if the provided configuration is
|
||||
* invalid.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadConfiguration() {
|
||||
foreach(static::CONFIGURATION as $optionName => $optionValue) {
|
||||
|
||||
$configurationOption = Configuration::getConfig(get_class($this), $optionName);
|
||||
|
||||
if($configurationOption !== null) {
|
||||
$this->configuration[$optionName] = $configurationOption;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isset($optionValue['required']) && $optionValue['required'] === true) {
|
||||
returnServerError(
|
||||
'Missing configuration option: '
|
||||
. $optionName
|
||||
);
|
||||
} elseif(isset($optionValue['defaultValue'])) {
|
||||
$this->configuration[$optionName] = $optionValue['defaultValue'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for the provided input
|
||||
*
|
||||
|
@ -251,6 +288,19 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
return $this->inputs[$this->queriedContext][$input]['value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for the selected configuration
|
||||
*
|
||||
* @param string $input The option name
|
||||
* @return mixed|null The option value or null if the input is not defined
|
||||
*/
|
||||
public function getOption($name){
|
||||
if(!isset($this->configuration[$name])) {
|
||||
return null;
|
||||
}
|
||||
return $this->configuration[$name];
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
public function getDescription(){
|
||||
return static::DESCRIPTION;
|
||||
|
@ -271,6 +321,11 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
return static::URI . '/favicon.ico';
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
public function getConfiguration(){
|
||||
return static::CONFIGURATION;
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
public function getParameters(){
|
||||
return static::PARAMETERS;
|
||||
|
|
|
@ -58,6 +58,19 @@ interface BridgeInterface {
|
|||
*/
|
||||
public function collectData();
|
||||
|
||||
/**
|
||||
* Get the user's supplied configuration for the bridge
|
||||
*/
|
||||
public function getConfiguration();
|
||||
|
||||
/**
|
||||
* Returns the value for the selected configuration
|
||||
*
|
||||
* @param string $input The option name
|
||||
* @return mixed|null The option value or null if the input is not defined
|
||||
*/
|
||||
public function getOption($name);
|
||||
|
||||
/**
|
||||
* Returns the description
|
||||
*
|
||||
|
|
|
@ -145,13 +145,10 @@ final class Configuration {
|
|||
// Replace default configuration with custom settings
|
||||
foreach(parse_ini_file(FILE_CONFIG, true, INI_SCANNER_TYPED) as $header => $section) {
|
||||
foreach($section as $key => $value) {
|
||||
// Skip unknown sections and keys
|
||||
if(array_key_exists($header, Configuration::$config) && array_key_exists($key, Configuration::$config[$header])) {
|
||||
Configuration::$config[$header][$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!is_string(self::getConfig('system', 'timezone'))
|
||||
|| !in_array(self::getConfig('system', 'timezone'), timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
|
||||
|
@ -218,13 +215,11 @@ final class Configuration {
|
|||
* @return mixed|null The parameter value.
|
||||
*/
|
||||
public static function getConfig($section, $key) {
|
||||
|
||||
if(array_key_exists($section, self::$config) && array_key_exists($key, self::$config[$section])) {
|
||||
return self::$config[$section][$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue