1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-28 16:19:50 +02:00

Mess with Config object

This commit is contained in:
Oliver Vogel
2024-05-10 17:01:38 +02:00
parent 64632cd2c3
commit 59781c723e
5 changed files with 16 additions and 60 deletions

View File

@@ -5,9 +5,8 @@ declare(strict_types=1);
namespace Intervention\Image; namespace Intervention\Image;
use Intervention\Image\Exceptions\InputException; use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Interfaces\ConfigInterface;
class Config implements ConfigInterface class Config
{ {
/** /**
* Create config object instance * Create config object instance
@@ -25,30 +24,20 @@ class Config implements ConfigInterface
} }
/** /**
* {@inheritdoc} * Set values of given config options
* *
* @see ConfigInterface::setOption() * @param mixed $options
*/ * @throws InputException
public function setOption(string $name, mixed $value): self * @return Config
{
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()
*/ */
public function setOptions(mixed ...$options): self public function setOptions(mixed ...$options): self
{ {
foreach ($options as $name => $value) { 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; return $this;

View File

@@ -10,7 +10,6 @@ use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\InputHandler; use Intervention\Image\InputHandler;
use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\AnalyzerInterface;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ConfigInterface;
use Intervention\Image\Interfaces\DecoderInterface; use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\EncoderInterface; use Intervention\Image\Interfaces\EncoderInterface;
@@ -25,7 +24,7 @@ abstract class AbstractDriver implements DriverInterface
/** /**
* Driver options * Driver options
*/ */
protected ConfigInterface $config; protected Config $config;
/** /**
* @throws DriverException * @throws DriverException
@@ -42,7 +41,7 @@ abstract class AbstractDriver implements DriverInterface
* *
* @see DriverInterface::config() * @see DriverInterface::config()
*/ */
public function config(): ConfigInterface public function config(): Config
{ {
return $this->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; namespace Intervention\Image\Interfaces;
use Intervention\Image\Config;
use Intervention\Image\Exceptions\DriverException; use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\Exceptions\RuntimeException;
@@ -23,9 +24,9 @@ interface DriverInterface
/** /**
* Get driver configuration * 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 * 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->assertFalse($result->decodeAnimation);
$this->assertEquals('f00', $result->blendingColor); $this->assertEquals('f00', $result->blendingColor);
$result = $config->setOption('blendingColor', '000'); $result = $config->setOptions(blendingColor: '000');
$this->assertFalse($config->autoOrientation); $this->assertFalse($config->autoOrientation);
$this->assertFalse($config->decodeAnimation); $this->assertFalse($config->decodeAnimation);
$this->assertEquals('000', $config->blendingColor); $this->assertEquals('000', $config->blendingColor);
$this->assertFalse($result->autoOrientation);
$this->assertFalse($result->decodeAnimation);
$this->assertEquals('000', $result->blendingColor);
} }
} }