/** * Set the file that this plugin is working on. This automatically extracts * the mime type. It will automatically load configuration if configuration * has not been loaded already * * @param string $fullPathToFileOnDisk e.g. /tmp/foo.png * * @throws FileNotFoundException If file $fullPathToFileOnDisk not found */ public function setFile($fullPathToFileOnDisk) { if (!file_exists($fullPathToFileOnDisk)) { throw new FileNotFoundException("{$fullPathToFileOnDisk} not found or not accessible"); } $this->fullPathToFileOnDisk = $fullPathToFileOnDisk; $this->mimeTypeOfCurrentFile = \BoxUK\Describr\Helper\FileHelper::getMimeType($this->fullPathToFileOnDisk); }
/** * Describe a file using all the relevant plugins that report they match * the mime type of the file at $fullPathToFileOnDisk * * @param string $fullPathToFileOnDisk e.g. /tmp/foo.png * * @return MediaFileAttributes The information found out about the file at $fullPathToFileOnDisk * * @throws \BoxUK\Describr\FileNotFoundException If the file at $fullPathToFileOnDisk is not * readable */ public function describeFile($fullPathToFileOnDisk) { if (!is_file($fullPathToFileOnDisk)) { throw new FileNotFoundException("File '{$fullPathToFileOnDisk}' not found or not accessible"); } // ascertain MIME type so we can check what plugins to use $mimeType = \BoxUK\Describr\Helper\FileHelper::getMimeType($fullPathToFileOnDisk); $extension = \BoxUK\Describr\Helper\FileHelper::getFileExtension($fullPathToFileOnDisk); $mediaFileAttributes = new MediaFileAttributes(); foreach ($this->availablePlugins as $pluginName) { /* @var $plugin plugins\Plugin */ $plugin = new $pluginName(); if ($plugin->supportsFile($mimeType, $extension)) { $plugin->setFile($fullPathToFileOnDisk); $mediaFileAttributes->setPluginResults($pluginName, $plugin->getAttributes()); } } return $mediaFileAttributes; }