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\DependencyInjection\Compiler; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Be default, a metadata reader that requires the "exif" PHP extension is used. This compiler pass checks if the |
18
|
|
|
* extension is loaded or not, and switches to a metadata reader (that does not rely on "exif") if not. |
19
|
|
|
*/ |
20
|
|
|
class MetadataReaderCompilerPass extends AbstractCompilerPass |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private static $metadataReaderParameter = 'liip_imagine.meta_data.reader.class'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private static $metadataReaderDefaultClass = 'Imagine\Image\Metadata\DefaultMetadataReader'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private static $metadataReaderExifClass = 'Imagine\Image\Metadata\ExifMetadataReader'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function process(ContainerBuilder $container) |
41
|
|
|
{ |
42
|
|
|
if (!$this->isExifExtensionLoaded() && $this->isExifMetadataReaderSet($container)) { |
43
|
|
|
$container->setParameter(self::$metadataReaderParameter, self::$metadataReaderDefaultClass); |
44
|
|
|
$message = 'Overwrote "%s" parameter value from "%s" to "%s" due to missing "exif" extension ' |
45
|
|
|
.'(installing the "exif" extension is highly recommended; you may experience degraded ' |
46
|
|
|
.'metadata handling without it)'; |
47
|
|
|
$this->log($container, $message, array( |
48
|
|
|
self::$metadataReaderParameter, |
49
|
|
|
self::$metadataReaderExifClass, |
50
|
|
|
self::$metadataReaderDefaultClass, |
51
|
|
|
)); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param ContainerBuilder $container |
57
|
|
|
* |
58
|
|
|
* @return bool |
59
|
|
|
*/ |
60
|
|
|
private function isExifMetadataReaderSet(ContainerBuilder $container) |
61
|
|
|
{ |
62
|
|
|
return $container->getParameter(self::$metadataReaderParameter) === self::$metadataReaderExifClass; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
|
|
protected function isExifExtensionLoaded() |
69
|
|
|
{ |
70
|
|
|
return extension_loaded('exif'); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|