ama-team/php-projection-framework

View on GitHub
src/Image/Adapter/Discovery.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace AmaTeam\Image\Projection\Image\Adapter;

use AmaTeam\Image\Projection\API\Image\ImageFactoryInterface;
use RuntimeException;

class Discovery
{
    const FACTORIES = [
        Gd\ImageFactory::class,
        Imagick\ImageFactory::class,
    ];

    /**
     * @return ImageFactoryInterface
     */
    public static function find()
    {
        foreach (self::FACTORIES as $backend) {
            if ($backend::supported()) {
                return new $backend;
            }
        }
        $message = 'Couldn\'t find any image processing backend, please ' .
            'install gd (preferred) / imagick.';
        throw new RuntimeException($message);
    }
}