mirror of
https://github.com/Intervention/image.git
synced 2025-01-17 12:18:14 +01:00
Image ImageManager instantiation signature
This commit is contained in:
parent
0bc8b7ce9b
commit
f0e7abb56b
8
src/Exceptions/ConfigurationException.php
Normal file
8
src/Exceptions/ConfigurationException.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Exceptions;
|
||||
|
||||
class ConfigurationException extends \RuntimeException
|
||||
{
|
||||
//
|
||||
}
|
@ -9,9 +9,16 @@ class ImageManager
|
||||
{
|
||||
use CanResolveDriverClass;
|
||||
|
||||
public function __construct(protected string $driver = 'gd')
|
||||
private static $required_options = ['driver'];
|
||||
|
||||
public function __construct(protected array $options)
|
||||
{
|
||||
//
|
||||
if (count(array_intersect(array_keys($options), self::$required_options)) != count(self::$required_options)) {
|
||||
throw new Exceptions\ConfigurationException(
|
||||
'The following attributes are required to initialize ImageManager: ' .
|
||||
implode(', ', self::$required_options)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,6 +62,6 @@ class ImageManager
|
||||
*/
|
||||
protected function getCurrentDriver(): string
|
||||
{
|
||||
return strtolower($this->driver);
|
||||
return strtolower($this->options['driver']);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Intervention\Image\Tests;
|
||||
|
||||
use Intervention\Image\Exceptions\ConfigurationException;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
|
||||
@ -12,14 +13,20 @@ class ImageManagerTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$manager = new ImageManager('foo');
|
||||
$manager = new ImageManager(['driver' => 'gd']);
|
||||
$this->assertInstanceOf(ImageManager::class, $manager);
|
||||
|
||||
$this->expectException(ConfigurationException::class);
|
||||
$manager = new ImageManager([]);
|
||||
|
||||
$this->expectException(ConfigurationException::class);
|
||||
$manager = new ImageManager(['foo' => 'bar']);
|
||||
}
|
||||
|
||||
/** @requires extension gd */
|
||||
public function testCreateGd()
|
||||
{
|
||||
$manager = new ImageManager('gd');
|
||||
$manager = new ImageManager(['driver' => 'gd']);
|
||||
$image = $manager->create(5, 4);
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
}
|
||||
@ -27,7 +34,7 @@ class ImageManagerTest extends TestCase
|
||||
/** @requires extension gd */
|
||||
public function testReadGd()
|
||||
{
|
||||
$manager = new ImageManager('gd');
|
||||
$manager = new ImageManager(['driver' => 'gd']);
|
||||
$image = $manager->read(__DIR__ . '/images/red.gif');
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
}
|
||||
@ -35,7 +42,7 @@ class ImageManagerTest extends TestCase
|
||||
/** @requires extension imagick */
|
||||
public function testCreateImagick()
|
||||
{
|
||||
$manager = new ImageManager('imagick');
|
||||
$manager = new ImageManager(['driver' => 'imagick']);
|
||||
$image = $manager->create(5, 4);
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
}
|
||||
@ -43,7 +50,7 @@ class ImageManagerTest extends TestCase
|
||||
/** @requires extension imagick */
|
||||
public function testReadImagick()
|
||||
{
|
||||
$manager = new ImageManager('imagick');
|
||||
$manager = new ImageManager(['driver' => 'imagick']);
|
||||
$image = $manager->read(__DIR__ . '/images/red.gif');
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user