/** * @param string * @param string file name of the channel.xml * * @return \PEAR2\Pyrus\ChannelFile\v1 */ function parse($data, $file = false, $class = 'PEAR2\Pyrus\ChannelFile\v1') { $ret = new $class; if (!$ret instanceof \PEAR2\Pyrus\ChannelFile\v1) { throw new \PEAR2\Pyrus\ChannelFile\Exception('Class ' . $class . ' passed to parse() must be a child class of \PEAR2\Pyrus\ChannelFile\v1'); } $schema = \PEAR2\Pyrus\Main::getDataPath() . '/channel-1.0.xsd'; // for running out of svn if (!file_exists($schema)) { $schema = dirname(dirname(dirname(dirname(__DIR__)))) . '/data/channel-1.0.xsd'; } try { if ($file) { $ret->fromArray(parent::parse($data, $schema)); } else { $ret->fromArray(parent::parseString($data, $schema)); } } catch (\Exception $e) { throw new \PEAR2\Pyrus\ChannelFile\Exception('Invalid channel.xml', null, $e); } return $ret; }
/** * Merge a tag into the array * @see \PEAR2\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; }