/** * @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; }
/** * Parses a string containing package xml and returns an object * * @param string $data data to parse * @param string|false $file name of the archive this package.xml came from, if any * @param string $class class name to instantiate and return. * This must be PEAR2\Pyrus\PackageFile\v2 or a subclass * @param int $state what state we are currently in * * @return \PEAR2\Pyrus\PackageFile\v2 */ function parse($data, $file = false, $class = 'PEAR2\\Pyrus\\PackageFile\\v2', $state = \PEAR2\Pyrus\Validate::NORMAL) { $this->_inContents = false; $this->_path = ''; $this->_files = array(); $this->_lastDepth = $this->_lastFileDepth = 0; $this->_inFile = 0; $ret = new $class(); if (!$ret instanceof \PEAR2\Pyrus\PackageFile\v2) { throw new \PEAR2\Pyrus\PackageFile\Exception('Class ' . $class . ' passed to parse() must be a child class of \\PEAR2\\Pyrus\\PackageFile\\v2'); } if (preg_match('/<package[^>]+version="2.1"/', $data)) { $schema = \PEAR2\Pyrus\Main::getDataPath() . '/package-2.1.xsd'; // for running out of cvs if (!file_exists($schema)) { $schema = dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/data/package-2.1.xsd'; } } elseif (preg_match('/<package[^>]+version="2.0"/', $data)) { $schema = \PEAR2\Pyrus\Main::getDataPath() . '/package-2.0.xsd'; // for running out of cvs if (!file_exists($schema)) { $schema = dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/data/package-2.0.xsd'; } } else { throw new \PEAR2\Pyrus\PackageFile\Exception('Cannot process package.xml version 1.0', -3); } try { $ret->fromArray(parent::parseString($data, $schema)); } catch (\Exception $e) { throw new \PEAR2\Pyrus\PackageFile\Exception('Invalid package.xml', $e); } $ret->setFileList($this->_files); $ret->setBaseInstallDirs($this->_baseinstalldirs); $ret->setPackagefile($file); return $ret; }