/** * {@inheritDoc} */ public function supports(MediaInterface $media) { if (!$media instanceof LocalFile) { return false; } $matchExt = false; foreach ($this->extensions as $extension) { if (fnmatch($extension, $media->getFileExtension())) { $matchExt = true; } } $matchMimeType = false; foreach ($this->mimeTypes as $mimeType) { if (fnmatch($mimeType, $media->getMimeType())) { $matchMimeType = true; } } return $media->getFileExtension() == '' ? $matchMimeType === true : ($matchExt && $matchMimeType) === true; }
/** * Transfer the file to another adapter * * Note that you will receive a different file object depending on whether you're sending to a * local or remote file adapter. This will not be the same file object you passed in. You will * have 2 independent objects. * * @param MediaInterface $file The file * @param GaufretteAdapterInterface $adapter A gaufrette adapter * @param string $key File key (name) used in place of the file being transferred. Useful for overriding the default * @return LocalFileInterface|RemoteFileInterface The file object returned depends on the type of gaufrette adapter you're transferring to. * @throws UnknownTransferAdapterException When adapter is not a local or remote adapter */ public function transfer(MediaInterface $file, GaufretteAdapterInterface $adapter, $key = null) { if ($adapter instanceof LocalFileAdapterInterface) { $local = new LocalFile($key ?: $file->getKey(), $adapter); $local->write($file->read()); $local = $this->convertFile($local); return $local; } elseif ($adapter instanceof RemoteFileAdapterInterface) { $remote = new RemoteFile($key ?: $file->getKey(), $adapter); $remote->write($file->read()); return $remote; } else { throw new UnknownTransferAdapterException('Adapter must be a local or remote file adapter to transfer to.'); } }