|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the `liip/LiipImagineBundle` project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Liip\ImagineBundle\Binary; |
|
13
|
|
|
|
|
14
|
|
|
use Liip\ImagineBundle\Exception\InvalidArgumentException; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface as DeprecatedSymfonyMimeTypeGuesserInterface; |
|
16
|
|
|
use Symfony\Component\Mime\MimeTypesInterface as SymfonyMimeTypeGuesserInterface; |
|
17
|
|
|
|
|
18
|
|
|
class SimpleMimeTypeGuesser implements MimeTypeGuesserInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var DeprecatedSymfonyMimeTypeGuesserInterface|SymfonyMimeTypeGuesserInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $mimeTypeGuesser; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param DeprecatedSymfonyMimeTypeGuesserInterface|SymfonyMimeTypeGuesserInterface $mimeTypeGuesser |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct($mimeTypeGuesser) |
|
29
|
|
|
{ |
|
30
|
|
|
if (!$mimeTypeGuesser instanceof SymfonyMimeTypeGuesserInterface && !$mimeTypeGuesser instanceof DeprecatedSymfonyMimeTypeGuesserInterface) { |
|
|
|
|
|
|
31
|
|
|
throw new InvalidArgumentException('$mimeTypeGuesser must be an instance of Symfony\Component\Mime\MimeTypeGuesserInterface or Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (interface_exists((SymfonyMimeTypeGuesserInterface::class) && $mimeTypeGuesser instanceof DeprecatedSymfonyMimeTypeGuesserInterface)) { |
|
|
|
|
|
|
35
|
|
|
@trigger_error(sprintf('Passing a %s to "%s()" is deprecated since Symfony 4.3, pass a "%s" instead.', DeprecatedSymfonyMimeTypeGuesserInterface::class, __METHOD__, SymfonyMimeTypeGuesserInterface::class), E_USER_DEPRECATED); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$this->mimeTypeGuesser = $mimeTypeGuesser; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
public function guess($binary) |
|
45
|
|
|
{ |
|
46
|
|
|
if (false === $tmpFile = tempnam(sys_get_temp_dir(), 'liip-imagine-bundle')) { |
|
47
|
|
|
throw new \RuntimeException(sprintf('Temp file can not be created in "%s".', sys_get_temp_dir())); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
try { |
|
51
|
|
|
file_put_contents($tmpFile, $binary); |
|
52
|
|
|
|
|
53
|
|
|
$mimeType = interface_exists(SymfonyMimeTypeGuesserInterface::class) ? $this->mimeTypeGuesser->guessMimeType($tmpFile) : $this->mimeTypeGuesser->guess($tmpFile); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
unlink($tmpFile); |
|
56
|
|
|
|
|
57
|
|
|
return $mimeType; |
|
58
|
|
|
} catch (\Exception $e) { |
|
59
|
|
|
unlink($tmpFile); |
|
60
|
|
|
|
|
61
|
|
|
throw $e; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.