Imbo\Database\MongoDB::getImageMimeType PHP Method

getImageMimeType() public method

public getImageMimeType ( $user, $imageIdentifier )
    public function getImageMimeType($user, $imageIdentifier)
    {
        try {
            $data = $this->getImageCollection()->findOne(['user' => $user, 'imageIdentifier' => $imageIdentifier]);
        } catch (MongoException $e) {
            throw new DatabaseException('Unable to fetch image meta data', 500, $e);
        }
        if ($data === null) {
            throw new DatabaseException('Image not found', 404);
        }
        return $data['mime'];
    }

Usage Example

Beispiel #1
0
 /**
  * @covers Imbo\Database\MongoDB::getImageMimeType
  * @expectedException Imbo\Exception\DatabaseException
  * @expectedExceptionMessage Unable to fetch image meta data
  * @expectedExceptionCode 500
  */
 public function testThrowsExceptionWhenMongoFailsDuringGetImageMimeType()
 {
     $this->imageCollection->expects($this->once())->method('findOne')->will($this->throwException(new MongoException()));
     $this->driver->getImageMimeType('key', 'identifier');
 }