Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
165 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Contributte\Imagist\Filter\StringFilter; | ||
|
||
use Contributte\Imagist\Filter\FilterIdentifier; | ||
use Contributte\Imagist\Filter\FilterInterface; | ||
use LogicException; | ||
|
||
final class StringFilter implements FilterInterface | ||
{ | ||
|
||
private string $name; | ||
|
||
/** @var mixed[] */ | ||
private array $arguments; | ||
|
||
/** | ||
* @param mixed[] $arguments | ||
*/ | ||
public function __construct(string $name, array $arguments = []) | ||
{ | ||
$this->name = $name; | ||
$this->arguments = $arguments; | ||
} | ||
|
||
public function getIdentifier(): FilterIdentifier | ||
{ | ||
return new FilterIdentifier($this->name, $this->arguments); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getArguments(): array | ||
{ | ||
return $this->arguments; | ||
} | ||
|
||
public function getOperations(): array | ||
{ | ||
throw new LogicException( | ||
sprintf( | ||
'String filter is only case without operations. Please use %s to extract correct filter.', | ||
StringFilterCollectionInterface::class, | ||
) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Contributte\Imagist\Filter\StringFilter; | ||
|
||
use Contributte\Imagist\Entity\ImageInterface; | ||
use Contributte\Imagist\Filter\FilterInterface; | ||
use LogicException; | ||
|
||
final class StringFilterFacade | ||
{ | ||
|
||
public static function resolveByFilter( | ||
?StringFilterCollectionInterface $collection, | ||
FilterInterface $filter | ||
): FilterInterface | ||
{ | ||
if ($filter instanceof StringFilter) { | ||
if (!$collection) { | ||
throw new LogicException( | ||
sprintf( | ||
'Class %s have to be set if you want use string filters.', | ||
StringFilterCollectionInterface::class | ||
) | ||
); | ||
} | ||
|
||
return $collection->get($filter->getName(), $filter->getArguments()); | ||
} | ||
|
||
return $filter; | ||
} | ||
|
||
public static function resolveByImage( | ||
?StringFilterCollectionInterface $collection, | ||
ImageInterface $image | ||
): ImageInterface | ||
{ | ||
if ($filter = $image->getFilter()) { | ||
return $image->withFilter(self::resolveByFilter($collection, $filter)); | ||
} | ||
|
||
return $image; | ||
} | ||
|
||
public static function resolveByNullableImage( | ||
?StringFilterCollectionInterface $collection, | ||
?ImageInterface $image | ||
): ?ImageInterface | ||
{ | ||
if (!$image) { | ||
return null; | ||
} | ||
|
||
if ($filter = $image->getFilter()) { | ||
return $image->withFilter(self::resolveByFilter($collection, $filter)); | ||
} | ||
|
||
return $image; | ||
} | ||
|
||
} |
Oops, something went wrong.