/** * Returns information about a package file. Expects the contents * of a package xml file as input. * * @param string $data name of package xml file * * @return array array with package information * * @access public * */ function infoFromString($data) { require_once 'PEAR/Dependency.php'; if (PEAR_Dependency::checkExtension($error, 'xml')) { return $this->raiseError($error); } $xp = @xml_parser_create(); if (!$xp) { return $this->raiseError('Unable to create XML parser'); } xml_set_object($xp, $this); xml_set_element_handler($xp, '_element_start', '_element_end'); xml_set_character_data_handler($xp, '_pkginfo_cdata'); xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false); $this->element_stack = array(); $this->pkginfo = array('provides' => array()); $this->current_element = false; unset($this->dir_install); $this->pkginfo['filelist'] = array(); $this->filelist =& $this->pkginfo['filelist']; $this->dir_names = array(); $this->in_changelog = false; $this->d_i = 0; $this->cdata = ''; $this->_validPackageFile = false; if (!xml_parse($xp, $data, 1)) { $code = xml_get_error_code($xp); $msg = sprintf("XML error: %s at line %d", xml_error_string($code), xml_get_current_line_number($xp)); xml_parser_free($xp); return $this->raiseError($msg, $code); } xml_parser_free($xp); if (!$this->_validPackageFile) { return $this->raiseError('Invalid Package File, no <package> tag'); } foreach ($this->pkginfo as $k => $v) { if (!is_array($v)) { $this->pkginfo[$k] = trim($v); } } return $this->pkginfo; }
/** * Check if the package meets all dependencies * * @param array Package information (passed by reference) * @param string Error message (passed by reference) * @return boolean False when no error occured, otherwise true */ function checkDeps(&$pkginfo, &$errors) { if (empty($this->registry)) { $this->registry = new PEAR_Registry($this->config->get('php_dir')); } $depchecker = new PEAR_Dependency($this->registry); $error = $errors = ''; $failed_deps = $optional_deps = array(); if (is_array($pkginfo['release_deps'])) { foreach ($pkginfo['release_deps'] as $dep) { $code = $depchecker->callCheckMethod($error, $dep); if ($code) { if (isset($dep['optional']) && $dep['optional'] == 'yes') { $optional_deps[] = array($dep, $code, $error); } else { $failed_deps[] = array($dep, $code, $error); } } } // {{{ failed dependencies $n = count($failed_deps); if ($n > 0) { for ($i = 0; $i < $n; $i++) { if (isset($failed_deps[$i]['type'])) { $type = $failed_deps[$i]['type']; } else { $type = 'pkg'; } switch ($failed_deps[$i][1]) { case PEAR_DEPENDENCY_MISSING: if ($type == 'pkg') { // install } $errors .= "\n" . $failed_deps[$i][2]; break; case PEAR_DEPENDENCY_UPGRADE_MINOR: if ($type == 'pkg') { // upgrade } $errors .= "\n" . $failed_deps[$i][2]; break; default: $errors .= "\n" . $failed_deps[$i][2]; break; } } return true; } // }}} // {{{ optional dependencies $count_optional = count($optional_deps); if ($count_optional > 0) { $errors = "Optional dependencies:"; for ($i = 0; $i < $count_optional; $i++) { if (isset($optional_deps[$i]['type'])) { $type = $optional_deps[$i]['type']; } else { $type = 'pkg'; } switch ($optional_deps[$i][1]) { case PEAR_DEPENDENCY_MISSING: case PEAR_DEPENDENCY_UPGRADE_MINOR: default: $errors .= "\n" . $optional_deps[$i][2]; break; } } return false; } // }}} } return false; }