Example #1
0
 /**
  * Read data from the request body and send it to curl
  *
  * @param resource $ch     Curl handle
  * @param resource $fd     File descriptor
  * @param int      $length Amount of data to read
  *
  * @return string
  */
 public function readRequestBody($ch, $fd, $length)
 {
     if (!($body = $this->request->getBody())) {
         return '';
     }
     $read = (string) $body->read($length);
     if ($this->emitIo) {
         $this->request->dispatch('curl.callback.read', array('request' => $this->request, 'read' => $read));
     }
     return $read;
 }
Example #2
0
 /**
  * {@inheritdoc}
  *
  * The $params array can contain the following custom keys specific to the PhpStreamRequestFactory:
  * - stream_class: The name of a class to create instead of a Guzzle\Stream\Stream object
  */
 public function fromRequest(RequestInterface $request, $context = array(), array $params = array())
 {
     if (is_resource($context)) {
         $this->contextOptions = stream_context_get_options($context);
         $this->context = $context;
     } elseif (is_array($context) || !$context) {
         $this->contextOptions = $context;
         $this->createContext($params);
     } elseif ($context) {
         throw new InvalidArgumentException('$context must be an array or resource');
     }
     // Dispatch the before send event
     $request->dispatch('request.before_send', array('request' => $request, 'context' => $this->context, 'context_options' => $this->contextOptions));
     $this->setUrl($request);
     $this->addDefaultContextOptions($request);
     $this->addSslOptions($request);
     $this->addBodyOptions($request);
     $this->addProxyOptions($request);
     // Create the file handle but silence errors
     return $this->createStream($params)->setCustomData('request', $request)->setCustomData('response_headers', $this->getLastResponseHeaders());
 }