mirror of
https://github.com/Intervention/image.git
synced 2025-08-21 13:11:18 +02:00
Added ModifierStack class
This commit is contained in:
28
src/ModifierStack.php
Normal file
28
src/ModifierStack.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image;
|
||||
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ModifierInterface;
|
||||
|
||||
class ModifierStack implements ModifierInterface
|
||||
{
|
||||
public function __construct(protected array $modifiers)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function apply(ImageInterface $image): ImageInterface
|
||||
{
|
||||
foreach ($this->modifiers as $modifier) {
|
||||
$modifier->apply($image);
|
||||
}
|
||||
}
|
||||
|
||||
public function push(ModifierInterface $modifier): self
|
||||
{
|
||||
$this->modifiers[] = $modifier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
25
tests/ModiferStackTest.php
Normal file
25
tests/ModiferStackTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests;
|
||||
|
||||
use Intervention\Image\Drivers\Gd\Modifiers\GreyscaleModifier;
|
||||
use Intervention\Image\ModifierStack;
|
||||
|
||||
/**
|
||||
* @covers \Intervention\Image\ModifierStack
|
||||
*/
|
||||
class ModifierStackTest extends TestCase
|
||||
{
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$stack = new ModifierStack([]);
|
||||
$this->assertInstanceOf(ModifierStack::class, $stack);
|
||||
}
|
||||
|
||||
public function testPush(): void
|
||||
{
|
||||
$stack = new ModifierStack([]);
|
||||
$result = $stack->push(new GreyscaleModifier());
|
||||
$this->assertInstanceOf(ModifierStack::class, $result);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user