1
0
mirror of https://github.com/Intervention/image.git synced 2025-03-11 04:39:38 +01:00

Mess with Config object

This commit is contained in:
Oliver Vogel 2024-05-10 17:01:38 +02:00
parent 64632cd2c3
commit 59781c723e
No known key found for this signature in database
GPG Key ID: 1B19D214C02D69BB
5 changed files with 16 additions and 60 deletions

View File

@ -5,9 +5,8 @@ declare(strict_types=1);
namespace Intervention\Image;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Interfaces\ConfigInterface;
class Config implements ConfigInterface
class Config
{
/**
* Create config object instance
@ -25,30 +24,20 @@ class Config implements ConfigInterface
}
/**
* {@inheritdoc}
* Set values of given config options
*
* @see ConfigInterface::setOption()
*/
public function setOption(string $name, mixed $value): self
{
if (!property_exists($this, $name)) {
throw new InputException('Property ' . $name . ' does not exists for ' . $this::class . '.');
}
$this->{$name} = $value;
return $this;
}
/**
* {@inheritdoc}
*
* @see COnfigInterface::setOptions()
* @param mixed $options
* @throws InputException
* @return Config
*/
public function setOptions(mixed ...$options): self
{
foreach ($options as $name => $value) {
$this->setOption($name, $value);
if (!property_exists($this, $name)) {
throw new InputException('Property ' . $name . ' does not exists for ' . $this::class . '.');
}
$this->{$name} = $value;
}
return $this;

View File

@ -10,7 +10,6 @@ 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;
@ -25,7 +24,7 @@ abstract class AbstractDriver implements DriverInterface
/**
* Driver options
*/
protected ConfigInterface $config;
protected Config $config;
/**
* @throws DriverException
@ -42,7 +41,7 @@ abstract class AbstractDriver implements DriverInterface
*
* @see DriverInterface::config()
*/
public function config(): ConfigInterface
public function config(): Config
{
return $this->config;
}

View File

@ -1,29 +0,0 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\InputException;
interface ConfigInterface
{
/**
* Set value of given config option
*
* @param string $name
* @param mixed $value
* @throws InputException
* @return ConfigInterface
*/
public function setOption(string $name, mixed $value): self;
/**
* Set values of given config options
*
* @param mixed $options
* @throws InputException
* @return ConfigInterface
*/
public function setOptions(mixed ...$options): self;
}

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Config;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Exceptions\RuntimeException;
@ -23,9 +24,9 @@ interface DriverInterface
/**
* Get driver configuration
*
* @return ConfigInterface
* @return Config
*/
public function config(): ConfigInterface;
public function config(): Config;
/**
* Resolve given object into a specialized version for the current driver

View File

@ -53,14 +53,10 @@ final class ConfigTest extends BaseTestCase
$this->assertFalse($result->decodeAnimation);
$this->assertEquals('f00', $result->blendingColor);
$result = $config->setOption('blendingColor', '000');
$result = $config->setOptions(blendingColor: '000');
$this->assertFalse($config->autoOrientation);
$this->assertFalse($config->decodeAnimation);
$this->assertEquals('000', $config->blendingColor);
$this->assertFalse($result->autoOrientation);
$this->assertFalse($result->decodeAnimation);
$this->assertEquals('000', $result->blendingColor);
}
}