Merge pull request #7453 from owncloud/preview-fileinfo

Cache the fileinfo in OC\Preview
This commit is contained in:
Vincent Petry 2014-03-03 18:52:25 +01:00
commit ad195a881e
1 changed files with 126 additions and 115 deletions

View File

@ -52,6 +52,11 @@ class Preview {
static private $providers = array(); static private $providers = array();
static private $registeredProviders = array(); static private $registeredProviders = array();
/**
* @var \OCP\Files\FileInfo
*/
protected $info;
/** /**
* @brief check if thumbnail or bigger version of thumbnail of file is cached * @brief check if thumbnail or bigger version of thumbnail of file is cached
* @param string $user userid - if no user is given, OC_User::getUser will be used * @param string $user userid - if no user is given, OC_User::getUser will be used
@ -61,12 +66,12 @@ class Preview {
* @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
* @param bool $scalingUp Disable/Enable upscaling of previews * @param bool $scalingUp Disable/Enable upscaling of previews
* @return mixed (bool / string) * @return mixed (bool / string)
* false if thumbnail does not exist * false if thumbnail does not exist
* path to thumbnail if thumbnail exists * path to thumbnail if thumbnail exists
*/ */
public function __construct($user='', $root='/', $file='', $maxX=1, $maxY=1, $scalingUp=true) { public function __construct($user = '', $root = '/', $file = '', $maxX = 1, $maxY = 1, $scalingUp = true) {
//init fileviews //init fileviews
if($user === ''){ if ($user === '') {
$user = \OC_User::getUser(); $user = \OC_User::getUser();
} }
$this->fileView = new \OC\Files\View('/' . $user . '/' . $root); $this->fileView = new \OC\Files\View('/' . $user . '/' . $root);
@ -86,11 +91,11 @@ class Preview {
$this->preview = null; $this->preview = null;
//check if there are preview backends //check if there are preview backends
if(empty(self::$providers)) { if (empty(self::$providers)) {
self::initProviders(); self::initProviders();
} }
if(empty(self::$providers)) { if (empty(self::$providers)) {
\OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR); \OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR);
throw new \Exception('No preview providers'); throw new \Exception('No preview providers');
} }
@ -99,15 +104,15 @@ class Preview {
/** /**
* @brief returns the path of the file you want a thumbnail from * @brief returns the path of the file you want a thumbnail from
* @return string * @return string
*/ */
public function getFile() { public function getFile() {
return $this->file; return $this->file;
} }
/** /**
* @brief returns the max width of the preview * @brief returns the max width of the preview
* @return integer * @return integer
*/ */
public function getMaxX() { public function getMaxX() {
return $this->maxX; return $this->maxX;
} }
@ -115,7 +120,7 @@ class Preview {
/** /**
* @brief returns the max height of the preview * @brief returns the max height of the preview
* @return integer * @return integer
*/ */
public function getMaxY() { public function getMaxY() {
return $this->maxY; return $this->maxY;
} }
@ -123,7 +128,7 @@ class Preview {
/** /**
* @brief returns whether or not scalingup is enabled * @brief returns whether or not scalingup is enabled
* @return bool * @return bool
*/ */
public function getScalingUp() { public function getScalingUp() {
return $this->scalingup; return $this->scalingup;
} }
@ -131,7 +136,7 @@ class Preview {
/** /**
* @brief returns the name of the thumbnailfolder * @brief returns the name of the thumbnailfolder
* @return string * @return string
*/ */
public function getThumbnailsFolder() { public function getThumbnailsFolder() {
return self::THUMBNAILS_FOLDER; return self::THUMBNAILS_FOLDER;
} }
@ -139,7 +144,7 @@ class Preview {
/** /**
* @brief returns the max scale factor * @brief returns the max scale factor
* @return string * @return string
*/ */
public function getMaxScaleFactor() { public function getMaxScaleFactor() {
return $this->maxScaleFactor; return $this->maxScaleFactor;
} }
@ -147,7 +152,7 @@ class Preview {
/** /**
* @brief returns the max width set in ownCloud's config * @brief returns the max width set in ownCloud's config
* @return string * @return string
*/ */
public function getConfigMaxX() { public function getConfigMaxX() {
return $this->configMaxX; return $this->configMaxX;
} }
@ -155,20 +160,28 @@ class Preview {
/** /**
* @brief returns the max height set in ownCloud's config * @brief returns the max height set in ownCloud's config
* @return string * @return string
*/ */
public function getConfigMaxY() { public function getConfigMaxY() {
return $this->configMaxY; return $this->configMaxY;
} }
protected function getFileInfo() {
if (!$this->info) {
$this->info = $this->fileView->getFileInfo($this->file);
}
return $this->info;
}
/** /**
* @brief set the path of the file you want a thumbnail from * @brief set the path of the file you want a thumbnail from
* @param string $file * @param string $file
* @return $this * @return $this
*/ */
public function setFile($file) { public function setFile($file) {
$this->file = $file; $this->file = $file;
$this->info = null;
if ($file !== '') { if ($file !== '') {
$this->mimetype = $this->fileView->getMimeType($this->file); $this->mimetype = $this->getFileInfo()->getMimetype();
} }
return $this; return $this;
} }
@ -185,14 +198,14 @@ class Preview {
* @brief set the the max width of the preview * @brief set the the max width of the preview
* @param int $maxX * @param int $maxX
* @return $this * @return $this
*/ */
public function setMaxX($maxX=1) { public function setMaxX($maxX = 1) {
if($maxX <= 0) { if ($maxX <= 0) {
throw new \Exception('Cannot set width of 0 or smaller!'); throw new \Exception('Cannot set width of 0 or smaller!');
} }
$configMaxX = $this->getConfigMaxX(); $configMaxX = $this->getConfigMaxX();
if(!is_null($configMaxX)) { if (!is_null($configMaxX)) {
if($maxX > $configMaxX) { if ($maxX > $configMaxX) {
\OC_Log::write('core', 'maxX reduced from ' . $maxX . ' to ' . $configMaxX, \OC_Log::DEBUG); \OC_Log::write('core', 'maxX reduced from ' . $maxX . ' to ' . $configMaxX, \OC_Log::DEBUG);
$maxX = $configMaxX; $maxX = $configMaxX;
} }
@ -205,14 +218,14 @@ class Preview {
* @brief set the the max height of the preview * @brief set the the max height of the preview
* @param int $maxY * @param int $maxY
* @return $this * @return $this
*/ */
public function setMaxY($maxY=1) { public function setMaxY($maxY = 1) {
if($maxY <= 0) { if ($maxY <= 0) {
throw new \Exception('Cannot set height of 0 or smaller!'); throw new \Exception('Cannot set height of 0 or smaller!');
} }
$configMaxY = $this->getConfigMaxY(); $configMaxY = $this->getConfigMaxY();
if(!is_null($configMaxY)) { if (!is_null($configMaxY)) {
if($maxY > $configMaxY) { if ($maxY > $configMaxY) {
\OC_Log::write('core', 'maxX reduced from ' . $maxY . ' to ' . $configMaxY, \OC_Log::DEBUG); \OC_Log::write('core', 'maxX reduced from ' . $maxY . ' to ' . $configMaxY, \OC_Log::DEBUG);
$maxY = $configMaxY; $maxY = $configMaxY;
} }
@ -225,9 +238,9 @@ class Preview {
* @brief set whether or not scalingup is enabled * @brief set whether or not scalingup is enabled
* @param bool $scalingUp * @param bool $scalingUp
* @return $this * @return $this
*/ */
public function setScalingup($scalingUp) { public function setScalingup($scalingUp) {
if($this->getMaxScaleFactor() === 1) { if ($this->getMaxScaleFactor() === 1) {
$scalingUp = false; $scalingUp = false;
} }
$this->scalingup = $scalingUp; $this->scalingup = $scalingUp;
@ -237,15 +250,15 @@ class Preview {
/** /**
* @brief check if all parameters are valid * @brief check if all parameters are valid
* @return bool * @return bool
*/ */
public function isFileValid() { public function isFileValid() {
$file = $this->getFile(); $file = $this->getFile();
if($file === '') { if ($file === '') {
\OC_Log::write('core', 'No filename passed', \OC_Log::DEBUG); \OC_Log::write('core', 'No filename passed', \OC_Log::DEBUG);
return false; return false;
} }
if(!$this->fileView->file_exists($file)) { if (!$this->fileView->file_exists($file)) {
\OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::DEBUG); \OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::DEBUG);
return false; return false;
} }
@ -256,40 +269,38 @@ class Preview {
/** /**
* @brief deletes previews of a file with specific x and y * @brief deletes previews of a file with specific x and y
* @return bool * @return bool
*/ */
public function deletePreview() { public function deletePreview() {
$file = $this->getFile(); $file = $this->getFile();
$fileInfo = $this->fileView->getFileInfo($file); $fileInfo = $this->getFileInfo($file);
$fileId = $fileInfo['fileid']; $fileId = $fileInfo->getId();
$previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png'; $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png';
$this->userView->unlink($previewPath); return $this->userView->unlink($previewPath);
return !$this->userView->file_exists($previewPath);
} }
/** /**
* @brief deletes all previews of a file * @brief deletes all previews of a file
* @return bool * @return bool
*/ */
public function deleteAllPreviews() { public function deleteAllPreviews() {
$file = $this->getFile(); $file = $this->getFile();
$fileInfo = $this->fileView->getFileInfo($file); $fileInfo = $this->getFileInfo($file);
$fileId = $fileInfo['fileid']; $fileId = $fileInfo->getId();
$previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
$this->userView->deleteAll($previewPath); $this->userView->deleteAll($previewPath);
$this->userView->rmdir($previewPath); return $this->userView->rmdir($previewPath);
return !$this->userView->is_dir($previewPath);
} }
/** /**
* @brief check if thumbnail or bigger version of thumbnail of file is cached * @brief check if thumbnail or bigger version of thumbnail of file is cached
* @return mixed (bool / string) * @return mixed (bool / string)
* false if thumbnail does not exist * false if thumbnail does not exist
* path to thumbnail if thumbnail exists * path to thumbnail if thumbnail exists
*/ */
private function isCached() { private function isCached() {
$file = $this->getFile(); $file = $this->getFile();
$maxX = $this->getMaxX(); $maxX = $this->getMaxX();
@ -297,75 +308,75 @@ class Preview {
$scalingUp = $this->getScalingUp(); $scalingUp = $this->getScalingUp();
$maxScaleFactor = $this->getMaxScaleFactor(); $maxScaleFactor = $this->getMaxScaleFactor();
$fileInfo = $this->fileView->getFileInfo($file); $fileInfo = $this->getFileInfo($file);
$fileId = $fileInfo['fileid']; $fileId = $fileInfo->getId();
if(is_null($fileId)) { if (is_null($fileId)) {
return false; return false;
} }
$previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
if(!$this->userView->is_dir($previewPath)) { if (!$this->userView->is_dir($previewPath)) {
return false; return false;
} }
//does a preview with the wanted height and width already exist? //does a preview with the wanted height and width already exist?
if($this->userView->file_exists($previewPath . $maxX . '-' . $maxY . '.png')) { if ($this->userView->file_exists($previewPath . $maxX . '-' . $maxY . '.png')) {
return $previewPath . $maxX . '-' . $maxY . '.png'; return $previewPath . $maxX . '-' . $maxY . '.png';
} }
$wantedAspectRatio = (float) ($maxX / $maxY); $wantedAspectRatio = (float)($maxX / $maxY);
//array for usable cached thumbnails //array for usable cached thumbnails
$possibleThumbnails = array(); $possibleThumbnails = array();
$allThumbnails = $this->userView->getDirectoryContent($previewPath); $allThumbnails = $this->userView->getDirectoryContent($previewPath);
foreach($allThumbnails as $thumbnail) { foreach ($allThumbnails as $thumbnail) {
$name = rtrim($thumbnail['name'], '.png'); $name = rtrim($thumbnail['name'], '.png');
$size = explode('-', $name); $size = explode('-', $name);
$x = (int) $size[0]; $x = (int)$size[0];
$y = (int) $size[1]; $y = (int)$size[1];
$aspectRatio = (float) ($x / $y); $aspectRatio = (float)($x / $y);
if($aspectRatio !== $wantedAspectRatio) { if ($aspectRatio !== $wantedAspectRatio) {
continue; continue;
} }
if($x < $maxX || $y < $maxY) { if ($x < $maxX || $y < $maxY) {
if($scalingUp) { if ($scalingUp) {
$scalefactor = $maxX / $x; $scalefactor = $maxX / $x;
if($scalefactor > $maxScaleFactor) { if ($scalefactor > $maxScaleFactor) {
continue; continue;
} }
}else{ } else {
continue; continue;
} }
} }
$possibleThumbnails[$x] = $thumbnail['path']; $possibleThumbnails[$x] = $thumbnail['path'];
} }
if(count($possibleThumbnails) === 0) { if (count($possibleThumbnails) === 0) {
return false; return false;
} }
if(count($possibleThumbnails) === 1) { if (count($possibleThumbnails) === 1) {
return current($possibleThumbnails); return current($possibleThumbnails);
} }
ksort($possibleThumbnails); ksort($possibleThumbnails);
if(key(reset($possibleThumbnails)) > $maxX) { if (key(reset($possibleThumbnails)) > $maxX) {
return current(reset($possibleThumbnails)); return current(reset($possibleThumbnails));
} }
if(key(end($possibleThumbnails)) < $maxX) { if (key(end($possibleThumbnails)) < $maxX) {
return current(end($possibleThumbnails)); return current(end($possibleThumbnails));
} }
foreach($possibleThumbnails as $width => $path) { foreach ($possibleThumbnails as $width => $path) {
if($width < $maxX) { if ($width < $maxX) {
continue; continue;
}else{ } else {
return $path; return $path;
} }
} }
@ -374,9 +385,9 @@ class Preview {
/** /**
* @brief return a preview of a file * @brief return a preview of a file
* @return \OC_Image * @return \OC_Image
*/ */
public function getPreview() { public function getPreview() {
if(!is_null($this->preview) && $this->preview->valid()){ if (!is_null($this->preview) && $this->preview->valid()) {
return $this->preview; return $this->preview;
} }
@ -386,22 +397,22 @@ class Preview {
$maxY = $this->getMaxY(); $maxY = $this->getMaxY();
$scalingUp = $this->getScalingUp(); $scalingUp = $this->getScalingUp();
$fileInfo = $this->fileView->getFileInfo($file); $fileInfo = $this->getFileInfo($file);
$fileId = $fileInfo['fileid']; $fileId = $fileInfo->getId();
$cached = $this->isCached(); $cached = $this->isCached();
if($cached) { if ($cached) {
$image = new \OC_Image($this->userView->file_get_contents($cached, 'r')); $image = new \OC_Image($this->userView->file_get_contents($cached, 'r'));
$this->preview = $image->valid() ? $image : null; $this->preview = $image->valid() ? $image : null;
$this->resizeAndCrop(); $this->resizeAndCrop();
} }
if(is_null($this->preview)) { if (is_null($this->preview)) {
$preview = null; $preview = null;
foreach(self::$providers as $supportedMimetype => $provider) { foreach (self::$providers as $supportedMimetype => $provider) {
if(!preg_match($supportedMimetype, $this->mimetype)) { if (!preg_match($supportedMimetype, $this->mimetype)) {
continue; continue;
} }
@ -409,7 +420,7 @@ class Preview {
$preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingUp, $this->fileView); $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingUp, $this->fileView);
if(!($preview instanceof \OC_Image)) { if (!($preview instanceof \OC_Image)) {
continue; continue;
} }
@ -419,11 +430,11 @@ class Preview {
$previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
$cachePath = $previewPath . $maxX . '-' . $maxY . '.png'; $cachePath = $previewPath . $maxX . '-' . $maxY . '.png';
if($this->userView->is_dir($this->getThumbnailsFolder() . '/') === false) { if ($this->userView->is_dir($this->getThumbnailsFolder() . '/') === false) {
$this->userView->mkdir($this->getThumbnailsFolder() . '/'); $this->userView->mkdir($this->getThumbnailsFolder() . '/');
} }
if($this->userView->is_dir($previewPath) === false) { if ($this->userView->is_dir($previewPath) === false) {
$this->userView->mkdir($previewPath); $this->userView->mkdir($previewPath);
} }
@ -433,7 +444,7 @@ class Preview {
} }
} }
if(is_null($this->preview)) { if (is_null($this->preview)) {
$this->preview = new \OC_Image(); $this->preview = new \OC_Image();
} }
@ -443,10 +454,10 @@ class Preview {
/** /**
* @brief show preview * @brief show preview
* @return void * @return void
*/ */
public function showPreview() { public function showPreview() {
\OCP\Response::enableCaching(3600 * 24); // 24 hours \OCP\Response::enableCaching(3600 * 24); // 24 hours
if(is_null($this->preview)) { if (is_null($this->preview)) {
$this->getPreview(); $this->getPreview();
} }
$this->preview->show(); $this->preview->show();
@ -456,7 +467,7 @@ class Preview {
/** /**
* @brief show preview * @brief show preview
* @return void * @return void
*/ */
public function show() { public function show() {
$this->showPreview(); $this->showPreview();
return; return;
@ -465,7 +476,7 @@ class Preview {
/** /**
* @brief resize, crop and fix orientation * @brief resize, crop and fix orientation
* @return void * @return void
*/ */
private function resizeAndCrop() { private function resizeAndCrop() {
$image = $this->preview; $image = $this->preview;
$x = $this->getMaxX(); $x = $this->getMaxX();
@ -473,17 +484,17 @@ class Preview {
$scalingUp = $this->getScalingUp(); $scalingUp = $this->getScalingUp();
$maxscalefactor = $this->getMaxScaleFactor(); $maxscalefactor = $this->getMaxScaleFactor();
if(!($image instanceof \OC_Image)) { if (!($image instanceof \OC_Image)) {
\OC_Log::write('core', '$this->preview is not an instance of OC_Image', \OC_Log::DEBUG); \OC_Log::write('core', '$this->preview is not an instance of OC_Image', \OC_Log::DEBUG);
return; return;
} }
$image->fixOrientation(); $image->fixOrientation();
$realx = (int) $image->width(); $realx = (int)$image->width();
$realy = (int) $image->height(); $realy = (int)$image->height();
if($x === $realx && $y === $realy) { if ($x === $realx && $y === $realy) {
$this->preview = $image; $this->preview = $image;
return; return;
} }
@ -491,36 +502,36 @@ class Preview {
$factorX = $x / $realx; $factorX = $x / $realx;
$factorY = $y / $realy; $factorY = $y / $realy;
if($factorX >= $factorY) { if ($factorX >= $factorY) {
$factor = $factorX; $factor = $factorX;
}else{ } else {
$factor = $factorY; $factor = $factorY;
} }
if($scalingUp === false) { if ($scalingUp === false) {
if($factor > 1) { if ($factor > 1) {
$factor = 1; $factor = 1;
} }
} }
if(!is_null($maxscalefactor)) { if (!is_null($maxscalefactor)) {
if($factor > $maxscalefactor) { if ($factor > $maxscalefactor) {
\OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $maxscalefactor, \OC_Log::DEBUG); \OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $maxscalefactor, \OC_Log::DEBUG);
$factor = $maxscalefactor; $factor = $maxscalefactor;
} }
} }
$newXsize = (int) ($realx * $factor); $newXsize = (int)($realx * $factor);
$newYsize = (int) ($realy * $factor); $newYsize = (int)($realy * $factor);
$image->preciseResize($newXsize, $newYsize); $image->preciseResize($newXsize, $newYsize);
if($newXsize === $x && $newYsize === $y) { if ($newXsize === $x && $newYsize === $y) {
$this->preview = $image; $this->preview = $image;
return; return;
} }
if($newXsize >= $x && $newYsize >= $y) { if ($newXsize >= $x && $newYsize >= $y) {
$cropX = floor(abs($x - $newXsize) * 0.5); $cropX = floor(abs($x - $newXsize) * 0.5);
//don't crop previews on the Y axis, this sucks if it's a document. //don't crop previews on the Y axis, this sucks if it's a document.
//$cropY = floor(abs($y - $newYsize) * 0.5); //$cropY = floor(abs($y - $newYsize) * 0.5);
@ -532,19 +543,19 @@ class Preview {
return; return;
} }
if($newXsize < $x || $newYsize < $y) { if ($newXsize < $x || $newYsize < $y) {
if($newXsize > $x) { if ($newXsize > $x) {
$cropX = floor(($newXsize - $x) * 0.5); $cropX = floor(($newXsize - $x) * 0.5);
$image->crop($cropX, 0, $x, $newYsize); $image->crop($cropX, 0, $x, $newYsize);
} }
if($newYsize > $y) { if ($newYsize > $y) {
$cropY = floor(($newYsize - $y) * 0.5); $cropY = floor(($newYsize - $y) * 0.5);
$image->crop(0, $cropY, $newXsize, $y); $image->crop(0, $cropY, $newXsize, $y);
} }
$newXsize = (int) $image->width(); $newXsize = (int)$image->width();
$newYsize = (int) $image->height(); $newYsize = (int)$image->height();
//create transparent background layer //create transparent background layer
$backgroundlayer = imagecreatetruecolor($x, $y); $backgroundlayer = imagecreatetruecolor($x, $y);
@ -573,8 +584,8 @@ class Preview {
* @param array $options * @param array $options
* @return void * @return void
*/ */
public static function registerProvider($class, $options=array()) { public static function registerProvider($class, $options = array()) {
self::$registeredProviders[]=array('class'=>$class, 'options'=>$options); self::$registeredProviders[] = array('class' => $class, 'options' => $options);
} }
/** /**
@ -582,19 +593,19 @@ class Preview {
* @return void * @return void
*/ */
private static function initProviders() { private static function initProviders() {
if(!\OC_Config::getValue('enable_previews', true)) { if (!\OC_Config::getValue('enable_previews', true)) {
$provider = new Preview\Unknown(array()); $provider = new Preview\Unknown(array());
self::$providers = array($provider->getMimeType() => $provider); self::$providers = array($provider->getMimeType() => $provider);
return; return;
} }
if(count(self::$providers)>0) { if (count(self::$providers) > 0) {
return; return;
} }
foreach(self::$registeredProviders as $provider) { foreach (self::$registeredProviders as $provider) {
$class=$provider['class']; $class = $provider['class'];
$options=$provider['options']; $options = $provider['options'];
$object = new $class($options); $object = new $class($options);
@ -611,7 +622,7 @@ class Preview {
public static function post_delete($args) { public static function post_delete($args) {
$path = $args['path']; $path = $args['path'];
if(substr($path, 0, 1) === '/') { if (substr($path, 0, 1) === '/') {
$path = substr($path, 1); $path = substr($path, 1);
} }
$preview = new Preview(\OC_User::getUser(), 'files/', $path); $preview = new Preview(\OC_User::getUser(), 'files/', $path);
@ -622,19 +633,19 @@ class Preview {
* @param string $mimetype * @param string $mimetype
*/ */
public static function isMimeSupported($mimetype) { public static function isMimeSupported($mimetype) {
if(!\OC_Config::getValue('enable_previews', true)) { if (!\OC_Config::getValue('enable_previews', true)) {
return false; return false;
} }
//check if there are preview backends //check if there are preview backends
if(empty(self::$providers)) { if (empty(self::$providers)) {
self::initProviders(); self::initProviders();
} }
//remove last element because it has the mimetype * //remove last element because it has the mimetype *
$providers = array_slice(self::$providers, 0, -1); $providers = array_slice(self::$providers, 0, -1);
foreach($providers as $supportedMimetype => $provider) { foreach ($providers as $supportedMimetype => $provider) {
if(preg_match($supportedMimetype, $mimetype)) { if (preg_match($supportedMimetype, $mimetype)) {
return true; return true;
} }
} }