1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-08 09:36:39 +02:00

[core] Add configuration for bridges, allowing private bridges (#1343)

This commit is contained in:
Lyra
2020-12-12 17:05:22 +01:00
committed by GitHub
parent 56b2c516e4
commit 810a2503c9
4 changed files with 70 additions and 6 deletions

View File

@@ -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;