function validate(\PEAR2\Pyrus\PackageInterface $package, array $file) { $parser = new \PEAR2\Pyrus\XMLParser(); $schemapath = \PEAR2\Pyrus\Main::getDataPath(); if (!file_exists(\PEAR2\Pyrus\Main::getDataPath() . '/customcommand-2.0.xsd')) { $schemapath = realpath(__DIR__ . '/../../../../../data'); } $taskschema = $schemapath . '/customcommand-2.0.xsd'; try { $taskinfo = $parser->parse($package->getFilePath($file['attribs']['name']), $taskschema); } catch (\Exception $e) { throw new \PEAR2\Pyrus\Installer\Role\Exception('Invalid custom command definition file,' . ' file does not conform to the schema', $e); } }
/** * Grab information on a maintainer * * @param string $handle The user's handle eg: cellog * * @return array */ function getInfo($handle) { $path = $this->getRESTPath('m', strtolower($handle) . '/info.xml'); $reader = new \PEAR2\Pyrus\XMLParser; if (!file_exists($path)) { return false; } try { $info = $reader->parse($path); return $info['m']; } catch (Exception $e) { throw new PEAR2_SimpleChannelServer_Exception('Cannot read information on ' . 'developer ' . $handle, $e); } }
public function listPackages($channel) { $dir = $this->_namePath($channel, ''); if (!@file_exists($dir)) { return array(); } $ret = array(); try { $parser = new \PEAR2\Pyrus\XMLParser(); foreach (new \DirectoryIterator($dir) as $file) { if ($file->isDot()) { continue; } try { foreach (new \DirectoryIterator($file->getPathName()) as $registries) { if ($registries->isDir()) { continue; } $a = $parser->parse($registries->getPathName()); $ret[] = $a['package']['name']; } } catch (\Exception $e) { \PEAR2\Pyrus\Logger::log(0, 'Warning: corrupted XML registry entry: ' . $file->getPathName() . ': ' . $e); } } } catch (\Exception $e) { throw new Exception('Could not open channel directory for ' . 'channel ' . $channel, $e); } return $ret; }
/** * Save package REST based on a release * * @param \PEAR2\Pyrus\Package $new */ function saveInfo(\PEAR2\Pyrus\Package $new) { $reader = new \PEAR2\Pyrus\XMLParser; $deprecated = false; if (file_exists($this->rest . DIRECTORY_SEPARATOR . 'p' . DIRECTORY_SEPARATOR . 'info.xml')) { $oldinfo = $reader->parse($this->rest . DIRECTORY_SEPARATOR . 'p' . DIRECTORY_SEPARATOR . 'info.xml'); if (isset($oldinfo['p']['dp'])) { $deprecated = array('dp' => $oldinfo['p']['dp'], 'dc' => $oldinfo['p']['dc']); } } $xml = array(); $xml['n'] = $new->name; $xml['c'] = $this->channel; try { $category = PEAR2_SimpleChannelServer_Categories::getPackageCategory($new->name); } catch (PEAR2_SimpleChannelServer_Categories_Exception $e) { $categories = PEAR2_SimpleChannelServer_Categories::create('Default', 'This is the default category'); $categories->linkPackageToCategory($new->name,'Default'); $category = PEAR2_SimpleChannelServer_Categories::getPackageCategory($new->name); } $xml['ca'] = array( 'attribs' => array('xlink:href' => $this->getCategoryRESTLink($category)), '_content' => $category, ); $xml['l'] = $new->license['name']; $xml['s'] = $new->summary; $xml['d'] = $new->description; $xml['r'] = array('attribs' => $this->getReleaseRESTLink(strtolower($new->name))); if ($a = $new->extends) { $xml['pa'] = array('attribs' => array('xlink:href' => $this->getPackageRESTLink(strtolower($a) . '/info.xml')), '_content' => $a); } $xmlinf = $this->_getProlog('p', 'package'); $xml['attribs'] = $xmlinf['p']['attribs']; $xml = array('p' => $xml); $this->savePackageREST(strtolower($new->name) . '/info.xml', $xml); }
/** * Scan through the Command directory looking for classes * and see what commands they implement. * @param string which directory to look for classes, defaults to * the Installer/Roles subdirectory of * the directory from where this file (__FILE__) is * included. * * @return bool TRUE on success, a PEAR error on failure * @access public * @static */ static function registerRoles($dir = null) { self::$_roles = array(); $parser = new \PEAR2\Pyrus\XMLParser; if ($dir === null) { $dir = __DIR__ . '/Role'; } if (!file_exists($dir) || !is_dir($dir)) { throw new Role\Exception("registerRoles: opendir($dir) failed"); } $dp = @opendir($dir); if (empty($dp)) { throw new Role\Exception("registerRoles: opendir($dir) failed"); } $schemapath = \PEAR2\Pyrus\Main::getDataPath() . '/customrole-2.0.xsd'; if (!file_exists($schemapath)) { $schemapath = realpath(__DIR__ . '/../../../data/customrole-2.0.xsd'); } while ($entry = readdir($dp)) { if ($entry{0} == '.' || substr($entry, -4) != '.xml') { continue; } $role = strtolower(basename($entry, '.xml')); // List of roles if (!isset(self::$_roles[$role])) { $file = "$dir/$entry"; $data = $parser->parse($file, $schemapath); $data = $data['role']; if (!is_array($data['releasetypes'])) { $data['releasetypes'] = array($data['releasetypes']); } self::$_roles[$role] = $data; } } closedir($dp); $roles = self::$_roles; ksort($roles); self::$_roles = $roles; self::getBaseinstallRoles(true); self::getInstallableRoles(true); self::getValidRoles('****', true); return true; }
/** * save REST information for all releases of this package * * @param \PEAR2\Pyrus\Package $new package to save all release info for * @param bool $erase if true, the release represented by the * version of $new will be removed. * * @return void */ function saveAll(\PEAR2\Pyrus\Package $new, $erase = false, $is2 = false) { if ($is2) { $is2 = '2'; } else { $is2 = ''; } $reader = new \PEAR2\Pyrus\XMLParser; $path = $this->getRESTPath('r', strtolower($new->name) . DIRECTORY_SEPARATOR . 'allreleases' . $is2 . '.xml'); if (file_exists($path)) { $xml = $reader->parse($path); if (isset($xml['a']['r']) && !isset($xml['a']['r'][0])) { $xml['a']['r'] = array($xml['a']['r']); } } else { $xml = $this->_getProlog('a', 'allreleases' . $is2); $xml['a']['p'] = $new->name; $xml['a']['c'] = $this->chan; $xml['a']['r'] = array(); } if ($erase) { foreach ($xml['a']['r'] as $i => $release) { if ($release['v'] === $new->version['release']) { unset($xml['a']['r'][$i]); $xml['a']['r'] = array_values($xml['a']['r']); break; } } if (!count($xml['a']['r'])) { // no releases, erase all traces foreach (new DirectoryIterator($this->getRESTPath('r', strtolower($new->name))) as $name => $info) { if ($info->isDot()) continue; unlink($name); } } } else { $info = array( 'v' => $new->version['release'], 's' => $new->stability['release'], ); if ($is2) { $info['m'] = $new->dependencies['required']->php->min; } if (count($new->compatible)) { $info['co'] = array(); foreach ($new->compatible as $package=>$cinfo) { if (strpos($package, '/')) { $c = substr($package, 0, strpos($package, '/')); $package = str_replace(array($c, '/'), '', $package); } else { $c = 'pear.php.net'; } unset($cinfo['channel']); unset($cinfo['package']); if (isset($cinfo['exclude'])) { $info['x'] = $cinfo['exclude']; unset($cinfo['exclude']); } $info['co'][] = array_merge(array('c' => $c, 'p' => $package), $cinfo); } } $test = $xml['a']['r']; if (count($test) && !isset($test[0])) { if ($test['v'] != $info['v']) { $test = array($info, $test); } } else { $found = false; foreach ($test as $i => $rel) { if ($rel['v'] == $info['v']) { $found = true; $test[$i] = $info; break; } } if (!$found) { array_unshift($test, $info); } } if (count($test) == 1) { $test = $test[0]; } $xml['a']['r'] = $test; } $this->saveReleaseREST(strtolower($new->name) . '/allreleases' . $is2 . '.xml', $xml); return $xml; }
function addDeveloperCommands($type) { $schemapath = \PEAR2\Pyrus\Main::getDataPath() . '/customcommand-2.0.xsd'; $defaultcommands = \PEAR2\Pyrus\Main::getDataPath() . '/' . $type . 'commands.xml'; if (!file_exists($schemapath)) { $schemapath = realpath(__DIR__ . '/../../../../data/customcommand-2.0.xsd'); $defaultcommands = realpath(__DIR__ . '/../../../../data/' . $type . 'commands.xml'); } $parser = new \PEAR2\Pyrus\XMLParser(); $commands = $parser->parse($defaultcommands, $schemapath); $commands = $commands['commands']['command']; \PEAR2\Pyrus\PluginRegistry::addCommand($commands); }
/** * Save packagesinfo.xml for a category * * @param string $category Category to update packages info for * * @return void */ function savePackagesInfo($category) { $xml = array(); $pdir = $this->rest . DIRECTORY_SEPARATOR . 'p'; $rdir = $this->rest . DIRECTORY_SEPARATOR . 'r'; $packages = PEAR2_SimpleChannelServer_Categories::packagesInCategory($category); $reader = new \PEAR2\Pyrus\XMLParser; clearstatcache(); $xml['pi'] = array(); foreach ($packages as $package) { $next = array(); if (!file_exists($pdir . DIRECTORY_SEPARATOR . strtolower($package['name']) . DIRECTORY_SEPARATOR . 'info.xml')) { continue; } $f = $reader->parse($pdir . DIRECTORY_SEPARATOR . strtolower($package['name']) . DIRECTORY_SEPARATOR . 'info.xml'); unset($f['p']['attribs']); $next['p'] = $f['p']; if (file_exists($rdir . DIRECTORY_SEPARATOR . strtolower($package['name']) . DIRECTORY_SEPARATOR . 'allreleases.xml')) { $r = $reader->parse($rdir . DIRECTORY_SEPARATOR . strtolower($package['name']) . DIRECTORY_SEPARATOR . 'allreleases.xml'); unset($r['a']['attribs']); unset($r['a']['p']); unset($r['a']['c']); $next['a'] = $r['a']; $dirhandle = opendir($rdir . DIRECTORY_SEPARATOR . strtolower($package['name'])); while (false !== ($entry = readdir($dirhandle))) { if (strpos($entry, 'deps.') === 0) { $version = str_replace(array('deps.', '.txt'), array('', ''), $entry); $next['deps'] = array(); $next['deps']['v'] = $version; $next['deps']['d'] = file_get_contents($rdir . DIRECTORY_SEPARATOR . strtolower($package['name']) . DIRECTORY_SEPARATOR . $entry); } } } $xml['pi'][] = $next; } $xmlinf = $this->_getProlog('f', 'categorypackageinfo'); $xmlinf['f'][] = $xml; $this->saveCategoryREST($category . DIRECTORY_SEPARATOR . 'packagesinfo.xml', $xmlinf); }
/** * List all maintainers, or maintainers of a specific package * * @param string|null $package null to list all maintainers * * @return array */ function listMaintainers($package = null) { if ($package === null) { if (!file_exists($this->rest->getRESTPath('p', 'allpackages.xml'))) { return array(); } try { $list = $reader->parse($this->rest->getRESTPath('m', 'allmaintainers.xml')); $maint = new PEAR2_SimpleChannelServer_REST_Maintainer($this->webpath, $this->channel, $this->uri); $ret = array(); foreach ($list['m']['h'] as $info) { $inf = $maint->getInfo($info['_content']); if (!$inf) { throw new PEAR2_SimpleChannelServer_Exception('Maintainer ' . $info['_content'] . ' is listed as a maintainer, ' . 'but does not have an info file'); } $ret[] = array( 'user' => $info['_content'], 'name' => $inf['n'] ); } return $ret; } catch (Exception $e) { throw new PEAR2_SimpleChannelServer_Exception('Unable to list maintainers', $e); } } $reader = new \PEAR2\Pyrus\XMLParser; $path = $this->rest->getRESTPath('r', strtolower($package) . '/maintainers2.xml'); if (!file_exists($path)) { return array(); } try { $list = $reader->parse($path); } catch (Exception $e) { throw new PEAR2_SimpleChannelServer_Exception('Unable to list maintainers for' . ' package ' . $package, $e); } $ret = array(); if (!isset($list['m']['m'][0])) { $list['m']['m'] = array($list['m']['m']); } $maint = new PEAR2_SimpleChannelServer_REST_Maintainer($this->webpath, $this->channel, $this->uri); foreach ($list['m']['m'] as $maintainer) { $info = $maint->getInfo($maintainer['h']); $inf = array( 'user' => $maintainer['h'], ); if ($info) { $inf['name'] = $info['n']; } $inf['active'] = $maintainer['a']; $ret[] = $inf; } return $ret; }