/** * @param string * @param string file name of the channel.xml * * @return \Pyrus\ChannelFile\v1 */ function parse($data, $class = 'Pyrus\\ChannelFile\\v1') { $ret = new $class(); if (!$ret instanceof \Pyrus\ChannelFile\v1) { throw new \Pyrus\ChannelFile\Exception('Class ' . $class . ' passed to parse() must be a child class of \\Pyrus\\ChannelFile\\v1'); } $schema = \Pyrus\Main::getDataPath() . '/channel-1.0.xsd'; try { $data = trim($data); if (substr($data, 0, 5) !== '<?xml' && file_exists($data)) { $ret->fromArray(parent::parse($data, $schema)); } else { $ret->fromArray(parent::parseString($data, $schema)); } } catch (\Exception $e) { throw new \Pyrus\ChannelFile\Exception('Invalid channel.xml', null, $e); } return $ret; }
/** * Merge a tag into the array * @see \Pyrus\XMLParser::mergeTag() * * @param array $arr The array representation of the XML * @param string $tag The tag name * @param array $attribs Associative array of attributes for this tag * @param string $name The tag name * @param int $depth The current depth within the XML document * * @return array */ protected function mergeTag($arr, $tag, $attribs, $name, $depth) { $arr = parent::mergeTag($arr, $tag, $attribs, $name, $depth); if ($this->_inContents) { if ($this->_inFile) { if ($depth < $this->_inFile) { $this->_inFile = 0; } } if ($name === 'dir') { while ($this->_lastDepth >= $depth) { $this->_path = dirname($this->_path); if ($this->_path == '.') { $this->_path = ''; } else { $this->_path .= '/'; } $this->_lastDepth--; } $this->_lastDepth = $depth; $this->_lastFileDepth = $depth + 1; $origpath = $path = $attribs['name']; if ($path === '/') { $path = ''; } else { $path .= '/'; } $this->_path .= $path; if (isset($attribs['baseinstalldir'])) { $this->_baseinstalldirs[$origpath] = $attribs['baseinstalldir']; } else { if (isset($this->_baseinstalldirs[dirname($path)])) { $this->_baseinstalldirs[$origpath] = $this->_baseinstalldirs[dirname($path)]; } } } elseif ($name === 'file') { while ($this->_lastFileDepth > $depth) { $this->_path = dirname($this->_path); if ($this->_path == '.') { $this->_path = ''; } else { $this->_path .= '/'; } $this->_lastFileDepth--; $this->_lastDepth--; } $path = $this->_path . $attribs['name']; if (isset($arr['file'][0])) { $newarr = $arr['file'][count($arr['file']) - 1]; } else { $newarr = $arr['file']; } $newarr['attribs']['name'] = $path; $this->_files[$path] = $newarr; $this->_curFile = $path; $this->_inFile = $depth; } elseif ($this->_inFile) { // add tasks $this->_files[$this->_curFile][$name] = $arr[$name]; } } elseif ($name === 'contents') { $this->_inContents = true; } return $arr; }