1
0
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:
Oliver Vogel
2022-02-11 19:33:29 +01:00
parent a1a07ac1e7
commit 9d2318d828
2 changed files with 53 additions and 0 deletions

28
src/ModifierStack.php Normal file
View 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;
}
}

View 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);
}
}