PEAR_Downloader::_getDepPackageDownloadUrl PHP 메소드

_getDepPackageDownloadUrl() 공개 메소드

public _getDepPackageDownloadUrl ( $dep, $parr )
    function _getDepPackageDownloadUrl($dep, $parr)
    {
        $xsdversion = isset($dep['rel']) ? '1.0' : '2.0';
        $curchannel = $this->config->get('default_channel');
        if (isset($dep['uri'])) {
            $xsdversion = '2.0';
            $chan =& $this->_registry->getChannel('__uri');
            if (PEAR::isError($chan)) {
                return $chan;
            }
            $version = $this->_registry->packageInfo($dep['name'], 'version', '__uri');
            $this->configSet('default_channel', '__uri');
        } else {
            if (isset($dep['channel'])) {
                $remotechannel = $dep['channel'];
            } else {
                $remotechannel = 'pear.php.net';
            }
            if (!$this->_registry->channelExists($remotechannel)) {
                do {
                    if ($this->config->get('auto_discover')) {
                        if ($this->discover($remotechannel)) {
                            break;
                        }
                    }
                    return PEAR::raiseError('Unknown remote channel: ' . $remotechannel);
                } while (false);
            }
            $chan =& $this->_registry->getChannel($remotechannel);
            if (PEAR::isError($chan)) {
                return $chan;
            }
            $version = $this->_registry->packageInfo($dep['name'], 'version', $remotechannel);
            $this->configSet('default_channel', $remotechannel);
        }
        $state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');
        if (isset($parr['state']) && isset($parr['version'])) {
            unset($parr['state']);
        }
        if (isset($dep['uri'])) {
            $info =& $this->newDownloaderPackage($this);
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
            $err = $info->initialize($dep);
            PEAR::staticPopErrorHandling();
            if (!$err) {
                // skip parameters that were missed by preferred_state
                return PEAR::raiseError('Cannot initialize dependency');
            }
            if (PEAR::isError($err)) {
                if (!isset($this->_options['soft'])) {
                    $this->log(0, $err->getMessage());
                }
                if (is_object($info)) {
                    $param = $info->getChannel() . '/' . $info->getPackage();
                }
                return PEAR::raiseError('Package "' . $param . '" is not valid');
            }
            return $info;
        } elseif ($chan->supportsREST($this->config->get('preferred_mirror')) && (($base2 = $chan->getBaseURL('REST1.3', $this->config->get('preferred_mirror'))) || ($base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))))) {
            if ($base2) {
                $base = $base2;
                $rest =& $this->config->getREST('1.3', $this->_options);
            } else {
                $rest =& $this->config->getREST('1.0', $this->_options);
            }
            $url = $rest->getDepDownloadURL($base, $xsdversion, $dep, $parr, $state, $version, $chan->getName());
            if (PEAR::isError($url)) {
                return $url;
            }
            if ($parr['channel'] != $curchannel) {
                $this->configSet('default_channel', $curchannel);
            }
            if (!is_array($url)) {
                return $url;
            }
            $url['raw'] = false;
            // no checking is necessary for REST
            if (!is_array($url['info'])) {
                return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' . 'this should never happen');
            }
            if (isset($url['info']['required'])) {
                if (!class_exists('PEAR_PackageFile_v2')) {
                    require_once 'PEAR/PackageFile/v2.php';
                }
                $pf = new PEAR_PackageFile_v2();
                $pf->setRawChannel($remotechannel);
            } else {
                if (!class_exists('PEAR_PackageFile_v1')) {
                    require_once 'PEAR/PackageFile/v1.php';
                }
                $pf = new PEAR_PackageFile_v1();
            }
            $pf->setRawPackage($url['package']);
            $pf->setDeps($url['info']);
            if ($url['compatible']) {
                $pf->setCompatible($url['compatible']);
            }
            $pf->setRawState($url['stability']);
            $url['info'] =& $pf;
            if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
                $ext = '.tar';
            } else {
                $ext = '.tgz';
            }
            if (is_array($url) && isset($url['url'])) {
                $url['url'] .= $ext;
            }
            return $url;
        }
        return $this->raiseError($parr['channel'] . ' is using a unsupported protocol - This should never happen.');
    }

Usage Example

