Exemplo n.º 1
0
 /**
  * @param string $category
  * @param Article $article
  */
 public function modules($category, $article)
 {
     $modules = $this->config->getModules($category);
     foreach ($modules as $module) {
         $obj = new $module($this->config());
         $obj->run($article);
     }
 }
Exemplo n.º 2
-1
 /**
  * @param string[] $imageSrcs
  * @param bool $returnAll
  * @param Configuration $config
  *
  * @return object[]|null
  */
 private static function handleEntity($imageSrcs, $returnAll, $config)
 {
     $guzzle = new \GuzzleHttp\Client();
     $results = [];
     $requests = function ($urls) use($guzzle, $config, &$results) {
         foreach ($urls as $key => $url) {
             $file = tempnam(sys_get_temp_dir(), 'goose');
             $results[] = (object) ['url' => $url, 'file' => $file];
             (yield $key => function ($options) use($guzzle, $url, $file) {
                 $options['sink'] = $file;
                 return $guzzle->sendAsync(new \GuzzleHttp\Psr7\Request('GET', $url), $options);
             });
         }
     };
     $pool = new \GuzzleHttp\Pool($guzzle, $requests($imageSrcs), ['concurrency' => 25, 'fulfilled' => function ($response, $index) use(&$results, $returnAll) {
         if (!$returnAll && $response->getStatusCode() != 200) {
             unset($results[$index]);
         }
     }, 'rejected' => function ($reason, $index) use(&$results, $returnAll) {
         if ($returnAll) {
             $results[$index]->file = null;
         } else {
             unset($results[$index]);
         }
     }, 'options' => $config->get('browser')]);
     $pool->promise()->wait();
     if (empty($results)) {
         return null;
     }
     return $results;
 }