Last active
July 2, 2022 23:38
-
-
Save ismail1432/07b5352982e8198eb9c268d04ba1a056 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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