/** * 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'); }
/** * 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)); }
/** * Création simple d'une Commande * * @return void */ public function testConstruct() { $this->object(new TestClass())->assert('Spécification à postériori de l\'url')->given($command = new TestClass())->variable($command->getUrl())->isNull()->assert('Spécification directe de l\'url')->given($command = new TestClass('toto'))->string($command->getUrl())->isEqualTo('toto'); }