function validatePackageName() { $ret = parent::validatePackageName(); if (in_array($this->_packagexml->getPackageType(), array('extsrc', 'zendextsrc'))) { $package = $this->_packagexml->name; $provides = $this->_packagexml->providesextension; if (strtolower($package) != strtolower($provides)) { $this->_addWarning('providesextension', 'package name "' . $package . '" is different from extension name "' . $provides . '"'); } } return $ret; }
/** * Parse a package name, or validate a parsed package name array * @param string string of format * [channel://][channame/]pname[-version|-state][/group=groupname] * [http|https]://uri * * @return array */ public function parseName($param, $defaultchannel = 'pear2.php.net') { $saveparam = $param; $components = @parse_url((string) $param); if (isset($components['scheme'])) { if ($components['scheme'] == 'http' || $components['scheme'] == 'https') { // uri package $param = array('uri' => $param, 'channel' => '__uri'); return $param; } elseif ($components['scheme'] != 'channel') { throw new ParseException('parsePackageName(): only channel:// uris may ' . 'be downloaded, not "' . $param . '"', 'scheme'); } } if (!isset($components['path'])) { throw new ParseException('parsePackageName(): array $param ' . 'must contain a valid package name in "' . $param . '"', 'path'); } if (isset($components['host'])) { // remove the leading "/" $components['path'] = substr($components['path'], 1); } if (!isset($components['scheme'])) { if (strpos($components['path'], '/') !== false) { if ($components['path'][0] == '/') { throw new ParseException('parsePackageName(): this is not ' . 'a package name, it begins with "/" in "' . $param . '"', 'invalid'); } $parts = explode('/', $components['path']); $components['host'] = array_shift($parts); if (count($parts) > 1) { $components['path'] = array_pop($parts); $components['host'] .= '/' . implode('/', $parts); } else { $components['path'] = implode('/', $parts); } } else { $components['host'] = $defaultchannel; } } else { if (strpos($components['path'], '/')) { $parts = explode('/', $components['path']); $components['path'] = array_pop($parts); $components['host'] .= '/' . implode('/', $parts); } } $param = array('package' => $components['path']); if (isset($components['host'])) { $param['channel'] = $components['host']; } if (isset($components['fragment'])) { $param['group'] = $components['fragment']; } if (isset($components['user'])) { $param['user'] = $components['user']; } if (isset($components['pass'])) { $param['pass'] = $components['pass']; } if (isset($components['query'])) { parse_str($components['query'], $param['opts']); } // check for extension $pathinfo = pathinfo($param['package']); if (isset($pathinfo['extension']) && in_array(strtolower($pathinfo['extension']), array('tgz', 'tar', 'zip', 'tbz', 'phar'))) { $param['extension'] = $pathinfo['extension']; $param['package'] = substr($pathinfo['basename'], 0, strlen($pathinfo['basename']) - strlen($pathinfo['extension']) - 1); } // check for version if (strpos($param['package'], '-')) { $test = explode('-', $param['package']); if (count($test) != 2) { throw new ParseException('parseName(): only one version/state ' . 'delimiter "-" is allowed in "' . $saveparam . '"', 'invalid'); } list($param['package'], $param['version']) = $test; } // validation $info = $this->exists($param['channel'], false); if (!$info) { throw new ParseException('unknown channel "' . $param['channel'] . '" in "' . $saveparam . '"', 'channel', $param); } try { $chan = $this->get($param['channel'], false); } catch (\Exception $e) { throw new ParseException("Exception: corrupt registry, could not " . "retrieve channel " . $param['channel'] . " information", 'other', $e); } $param['channel'] = $chan->name; $validate = $chan->getValidationObject(false); $vpackage = $chan->getValidationPackage(); // validate package name if (!$validate->validPackageName($param['package'], $vpackage['_content'])) { throw new ParseException('parseName(): invalid package name "' . $param['package'] . '" in "' . $saveparam . '"', 'package'); } if (isset($param['group'])) { if (!\PEAR2\Pyrus\Validate::validGroupName($param['group'])) { throw new ParseException('parseName(): dependency group "' . $param['group'] . '" is not a valid group name in "' . $saveparam . '"', 'group'); } } if (isset($param['version'])) { // check whether version is actually a state if (in_array(strtolower($param['version']), $validate->getValidStates())) { $param['state'] = strtolower($param['version']); unset($param['version']); } else { if (!$validate->validVersion($param['version'])) { throw new ParseException('parseName(): "' . $param['version'] . '" is neither a valid version nor a valid state in "' . $saveparam . '"', 'version/state'); } } } return $param; }