-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuessTrait.php
44 lines (40 loc) · 1.01 KB
/
GuessTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Created by PhpStorm.
* User: gseidel
* Date: 27.08.17
* Time: 13:30
*/
namespace Enhavo\Bundle\MediaBundle\Factory;
use Symfony\Component\Mime\MimeTypes;
trait GuessTrait
{
/**
* Guess the mime type of a file.
*
* @param string $path Full file name including path and extension
* @return string|null Mime type of null if none found
*/
protected function guessMimeType($path)
{
$guesser = MimeTypes::getDefault();
return $guesser->guessMimeType($path);
}
/**
* Guess extension
*
* If the mime type is unknown, returns null.
*
* @param string $path
* @return string|null The guessed extension or null if it cannot be guessed
*/
protected function guessExtension($path)
{
$guesser = MimeTypes::getDefault();
$extensions = $guesser->getExtensions($this->guessMimeType($path));
if ($extensions && count($extensions)) {
return $extensions[0];
}
return null;
}
}