Exemplo n.º 1
0
 /**
  * Chargement des variations de la commande
  *
  * @param Command   $cmd     Commande en cours
  * @param string    $content Resultat de l'aspiration
  * @param Mollicute $moll    Plan d'aspiration
  *
  * @return array
  * @throws \Siwayll\Mollicute\Abort si un plan est chargé
  */
 public function before(Command $cmd, $content, Mollicute $moll)
 {
     if ($cmd->declination !== true) {
         return;
     }
     foreach ($cmd->declGenerator as $key => $generator) {
         $tag = '[' . $key . ']';
         foreach ($cmd->getDeclination($key) as $data) {
             $result = clone $cmd;
             if (is_array($data)) {
                 $result->set('declinationData', $data);
                 $data = $data[0];
             }
             if (is_object($data)) {
                 $result->set('declinationData', $data);
             }
             $url = str_replace($tag, $data, $cmd->getUrl());
             $result->setUrl($url);
             if ($result->hasMethod('getFileName') && strpos($result->getFileName(), $tag) !== false) {
                 $newName = str_replace($tag, $data, $result->getFileName());
                 $result->setFileName($newName);
                 unset($newName);
             }
             $result->declination = false;
             $moll->add($result);
         }
     }
     throw new Abort('cancel');
 }
Exemplo n.º 2
0
 /**
  * Lance l'éxécution de l'aspiration
  *
  * @return void
  * @throws
  */
 public function run()
 {
     if (empty($this->log)) {
         throw new Exception('Un logger est nécessaire');
     }
     $this->curl->setLogger($this->log);
     $this->execPlugin('init');
     do {
         $this->curContent = null;
         $this->curCmd = array_pop($this->plan);
         try {
             $this->execPlugin('before', $this->curCmd);
             $this->exec('CallPre', $this->curCmd);
         } catch (Abort $exc) {
             continue;
         }
         // Paramétrage curl
         $this->curl->setOpts($this->curCmd->getCurlOpts());
         // éxecution curl
         $this->curContent = $this->curl->exec($this->curCmd->getUrl());
         $this->exec('CallBack', $this->curCmd);
         $this->execPlugin('after', $this->curCmd);
         $this->exec('CallAfterPlug', $this->curCmd);
         $this->sleep($this->curCmd);
     } while (!empty($this->plan));
 }
Exemplo n.º 3
0
 /**
  * Paramétrage de Curl
  *
  * @throws Exception
  */
 public function testCurlConfig()
 {
     $this->given($command = new TestClass('toto'))->assert('Définition d\'une option curl')->array($command->getCurlOpts())->notHasKey(CURLOPT_VERBOSE)->object($command->setCurlOpt(CURLOPT_VERBOSE, true))->isIdenticalTo($command)->array($command->getCurlOpts())->boolean[CURLOPT_VERBOSE]->isTrue()->boolean($command->getCurlOpt(CURLOPT_VERBOSE))->isTrue()->assert('Réécriture d\'une option curl')->object($command->setCurlOpt(CURLOPT_VERBOSE, false))->isIdenticalTo($command)->array($command->getCurlOpts())->boolean[CURLOPT_VERBOSE]->isFalse()->boolean($command->getCurlOpt(CURLOPT_VERBOSE))->isFalse()->assert('Demande d\'information non présente')->exception(function () use($command) {
         $command->getCurlOpt(CURLOPT_BINARYTRANSFER);
     })->hasMessage('Aucun attribut curl du nom de __' . CURLOPT_BINARYTRANSFER . '__');
 }
Exemplo n.º 4
0
 /**
  * Temporisation
  *
  * @param Command $command Command courante
  */
 private function sleep(Command $command)
 {
     if ($command->getSleep() === false) {
         return;
     }
     $progress = null;
     foreach ($this->plugins as $plugin) {
         if (method_exists($plugin, 'getTickSleep')) {
             $progress = $plugin->getTickSleep();
             break;
         }
     }
     for ($i = $command->getSleep(); $i > 0; $i--) {
         if (is_callable($progress)) {
             $progress($i);
         }
         sleep(1);
     }
 }