1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-08 23:06:40 +02:00

Add possibility to add objects to decoder array

This commit is contained in:
Oliver Vogel
2024-01-15 10:19:00 +01:00
parent dc7dc5f5ab
commit 0d080ffe5a
2 changed files with 16 additions and 7 deletions

View File

@@ -3,6 +3,7 @@
namespace Intervention\Image\Drivers; namespace Intervention\Image\Drivers;
use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\AnalyzerInterface;
use Intervention\Image\Interfaces\DecoderInterface; use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\DriverInterface;
@@ -50,10 +51,18 @@ abstract class AbstractDriver implements DriverInterface
* *
* @see DriverInterface::specializeMultiple() * @see DriverInterface::specializeMultiple()
*/ */
public function specializeMultiple(array $objects): array public function specializeMultiple(array $specializables): array
{ {
return array_map(function ($classname) { return array_map(function ($specializable) {
return $this->specialize(new $classname()); return $this->specialize(
}, $objects); match (true) {
is_string($specializable) => new $specializable(),
is_object($specializable) => $specializable,
default => throw new RuntimeException(
'Specializable item must be either a class name or an object.'
)
}
);
}, $specializables);
} }
} }

View File

@@ -20,12 +20,12 @@ interface DriverInterface
public function specialize(object $object): ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface; public function specialize(object $object): ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface;
/** /**
* Resolve each object in given array into a specialized version for the current driver * Resolve array of classnames or objects into their specialized version for the current driver
* *
* @param array $objects * @param array $specializables
* @return array * @return array
*/ */
public function specializeMultiple(array $objects): array; public function specializeMultiple(array $specializables): array;
/** /**
* Create new image instance with the current driver in given dimensions * Create new image instance with the current driver in given dimensions