예제 #1
0
 function _detect1($deps, $pname, $options, $params)
 {
     $this->_downloadDeps = array();
     $skipnames = array();
     foreach ($deps as $dep) {
         $nodownload = false;
         if ($dep['type'] == 'pkg') {
             $dep['channel'] = 'pear.php.net';
             $dep['package'] = $dep['name'];
             switch ($dep['rel']) {
                 case 'not':
                     continue 2;
                 case 'ge':
                 case 'eq':
                 case 'gt':
                 case 'has':
                     $group = !isset($dep['optional']) || $dep['optional'] == 'no' ? 'required' : 'optional';
                     if (PEAR_Downloader_Package::willDownload($dep, $params)) {
                         $this->_downloader->log(2, $this->getShortName() . ': Skipping ' . $group . ' dependency "' . $this->_registry->parsedPackageNameToString($dep, true) . '", will be installed');
                         continue 2;
                     }
                     $fakedp = new PEAR_PackageFile_v1();
                     $fakedp->setPackage($dep['name']);
                     // skip internet check if we are not upgrading (bug #5810)
                     if (!isset($options['upgrade']) && $this->isInstalled($fakedp, $dep['rel'])) {
                         $this->_downloader->log(2, $this->getShortName() . ': Skipping ' . $group . ' dependency "' . $this->_registry->parsedPackageNameToString($dep, true) . '", is already installed');
                         continue 2;
                     }
             }
             PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
             if ($this->_explicitState) {
                 $pname['state'] = $this->_explicitState;
             }
             $url = $this->_downloader->_getDepPackageDownloadUrl($dep, $pname);
             $chan = 'pear.php.net';
             if (PEAR::isError($url)) {
                 // check to see if this is a pecl package that has jumped
                 // from pear.php.net to pecl.php.net channel
                 if (!class_exists('PEAR_Dependency2')) {
                     require_once 'PEAR/Dependency2.php';
                 }
                 $newdep = PEAR_Dependency2::normalizeDep($dep);
                 $newdep = $newdep[0];
                 $newdep['channel'] = 'pecl.php.net';
                 $chan = 'pecl.php.net';
                 $url = $this->_downloader->_getDepPackageDownloadUrl($newdep, $pname);
                 $obj =& $this->_registry->getPackage($dep['name']);
                 if (PEAR::isError($url)) {
                     PEAR::popErrorHandling();
                     if ($obj !== null && $this->isInstalled($obj, $dep['rel'])) {
                         $group = !isset($dep['optional']) || $dep['optional'] == 'no' ? 'required' : 'optional';
                         $dep['package'] = $dep['name'];
                         if (!isset($options['soft'])) {
                             $this->_downloader->log(3, $this->getShortName() . ': Skipping ' . $group . ' dependency "' . $this->_registry->parsedPackageNameToString($dep, true) . '", already installed as version ' . $obj->getVersion());
                         }
                         if (@$skipnames[count($skipnames) - 1] == $this->_registry->parsedPackageNameToString($dep, true)) {
                             array_pop($skipnames);
                         }
                         continue;
                     } else {
                         if (isset($dep['optional']) && $dep['optional'] == 'yes') {
                             $this->_downloader->log(2, $this->getShortName() . ': Skipping ' . $group . ' dependency "' . $this->_registry->parsedPackageNameToString($dep, true) . '", no releases exist');
                             continue;
                         } else {
                             return $url;
                         }
                     }
                 }
             }
             PEAR::popErrorHandling();
             if (!isset($options['alldeps'])) {
                 if (isset($dep['optional']) && $dep['optional'] == 'yes') {
                     if (!isset($options['soft'])) {
                         $this->_downloader->log(3, 'Notice: package "' . $this->getShortName() . '" optional dependency "' . $this->_registry->parsedPackageNameToString(array('channel' => $chan, 'package' => $dep['name']), true) . '" will not be automatically downloaded');
                     }
                     $skipnames[] = $this->_registry->parsedPackageNameToString(array('channel' => $chan, 'package' => $dep['name']), true);
                     $nodownload = true;
                 }
             }
             if (!isset($options['alldeps']) && !isset($options['onlyreqdeps'])) {
                 if (!isset($dep['optional']) || $dep['optional'] == 'no') {
                     if (!isset($options['soft'])) {
                         $this->_downloader->log(3, 'Notice: package "' . $this->getShortName() . '" required dependency "' . $this->_registry->parsedPackageNameToString(array('channel' => $chan, 'package' => $dep['name']), true) . '" will not be automatically downloaded');
                     }
                     $skipnames[] = $this->_registry->parsedPackageNameToString(array('channel' => $chan, 'package' => $dep['name']), true);
                     $nodownload = true;
                 }
             }
             // check to see if a dep is already installed
             // do not try to move this before getDepPackageDownloadURL
             // we can't determine whether upgrade is necessary until we know what
             // version would be downloaded
             if (!isset($options['force']) && $this->isInstalled($url, $dep['rel'])) {
                 $group = !isset($dep['optional']) || $dep['optional'] == 'no' ? 'required' : 'optional';
                 $dep['package'] = $dep['name'];
                 if (isset($newdep)) {
                     $version = $this->_registry->packageInfo($newdep['name'], 'version', $newdep['channel']);
                 } else {
                     $version = $this->_registry->packageInfo($dep['name'], 'version');
                 }
                 $dep['version'] = $url['version'];
                 if (!isset($options['soft'])) {
                     $this->_downloader->log(3, $this->getShortName() . ': Skipping ' . $group . ' dependency "' . $this->_registry->parsedPackageNameToString($dep, true) . '", already installed as version ' . $version);
                 }
                 if (@$skipnames[count($skipnames) - 1] == $this->_registry->parsedPackageNameToString($dep, true)) {
                     array_pop($skipnames);
                 }
                 continue;
             }
             if ($nodownload) {
                 continue;
             }
             PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
             if (isset($newdep)) {
                 $dep = $newdep;
             }
             $dep['package'] = $dep['name'];
             $ret = $this->_analyzeDownloadURL($url, 'dependency', $dep, $params, isset($dep['optional']) && $dep['optional'] == 'yes' && !isset($options['alldeps']));
             PEAR::popErrorHandling();
             if (PEAR::isError($ret)) {
                 if (!isset($options['soft'])) {
                     $this->_downloader->log(0, $ret->getMessage());
                 }
                 continue;
             }
             $this->_downloadDeps[] = $ret;
         }
     }
     if (count($skipnames)) {
         if (!isset($options['soft'])) {
             $this->_downloader->log(1, 'Did not download dependencies: ' . implode(', ', $skipnames) . ', use --alldeps or --onlyreqdeps to download automatically');
         }
     }
 }
All Usage Examples Of PEAR_Downloader::_getDepPackageDownloadUrl