-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set DefaultMetadataReader when ext-exif is not present
This fixes the issue where an exif reader is used, but ext-exif is not loaded. Closes: #501
- Loading branch information
1 parent
1eac259
commit 764a1b6
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
DependencyInjection/Compiler/MetadataReaderCompilerPass.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `liip/LiipImagineBundle` project. | ||
* | ||
* (c) /~https://github.com/liip/LiipImagineBundle/graphs/contributors | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Liip\ImagineBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* By default, a metadata reader based on the exif php extension is used. | ||
* This compiler pass checks if the extension is loaded an switches to a simpler | ||
* implementation if not. | ||
*/ | ||
class MetadataReaderCompilerPass implements CompilerPassInterface | ||
{ | ||
const METADATA_READER_PARAM = 'liip_imagine.meta_data.reader.class'; | ||
|
||
const DEFAULT_METADATA_READER_CLASS = 'Imagine\Image\Metadata\DefaultMetadataReader'; | ||
|
||
const EXIF_METADATA_READER_CLASS = 'Imagine\Image\Metadata\ExifMetadataReader'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!extension_loaded('exif') && $this->isDefaultMetadataReader($container)) { | ||
$container->setParameter(self::METADATA_READER_PARAM, self::DEFAULT_METADATA_READER_CLASS); | ||
$this->logMetadataReaderReplaced($container); | ||
} | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
* | ||
* @return bool | ||
*/ | ||
protected function isDefaultMetadataReader(ContainerBuilder $container) | ||
{ | ||
$currentMetadataReaderParameter = $container->getParameter(self::METADATA_READER_PARAM); | ||
|
||
return $currentMetadataReaderParameter === self::EXIF_METADATA_READER_CLASS; | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
*/ | ||
protected function logMetadataReaderReplaced(ContainerBuilder $container) | ||
{ | ||
$compiler = $container->getCompiler(); | ||
$formatter = $compiler->getLoggingFormatter(); | ||
$message = 'Automatically replaced Imagine ExifMetadataReader with DefaultMetadataReader; '. | ||
'you might experience issues with LiipImagineBundle; reason: PHP extension "exif" is missing; solution: '. | ||
'for advanced metadata extraction install the PHP extension "exif" or set a custom MetadataReader '. | ||
'through the "liip_imagine.meta_data.reader.class" parameter'; | ||
|
||
$compiler->addLogMessage($formatter->format($this, $message)); | ||
} | ||
} |
This file contains 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
This file contains 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