Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401]

   1  <?php
   2  
   3  namespace Box\Spout\Common\Manager;
   4  
   5  /**
   6   * Class OptionsManager
   7   */
   8  abstract class OptionsManagerAbstract implements OptionsManagerInterface
   9  {
  10      const PREFIX_OPTION = 'OPTION_';
  11  
  12      /** @var string[] List of all supported option names */
  13      private $supportedOptions = [];
  14  
  15      /** @var array Associative array [OPTION_NAME => OPTION_VALUE] */
  16      private $options = [];
  17  
  18      /**
  19       * OptionsManagerAbstract constructor.
  20       */
  21      public function __construct()
  22      {
  23          $this->supportedOptions = $this->getSupportedOptions();
  24          $this->setDefaultOptions();
  25      }
  26  
  27      /**
  28       * @return array List of supported options
  29       */
  30      abstract protected function getSupportedOptions();
  31  
  32      /**
  33       * Sets the default options.
  34       * To be overriden by child classes
  35       *
  36       * @return void
  37       */
  38      abstract protected function setDefaultOptions();
  39  
  40      /**
  41       * Sets the given option, if this option is supported.
  42       *
  43       * @param string $optionName
  44       * @param mixed $optionValue
  45       * @return void
  46       */
  47      public function setOption($optionName, $optionValue)
  48      {
  49          if (in_array($optionName, $this->supportedOptions)) {
  50              $this->options[$optionName] = $optionValue;
  51          }
  52      }
  53  
  54      /**
  55       * @param string $optionName
  56       * @return mixed|null The set option or NULL if no option with given name found
  57       */
  58      public function getOption($optionName)
  59      {
  60          $optionValue = null;
  61  
  62          if (isset($this->options[$optionName])) {
  63              $optionValue = $this->options[$optionName];
  64          }
  65  
  66          return $optionValue;
  67      }
  68  }