Example #1
0
 /**
  * Get a singleton instance of the class
  *
  * @return self
  * @codeCoverageIgnore
  */
 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #2
0
 private function addContentType(puzzle_message_RequestInterface $request, puzzle_stream_StreamInterface $body)
 {
     if (!$body instanceof puzzle_stream_MetadataStreamInterface) {
         return;
     }
     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 = puzzle_Mimetypes::getInstance()->fromFilename($uri)) {
         $request->setHeader('Content-Type', $contentType);
     }
 }
Example #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'] = puzzle_Mimetypes::getInstance()->fromFilename($this->filename) ? puzzle_Mimetypes::getInstance()->fromFilename($this->filename) : 'text/plain';
     }
 }
Example #4
0
 public function testReturnsNullWhenNoMatchFound()
 {
     $this->assertNull(puzzle_Mimetypes::getInstance()->fromExtension('foobar'));
 }