mirror of
https://github.com/Intervention/image.git
synced 2025-08-29 00:29:55 +02:00
Add configuration object
This commit is contained in:
32
src/Config.php
Normal file
32
src/Config.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image;
|
||||
|
||||
use Intervention\Image\Interfaces\ConfigInterface;
|
||||
|
||||
class Config implements ConfigInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected bool $autoOrientate = true,
|
||||
protected bool $decodeAnimation = true,
|
||||
protected mixed $blendingColor = 'ffffffff',
|
||||
) {
|
||||
}
|
||||
|
||||
public function decodeAnimation(): bool
|
||||
{
|
||||
return $this->decodeAnimation;
|
||||
}
|
||||
|
||||
public function autoOrientate(): bool
|
||||
{
|
||||
return $this->autoOrientate;
|
||||
}
|
||||
|
||||
public function blendingColor(): mixed
|
||||
{
|
||||
return $this->blendingColor;
|
||||
}
|
||||
}
|
@@ -4,11 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Drivers;
|
||||
|
||||
use Intervention\Image\Config;
|
||||
use Intervention\Image\Exceptions\DriverException;
|
||||
use Intervention\Image\Exceptions\NotSupportedException;
|
||||
use Intervention\Image\InputHandler;
|
||||
use Intervention\Image\Interfaces\AnalyzerInterface;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ConfigInterface;
|
||||
use Intervention\Image\Interfaces\DecoderInterface;
|
||||
use Intervention\Image\Interfaces\DriverInterface;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
@@ -21,13 +23,25 @@ use ReflectionClass;
|
||||
abstract class AbstractDriver implements DriverInterface
|
||||
{
|
||||
/**
|
||||
* @param ConfigInterface $config
|
||||
* @throws DriverException
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(protected ConfigInterface $config = new Config())
|
||||
{
|
||||
$this->checkHealth();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DriverInterface::config()
|
||||
*/
|
||||
public function config(): ConfigInterface
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
@@ -40,22 +40,24 @@ final class ImageManager implements ImageManagerInterface
|
||||
* Create image manager with GD driver
|
||||
*
|
||||
* @link https://image.intervention.io/v3/basics/image-manager#static-gd-driver-constructor
|
||||
* @param mixed $options
|
||||
* @return ImageManager
|
||||
*/
|
||||
public static function gd(): self
|
||||
public static function gd(mixed ...$options): self
|
||||
{
|
||||
return self::withDriver(GdDriver::class);
|
||||
return self::withDriver(new GdDriver(new Config(...$options)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create image manager with Imagick driver
|
||||
*
|
||||
* @link https://image.intervention.io/v3/basics/image-manager#static-imagick-driver-constructor
|
||||
* @param mixed $options
|
||||
* @return ImageManager
|
||||
*/
|
||||
public static function imagick(): self
|
||||
public static function imagick(mixed ...$options): self
|
||||
{
|
||||
return self::withDriver(ImagickDriver::class);
|
||||
return self::withDriver(new ImagickDriver(new Config(...$options)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
12
src/Interfaces/ConfigInterface.php
Normal file
12
src/Interfaces/ConfigInterface.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Interfaces;
|
||||
|
||||
interface ConfigInterface
|
||||
{
|
||||
public function decodeAnimation(): bool;
|
||||
public function autoOrientate(): bool;
|
||||
public function blendingColor(): mixed;
|
||||
}
|
@@ -20,6 +20,13 @@ interface DriverInterface
|
||||
*/
|
||||
public function id(): string;
|
||||
|
||||
/**
|
||||
* Get driver configuration
|
||||
*
|
||||
* @return ConfigInterface
|
||||
*/
|
||||
public function config(): ConfigInterface;
|
||||
|
||||
/**
|
||||
* Resolve given object into a specialized version for the current driver
|
||||
*
|
||||
|
Reference in New Issue
Block a user