*/ public function __construct() { $this->loadOptions(); } /** * Load options, make sure required options are set * * @author Phil Burton */ protected function loadOptions() { $this->options = getopt($this->getShortOptionString(), $this->getLongOptionString()); if (!array_key_exists('f', $this->options)) { throw new Exception('Filename Option `-f` is required'); } // If only a day or a time is given, we throw exception as we need neither or both if ((array_key_exists('d', $this->options) <=> array_key_exists('t', $this->options)) !== 0) { throw new Exception('Both day and time options (`-d` and `-t`) are required for time based filtering'); } if (array_key_exists('c', $this->options) && !is_numeric($this->options['c'])) { throw new Exception('Value for option `-c` must be an integer'); } if (array_key_exists('l', $this->options) && is_numeric($this->options['l'])) { throw new Exception('Value for option `-l` must be a string'); } } /** * Return the option string for the options we want to load * * @author Phil Burton * @return string */ public function getShortOptionString(): string { return $this->shortOpts; } /** * Return the option string for the options we want to load * * @author Phil Burton * @return string */ public function getLongOptionString(): array { return $this->longOpts; } /** * Return an option value * In it doesn't exist return false * * @author Phil Burton * @param string $key * @return mixed */ public function getOption(string $key) { if (!array_key_exists($key, $this->options)) { return false; } return $this->options[$key]; } }