Esempio n. 1
0
 public function testAttachAndDetach()
 {
     $observer = $this->prophesize('SplObserver');
     $joinPoint = new JoinPoint('pre-download', new HttpGetRequest('example.com', 'https://example.com/', new IO\NullIO()));
     $mock = $observer->reveal();
     $joinPoint->attach($mock);
     $observer->update($joinPoint)->shouldBeCalled();
     $joinPoint->notify();
     $joinPoint->detach($mock);
     $observer->update()->shouldNotBeCalled();
     $joinPoint->notify();
 }
 /**
  * @param string $origin
  * @param string $fileUrl
  * @param boolean $progress
  * @param \Closure $exec
  */
 protected function fetch($origin, $fileUrl, $progress, $options, $exec)
 {
     do {
         $this->_retry = false;
         $request = new Aspects\HttpGetRequest($origin, $fileUrl, $this->io);
         $request->setSpecial(array('github' => $this->config->get('github-domains') ?: array(), 'gitlab' => $this->config->get('gitlab-domains') ?: array()));
         $this->onPreDownload = Factory::getPreEvent($request);
         $this->onPostDownload = Factory::getPostEvent($request);
         if ($this->_degradedMode) {
             $this->onPreDownload->attach(new Aspects\AspectDegradedMode());
         }
         $options += $this->options;
         // override
         if ('github' === $request->special && isset($options['github-token'])) {
             $request->query['access_token'] = $options['github-token'];
         }
         if ('gitlab' === $request->special && isset($options['gitlab-token'])) {
             $request->query['access_token'] = $options['gitlab-token'];
         }
         if ($this->io->isDebug()) {
             $this->io->write('Downloading ' . $fileUrl);
         }
         if ($progress) {
             $this->io->write("    Downloading: <comment>Connecting...</comment>", false);
             $request->curlOpts[CURLOPT_NOPROGRESS] = false;
             $request->curlOpts[CURLOPT_PROGRESSFUNCTION] = array($this, 'progress');
         } else {
             $request->curlOpts[CURLOPT_NOPROGRESS] = true;
             $request->curlOpts[CURLOPT_PROGRESSFUNCTION] = null;
         }
         $this->onPreDownload->notify();
         $opts = $request->getCurlOpts();
         $ch = Factory::getConnection($origin, isset($opts[CURLOPT_USERPWD]));
         if ($this->pluginConfig['insecure']) {
             $opts[CURLOPT_SSL_VERIFYPEER] = false;
         }
         if (!empty($pluginConfig['userAgent'])) {
             $opts[CURLOPT_USERAGENT] = $pluginConfig['userAgent'];
         }
         if (!empty($pluginConfig['capath'])) {
             $opts[CURLOPT_CAPATH] = $pluginConfig['capath'];
         }
         curl_setopt_array($ch, $opts);
         list($execStatus, ) = $exec($ch, $request);
     } while ($this->_retry);
     if ($progress) {
         $this->io->overwrite("    Downloading: <comment>100%</comment>");
     }
     return $execStatus;
 }
Esempio n. 3
0
 /**
  * @return Aspects\JoinPoint
  */
 public static function getPostEvent(Aspects\HttpGetRequest $req)
 {
     $post = new Aspects\JoinPoint('post-download', $req);
     $post->attach(static::getAspectAuth());
     return $post;
 }