mirror of
https://github.com/Intervention/image.git
synced 2025-08-22 13:32:56 +02:00
Add InputHandlerInterface
This commit is contained in:
@@ -6,8 +6,9 @@ use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
||||
use Intervention\Image\Exceptions\DecoderException;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\InputHandlerInterface;
|
||||
|
||||
abstract class AbstractInputHandler
|
||||
abstract class AbstractInputHandler implements InputHandlerInterface
|
||||
{
|
||||
/**
|
||||
* Array of decoders which will be stacked into to the input handler chain
|
||||
@@ -15,15 +16,25 @@ abstract class AbstractInputHandler
|
||||
protected array $decoders = [];
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param array $decoders
|
||||
* @see InputHandlerInterface::__construct()
|
||||
*/
|
||||
public function __construct(array $decoders = [])
|
||||
{
|
||||
$this->decoders = count($decoders) ? $decoders : $this->decoders;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see InputHandlerInterface::handle()
|
||||
*/
|
||||
public function handle($input): ImageInterface|ColorInterface
|
||||
{
|
||||
return $this->chain()->handle($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stack the decoder array into a nested decoder object
|
||||
*
|
||||
@@ -46,15 +57,4 @@ abstract class AbstractInputHandler
|
||||
|
||||
return $chain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to decode the given input with each decoder of the the handler chain
|
||||
*
|
||||
* @param mixed $input
|
||||
* @return ImageInterface|ColorInterface
|
||||
*/
|
||||
public function handle($input): ImageInterface|ColorInterface
|
||||
{
|
||||
return $this->chain()->handle($input);
|
||||
}
|
||||
}
|
||||
|
21
src/Interfaces/InputHandlerInterface.php
Normal file
21
src/Interfaces/InputHandlerInterface.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Interfaces;
|
||||
|
||||
interface InputHandlerInterface
|
||||
{
|
||||
/**
|
||||
* Create new instance with an array of decoders
|
||||
*
|
||||
* @param array $decoders
|
||||
*/
|
||||
public function __construct(array $decoders = []);
|
||||
|
||||
/**
|
||||
* Try to decode the given input with each decoder of the the handler chain
|
||||
*
|
||||
* @param mixed $input
|
||||
* @return ImageInterface|ColorInterface
|
||||
*/
|
||||
public function handle($input): ImageInterface|ColorInterface;
|
||||
}
|
@@ -29,15 +29,16 @@ final class AbstractInputHandlerTest extends TestCase
|
||||
|
||||
private function getModifier(AbstractDecoder $chain): AbstractInputHandler
|
||||
{
|
||||
return new class ($chain) extends AbstractInputHandler {
|
||||
public function __construct(private AbstractDecoder $chain)
|
||||
return new class ([$chain]) extends AbstractInputHandler
|
||||
{
|
||||
public function __construct(protected array $decoders = [])
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
protected function chain(): AbstractDecoder
|
||||
{
|
||||
return $this->chain;
|
||||
return $this->decoders[0];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user