Пример #1
0
 /**
  * Sets the response content.
  *
  * If new content is set and a stream exists also reset the content in the stream.
  *
  * @param mixed  $content   The content
  * @param string $type      The content type
  * @throws \UnexpectedValueException If the content is not a string are cannot be casted to a string.
  * @return HttpMessage
  */
 public function setContent($content, $type = null)
 {
     //Refresh the buffer
     if ($this->__stream instanceof FilesystemStreamInterface) {
         $this->__stream->truncate(0);
         $this->__stream->write($content);
     }
     return parent::setContent($content, $type);
 }
Пример #2
0
 /**
  * Sets the response content
  *
  * The buffer:// stream wrapper will be used when setting content as a string. This wrapper allows to pass a
  * string directly to the response transport and send it to the client.
  *
  * @param mixed  $content   The content
  * @param string $type      The content type
  * @return HttpMessage
  */
 public function setContent($content, $type = null)
 {
     parent::setContent($content, $type);
     $stream = $this->getStream();
     if (!$stream->isRegistered('buffer')) {
         $stream->registerWrapper('lib:filesystem.stream.wrapper.buffer');
     }
     $stream->open('buffer://memory', 'w+b');
     $stream->write($content);
     return $this;
 }