importFile($import_file); if(is_null($this->fetchUserAgentString)) { $this->fetchUserAgentString = sprintf('Arsse/%s (%s %s; %s; https://code.jkingweb.ca/jking/arsse) PicoFeed (https://github.com/fguillot/picoFeed)', VERSION, // Arsse version php_uname('s'), // OS php_uname('r'), // OS version php_uname('m') // platform architecture ); } } /** Layers configuration data from a file into an existing object * * The file must be a PHP script which return an array with keys that match the properties of the Conf class. Malformed files will throw an exception; unknown keys are silently ignored. Files may be imported is succession, though this is not currently used. * @param string $file Full path and file name for the file to import */ public function importFile(string $file): self { if(!file_exists($file)) throw new Conf\Exception("fileMissing", $file); if(!is_readable($file)) throw new Conf\Exception("fileUnreadable", $file); try { ob_start(); $arr = (@include $file); } catch(\Throwable $e) { $arr = null; } finally { ob_end_clean(); } if(!is_array($arr)) throw new Conf\Exception("fileCorrupt", $file); return $this->import($arr); } /** Layers configuration data from an associative array into an existing object * * The input array must have keys that match the properties of the Conf class; unknown keys are silently ignored. Arrays may be imported is succession, though this is not currently used. * @param mixed[] $arr Array of configuration parameters to export */ public function import(array $arr): self { foreach($arr as $key => $value) { $this->$key = $value; } return $this; } /** Outputs non-default configuration settings as a string compatible with var_export() * * If provided a file name, will produce the text of a PHP script suitable for later import * @param string $file Full path and file name for the file to export to */ public function export(string $file = ""): string { // TODO: write export method } /** Alias of export() method with no parameters * @see self::export() */ public function __toString(): string { return $this->export(); } }