/** * Loads an array from a given file name * * json => json_decode * php => include * yml? => Tale\Yaml\Parser * xml => Tale\Dom\Xml\Parser * * @param string $path The path of the array file to load * * @throws \Exception * * @return array The array parsed from the file */ public static function fromFile($path) { $ext = pathinfo($path, \PATHINFO_EXTENSION); $items = null; switch ($ext) { default: case 'php': $items = (include $path); break; case 'json': //Special tale flavor? //Allows for //-style comments line-wise $json = implode('', array_filter(array_map('trim', file($path)), function ($line) { return strpos($line, '//') !== 0; })); $items = json_decode($json, true); break; case 'xml': $items = XmlElement::fromFile($path)->getArray(); break; } if (!is_array($items)) { throw new \Exception("Failed to load array from file: {$path} doesnt contain a valid array"); } return $items; }
public function __construct($name, array $attributes = null, $version = null, $encoding = null, Node $parent = null, array $children = null) { parent::__construct($name, $attributes, $parent, $children); $this->_version = $version ? $version : self::DEFAULT_VERSION; $this->_encoding = $encoding ? $encoding : self::DEFAULT_ENCODING; }