예제 #1
0
 private function addContentType(RequestInterface $request, StreamInterface $body)
 {
     if (!($uri = $body->getMetadata('uri'))) {
         return;
     }
     // Guess the content-type based on the stream's "uri" metadata value.
     // The file extension is used to determine the appropriate mime-type.
     if ($contentType = Mimetypes::getInstance()->fromFilename($uri)) {
         $request->setHeader('Content-Type', $contentType);
     }
 }
예제 #2
0
 public function testReturnsNullWhenNoMatchFound()
 {
     $this->assertNull(Mimetypes::getInstance()->fromExtension('foobar'));
 }
예제 #3
0
 /**
  * Applies default Content-Disposition and Content-Type headers if needed.
  */
 private function prepareDefaultHeaders()
 {
     // Set a default content-disposition header if one was no provided
     if (!$this->hasHeader('Content-Disposition')) {
         $this->headers['Content-Disposition'] = sprintf('form-data; name="%s"; filename="%s"', $this->name, basename($this->filename));
     }
     // Set a default Content-Type if one was not supplied
     if (!$this->hasHeader('Content-Type')) {
         $this->headers['Content-Type'] = Mimetypes::getInstance()->fromFilename($this->filename) ?: 'text/plain';
     }
 }