PEAR_Downloader::discover PHP Метод

discover() публичный Метод

Attempt to discover a channel's remote capabilities from its server name
public discover ( $channel ) : boolean
Результат boolean
    function discover($channel)
    {
        $this->log(1, 'Attempting to discover channel "' . $channel . '"...');
        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
        $callback = $this->ui ? array(&$this, '_downloadCallback') : null;
        if (!class_exists('System')) {
            require_once 'System.php';
        }
        $tmpdir = $this->config->get('temp_dir');
        $tmp = System::mktemp("-d -t {$tmpdir}");
        $a = $this->downloadHttp('http://' . $channel . '/channel.xml', $this->ui, $tmp, $callback, false);
        PEAR::popErrorHandling();
        if (PEAR::isError($a)) {
            // Attempt to fallback to https automatically.
            PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
            $this->log(1, 'Attempting fallback to https instead of http on channel "' . $channel . '"...');
            $a = $this->downloadHttp('https://' . $channel . '/channel.xml', $this->ui, $tmp, $callback, false);
            PEAR::popErrorHandling();
            if (PEAR::isError($a)) {
                return false;
            }
        }
        list($a, $lastmodified) = $a;
        if (!class_exists('PEAR_ChannelFile')) {
            require_once 'PEAR/ChannelFile.php';
        }
        $b = new PEAR_ChannelFile();
        if ($b->fromXmlFile($a)) {
            unlink($a);
            if ($this->config->get('auto_discover')) {
                $this->_registry->addChannel($b, $lastmodified);
                $alias = $b->getName();
                if ($b->getName() == $this->_registry->channelName($b->getAlias())) {
                    $alias = $b->getAlias();
                }
                $this->log(1, 'Auto-discovered channel "' . $channel . '", alias "' . $alias . '", adding to registry');
            }
            return true;
        }
        unlink($a);
        return false;
    }

Usage Example

Пример #1
0
 /**
  *
  * @param string|array pass in an array of format
  *                     array(
  *                      'package' => 'pname',
  *                     ['channel' => 'channame',]
  *                     ['version' => 'version',]
  *                     ['state' => 'state',])
  *                     or a string of format [channame/]pname[-version|-state]
  */
 function _fromString($param)
 {
     $options = $this->_downloader->getOptions();
     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
     $pname = $this->_registry->parsePackageName($param, $this->_config->get('default_channel'));
     PEAR::popErrorHandling();
     if (PEAR::isError($pname)) {
         if ($pname->getCode() == 'invalid') {
             $this->_valid = false;
             return false;
         }
         if ($pname->getCode() == 'channel') {
             $parsed = $pname->getUserInfo();
             if ($this->_downloader->discover($parsed['channel'])) {
                 if ($this->_config->get('auto_discover')) {
                     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
                     $pname = $this->_registry->parsePackageName($param, $this->_config->get('default_channel'));
                     PEAR::popErrorHandling();
                 } else {
                     if (!isset($options['soft'])) {
                         $this->_downloader->log(0, 'Channel "' . $parsed['channel'] . '" is not initialized, use ' . '"pear channel-discover ' . $parsed['channel'] . '" to initialize' . 'or pear config-set auto_discover 1');
                     }
                 }
             }
             if (PEAR::isError($pname)) {
                 if (!isset($options['soft'])) {
                     $this->_downloader->log(0, $pname->getMessage());
                 }
                 if (is_array($param)) {
                     $param = $this->_registry->parsedPackageNameToString($param);
                 }
                 $err = PEAR::raiseError('invalid package name/package file "' . $param . '"');
                 $this->_valid = false;
                 return $err;
             }
         } else {
             if (!isset($options['soft'])) {
                 $this->_downloader->log(0, $pname->getMessage());
             }
             $err = PEAR::raiseError('invalid package name/package file "' . $param . '"');
             $this->_valid = false;
             return $err;
         }
     }
     if (!isset($this->_type)) {
         $this->_type = 'xmlrpc';
     }
     $this->_parsedname = $pname;
     if (isset($pname['state'])) {
         $this->_explicitState = $pname['state'];
     } else {
         $this->_explicitState = false;
     }
     if (isset($pname['group'])) {
         $this->_explicitGroup = true;
     } else {
         $this->_explicitGroup = false;
     }
     $info = $this->_downloader->_getPackageDownloadUrl($pname);
     if (PEAR::isError($info)) {
         if ($pname['channel'] == 'pear.php.net') {
             // try pecl
             $pname['channel'] = 'pecl.php.net';
             if ($test = $this->_downloader->_getPackageDownloadUrl($pname)) {
                 if (!PEAR::isError($test)) {
                     $info = PEAR::raiseError($info->getMessage() . ' - package ' . $this->_registry->parsedPackageNameToString($pname, true) . ' can be installed with "pecl install ' . $pname['package'] . '"');
                 }
             }
         }
         return $info;
     }
     $this->_rawpackagefile = $info['raw'];
     $ret = $this->_analyzeDownloadURL($info, $param, $pname);
     if (PEAR::isError($ret)) {
         return $ret;
     }
     if ($ret) {
         $this->_downloadURL = $ret;
         return $this->_valid = (bool) $ret;
     }
 }