Example #1
0
 /**
  * Guesses the mimetype by the files extension ... or default
  * @param string $filename
  * @param string $default
  * @return string
  */
 public static function guessMimeType($filename, $default = 'application/octed-stream')
 {
     $guesser = new FileExtMimeTypeGuesser();
     $mime = $guesser->guess($filename);
     if (null === $mime) {
         try {
             $mime = MimeTypeGuesser::getInstance()->guess($filename);
         } catch (FileNotFoundException $ex) {
             // dont care
         }
     }
     return null === $mime ? $default : $mime;
 }
 public function testGetSet()
 {
     $mimes = ['foo' => 'application/x-foo', 'bar' => 'application/x-bar'];
     $guesser = new FileExtMimeTypeGuesser();
     $this->assertNotEquals($mimes, $guesser->getMimes());
     $this->assertNull($guesser->guess('bazz.bar'));
     $this->assertNull($guesser->guess('bazz.foo'));
     $guesser->setMimes($mimes);
     $this->assertEquals($mimes, $guesser->getMimes());
     $this->assertEquals($mimes['bar'], $guesser->guess('bazz.bar'));
     $this->assertEquals($mimes['foo'], $guesser->guess('bazz.foo'));
 }