示例#1
0
 /**
  * Find the mime type of the given stream
  *
  * @param FilesystemStreamInterface $stream
  * @return string The mime type or NULL, if none could be guessed
  */
 public function fromStream(FilesystemStreamInterface $stream)
 {
     $mimetype = null;
     if (static::isSupported()) {
         if ($path = $stream->getPath()) {
             $mimetype = $this->_getMimetype(strtolower(pathinfo($path, PATHINFO_EXTENSION)));
         }
     }
     return $mimetype;
 }
示例#2
0
 /**
  * Find the mime type of the given stream
  *
  * @param FilesystemStreamInterface $stream
  * @return string The mime type or NULL, if none could be guessed
  */
 public function fromStream(FilesystemStreamInterface $stream)
 {
     $mimetype = null;
     if (static::isSupported()) {
         if ($finfo = new \finfo(FILEINFO_MIME_TYPE, $this->getConfig()->magic_file)) {
             if ($path = $stream->getPath()) {
                 $mimetype = $finfo->file($path);
             } else {
                 $mimetype = $finfo->buffer($stream->toString());
             }
         }
     }
     return $mimetype;
 }
示例#3
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);
 }
示例#4
0
 /**
  * Find the mime type of the given stream
  *
  * @param FilesystemStreamInterface $stream
  * @throws \RuntimeException If the stream is not readable
  * @return string The mime type or NULL, if none could be guessed
  */
 public function fromStream(FilesystemStreamInterface $stream)
 {
     if (!$stream->isReadable()) {
         throw new \RuntimeException('Stream not readable');
     }
     $mimetype = null;
     foreach (array_reverse($this->__resolvers) as $name => $resolver) {
         //Lazy create the resolver
         if (!$resolver instanceof FilesystemMimetypeInterface) {
             $resolver = $this->getObject($resolver);
             if (!$resolver instanceof FilesystemMimetypeInterface) {
                 throw new \UnexpectedValueException('Resolver does not implement FilesystemMimetypeInterface');
             }
             $this->__resolvers[$name] = $resolver;
         }
         /* @var $resolver FilesystemMimetypeInterface */
         if (null !== ($mimetype = $resolver->fromStream($stream))) {
             break;
         }
     }
     return $mimetype;
 }