Skip to content

Commit

Permalink
Set DefaultMetadataReader when ext-exif is not present
Browse files Browse the repository at this point in the history
This fixes the issue where an exif reader is used, but ext-exif
is not loaded.

Closes: #501
  • Loading branch information
cedricziel committed Jan 3, 2017
1 parent 1eac259 commit 055ada8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
33 changes: 33 additions & 0 deletions DependencyInjection/Compiler/MetadataReaderCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!extension_loaded('exif')) {
$container->setParameter('liip_imagine.meta_data.reader.class', 'Imagine\Image\Metadata\DefaultMetadataReader');
}
}
}
2 changes: 2 additions & 0 deletions LiipImagineBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Liip\ImagineBundle\DependencyInjection\Compiler\FiltersCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\LoadersCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\MetadataReaderCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\PostProcessorsCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Compiler\ResolversCompilerPass;
use Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory;
Expand All @@ -38,6 +39,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new FiltersCompilerPass());
$container->addCompilerPass(new PostProcessorsCompilerPass());
$container->addCompilerPass(new ResolversCompilerPass());
$container->addCompilerPass(new MetadataReaderCompilerPass());

/** @var $extension LiipImagineExtension */
$extension = $container->getExtension('liip_imagine');
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"suggest": {
"amazonwebservices/aws-sdk-for-php": "Required to use AWS version 1 cache resolver.",
"aws/aws-sdk-php": "Required to use AWS version 2/3 cache resolver.",
"ext-exif": "Required to read metadata from Exif information",
"league/flysystem": "Required to use FlySystem data loader or cache resolver.",
"monolog/monolog": "A psr/log compatible logger is required to enable logging.",
"twig/twig": "Required to use the provided Twig extension. Version 1.12 or greater needed."
Expand Down

0 comments on commit 055ada8

Please sign in to comment.