コード例 #1
0
ファイル: functions.php プロジェクト: puzzlehttp/puzzle
 /**
  * Convenience method for sending multiple requests in parallel and
  * retrieving a hash map of requests to response objects or
  * RequestException objects.
  *
  * Note: This method keeps every request and response in memory, and as
  * such is NOT recommended when sending a large number or an indeterminable
  * number of requests in parallel.
  *
  * @param puzzle_ClientInterface $client   Client used to send the requests
  * @param array|Iterator $requests Requests to send in parallel
  * @param array           $options  Passes through the options available in
  *                                  {@see puzzle_ClientInterface::sendAll()}
  *
  * @return SplObjectStorage Requests are the key and each value is a
  *     {@see puzzle_message_ResponseInterface} if the request succeeded
  *     or a {@see puzzle_exception_RequestException} if it failed.
  * @throws InvalidArgumentException if the event format is incorrect.
  */
 function puzzle_batch(puzzle_ClientInterface $client, $requests, array $options = array())
 {
     global $__closure_puzzle_batch_hash;
     $__closure_puzzle_batch_hash = new puzzle_SplObjectStorage();
     foreach ($requests as $request) {
         $__closure_puzzle_batch_hash->offsetSet($request);
     }
     // Merge the necessary complete and error events to the event listeners
     // so that as each request succeeds or fails, it is added to the result
     // hash.
     $options = puzzle_event_RequestEvents::convertEventArray($options, array('complete', 'error'), array('priority' => puzzle_event_RequestEvents::EARLY, 'once' => true, 'fn' => '__callback_puzzle_batch_convertEvents'));
     // Send the requests in parallel and aggregate the results.
     $client->sendAll($requests, $options);
     // Update the received value for any of the intercepted requests.
     foreach ($__closure_puzzle_batch_hash as $request) {
         $storedEvent = $__closure_puzzle_batch_hash->offsetGet($request);
         if ($storedEvent instanceof puzzle_event_CompleteEvent) {
             $__closure_puzzle_batch_hash->offsetSet($request, $storedEvent->getResponse());
         } elseif ($storedEvent instanceof puzzle_event_ErrorEvent) {
             $__closure_puzzle_batch_hash->offsetSet($request, $storedEvent->getException());
         }
     }
     return $__closure_puzzle_batch_hash;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOption($keyOrPath, $value)
 {
     $this->_delegate->setDefaultOption($keyOrPath, $value);
 }