Skip to content

Instantly share code, notes, and snippets.

@ismail1432
Last active July 2, 2022 23:38
Show Gist options
  • Save ismail1432/07b5352982e8198eb9c268d04ba1a056 to your computer and use it in GitHub Desktop.
Save ismail1432/07b5352982e8198eb9c268d04ba1a056 to your computer and use it in GitHub Desktop.
<?php
use Symfony\Component\Mime\{MimeTypes, FileBinaryMimeTypeGuesser};
class FileCreator
{
public function create(string $filePath): void
{
$mimeTypes = new MimeTypes();
// The last registered guesser has precedence over the other ones.
$mimesTypes->registerGuesser(new FileBinaryMimeTypeGuesser);
$mimeType = $mimeTypes->guessMimeType($filePath);
if (false === $this->supports($mimeType)) {
// throw error
}
// stuff
}
private function supports(?string $mimeType): bool
{
return 'application/pdf' === $mimeType;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment