$value) { if (isset($this->$option) && isset($value)) { $this->$option = $value; } } $this->getEnv(); } /** * Override options from environement variables. * Supported environment variables: CONVERT, PYTHON, AUDIO_BITRATE. * * @return void */ private function getEnv() { foreach (['CONVERT', 'PYTHON', 'AUDIO_BITRATE', 'STREAM'] as $var) { $env = getenv($var); if ($env) { $prop = lcfirst(str_replace('_', '', ucwords(strtolower($var), '_'))); $this->$prop = $env; } } } /** * Get Config singleton instance from YAML config file. * * @param string $yamlfile YAML config file name * * @return Config */ public static function getInstance($yamlfile = 'config/config.yml') { $yamlPath = __DIR__.'/../'.$yamlfile; if (is_null(self::$instance) || self::$instance->file != $yamlfile) { if (is_file($yamlfile)) { $options = Yaml::parse(file_get_contents($yamlPath)); } elseif ($yamlfile == 'config/config.yml' || empty($yamlfile)) { /* Allow for the default file to be missing in order to not surprise users that did not create a config file */ $options = []; } else { throw new Exception("Can't find config file at ".$yamlPath); } self::$instance = new self($options); self::$instance->file = $yamlfile; } return self::$instance; } /** * Destroy singleton instance. * * @return void */ public static function destroyInstance() { self::$instance = null; } }