Example #1
0
 /**
  * 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;
 }