Exemple #1
0
 /**
  * Calculates length of the request body, adds proper headers
  *
  * @param array &$headers associative array of request headers, this method
  *                        will add proper 'Content-Length' and 'Content-Type'
  *                        headers to this array (or remove them if not needed)
  */
 protected function calculateRequestLength(&$headers)
 {
     $this->requestBody = $this->request->getBody();
     if (is_string($this->requestBody)) {
         $this->contentLength = strlen($this->requestBody);
     } elseif (is_resource($this->requestBody)) {
         $stat = fstat($this->requestBody);
         $this->contentLength = $stat['size'];
         rewind($this->requestBody);
     } else {
         $this->contentLength = $this->requestBody->getLength();
         $headers['content-type'] = 'multipart/form-data; boundary=' . $this->requestBody->getBoundary();
         $this->requestBody->rewind();
     }
     if (in_array($this->request->getMethod(), self::$bodyDisallowed) || 0 == $this->contentLength) {
         // No body: send a Content-Length header nonetheless (request #12900),
         // but do that only for methods that require a body (bug #14740)
         if (in_array($this->request->getMethod(), self::$bodyRequired)) {
             $headers['content-length'] = 0;
         } else {
             unset($headers['content-length']);
             // if the method doesn't require a body and doesn't have a
             // body, don't send a Content-Type header. (request #16799)
             unset($headers['content-type']);
         }
     } else {
         if (empty($headers['content-type'])) {
             $headers['content-type'] = 'application/x-www-form-urlencoded';
         }
         // Content-Length should not be sent for chunked Transfer-Encoding (bug #20125)
         if (!isset($headers['transfer-encoding'])) {
             $headers['content-length'] = $this->contentLength;
         }
     }
 }
 /**
  * Method used to retrieve the previous row from a query result
  *
  * @param   string             Whether or not the result should be returned as an array
  * @return  mixed              An array or an object with the result of the previous query result
  * @access  public
  */
 public function previous_row($array = '')
 {
     $info = $this->_result->info();
     $this->_result->rewind();
     // Check that the cursor has started iterating
     if (isset($info['at'])) {
         // Move the cursor to the required position
         for ($i = 1; $i < $info['at'] - 1; $i++) {
             $this->_result->next();
         }
     }
     $result = $this->_get_result();
     return $this->_cast_result($array, $result);
 }
Exemple #3
0
 /**
  * Creates a stream.
  *
  * @param null|resource|string|\Psr\Http\Message\StreamInterface|null $body The body
  *
  * @return \Psr\Http\Message\StreamInterface The stream
  */
 private function doCreateStream($body)
 {
     if ($body instanceof StreamInterface) {
         $body->rewind();
         return $body;
     }
     if (is_resource($body)) {
         return $this->doCreateStream(new Stream($body));
     }
     $stream = new Stream('php://memory', 'rw');
     if ($body === null) {
         return $stream;
     }
     $stream->write((string) $body);
     return $this->doCreateStream($stream);
 }
 /**
  * remove host from hosts file.
  *
  * @param string The $host to be removed to the hosts file
  *
  * @throws RuntimeException if host does not exists or cant write to file
  *
  * @return bool
  **/
 public function remove($host)
 {
     $this->validHost($host);
     if (!$this->check($host)) {
         throw new \RuntimeException('Host does not exists in the file');
     }
     $this->backup();
     $tmpFilePath = $this->filepath . '.tmp';
     $tmpFile = new \SplFileObject($tmpFilePath, 'w+');
     $this->file->rewind();
     while (!$this->file->eof()) {
         $pattern = '/\\b' . $host . '\\b/i';
         if (!preg_match($pattern, $this->file->current())) {
             $tmpFile->fwrite($this->file->current());
         }
         $this->file->next();
     }
     copy($tmpFilePath, $this->filepath);
     unlink($tmpFilePath);
     return true;
 }
Exemple #5
0
 /**
  * Calculates length of the request body, adds proper headers
  *
  * @param    array   associative array of request headers, this method will 
  *                   add proper 'Content-Length' and 'Content-Type' headers 
  *                   to this array (or remove them if not needed)
  */
 protected function calculateRequestLength(&$headers)
 {
     $this->requestBody = $this->request->getBody();
     if (is_string($this->requestBody)) {
         $this->contentLength = strlen($this->requestBody);
     } elseif (is_resource($this->requestBody)) {
         $stat = fstat($this->requestBody);
         $this->contentLength = $stat['size'];
         rewind($this->requestBody);
     } else {
         $this->contentLength = $this->requestBody->getLength();
         $headers['content-type'] = 'multipart/form-data; boundary=' . $this->requestBody->getBoundary();
         $this->requestBody->rewind();
     }
     if (in_array($this->request->getMethod(), self::$bodyDisallowed) || 0 == $this->contentLength) {
         unset($headers['content-type']);
         // No body: send a Content-Length header nonetheless (request #12900),
         // but do that only for methods that require a body (bug #14740)
         if (in_array($this->request->getMethod(), self::$bodyRequired)) {
             $headers['content-length'] = 0;
         } else {
             unset($headers['content-length']);
         }
     } else {
         if (empty($headers['content-type'])) {
             $headers['content-type'] = 'application/x-www-form-urlencoded';
         }
         $headers['content-length'] = $this->contentLength;
     }
 }
 /**
  * Initializes the reader to read from locale $locale.
  *
  * Opens the translation file.
  *
  * @throws ezcTranslationNotConfiguredException if the option <i>format</i>
  *         is not set before this method is called.
  *
  * @param string $locale
  * @return void
  */
 public function initReader($locale)
 {
     $this->xmlParser = $this->openTranslationFile($locale, 'SimpleXMLIterator');
     $this->xmlParser->rewind();
 }