"Fossies" - the Fresh Open Source Software Archive

Member "contao-4.4.48/core-bundle/src/DependencyInjection/Compiler/AddImagineClassPass.php" (2 Apr 2020, 1385 Bytes) of package /linux/www/contao-4.4.48.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AddImagineClassPass.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 /*
    4  * This file is part of Contao.
    5  *
    6  * (c) Leo Feyer
    7  *
    8  * @license LGPL-3.0-or-later
    9  */
   10 
   11 namespace Contao\CoreBundle\DependencyInjection\Compiler;
   12 
   13 use Imagine\Exception\RuntimeException;
   14 use Imagine\Gd\Imagine;
   15 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
   16 use Symfony\Component\DependencyInjection\ContainerBuilder;
   17 
   18 /**
   19  * Sets the available Imagine class name in the container.
   20  *
   21  * @author Martin Auswöger <martin@auswoeger.com>
   22  */
   23 class AddImagineClassPass implements CompilerPassInterface
   24 {
   25     /**
   26      * @var array
   27      */
   28     private $magicks = ['Gmagick', 'Imagick'];
   29 
   30     /**
   31      * {@inheritdoc}
   32      */
   33     public function process(ContainerBuilder $container)
   34     {
   35         $container->getDefinition('contao.image.imagine')->setClass($this->getImagineImplementation());
   36     }
   37 
   38     /**
   39      * Returns the available Imagine implementation.
   40      *
   41      * @return string
   42      */
   43     private function getImagineImplementation()
   44     {
   45         foreach ($this->magicks as $name) {
   46             $class = 'Imagine\\'.$name.'\Imagine';
   47 
   48             // Will throw an exception if the PHP implementation is not available
   49             try {
   50                 new $class();
   51             } catch (RuntimeException $e) {
   52                 continue;
   53             }
   54 
   55             return $class;
   56         }
   57 
   58         return Imagine::class; // see #616
   59     }
   60 }