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:
parent
64632cd2c3
commit
59781c723e
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user