mirror of
https://github.com/Intervention/image.git
synced 2025-01-17 20:28:21 +01:00
Add possibility to add objects to decoder array
This commit is contained in:
parent
dc7dc5f5ab
commit
0d080ffe5a
@ -3,6 +3,7 @@
|
||||
namespace Intervention\Image\Drivers;
|
||||
|
||||
use Intervention\Image\Exceptions\NotSupportedException;
|
||||
use Intervention\Image\Exceptions\RuntimeException;
|
||||
use Intervention\Image\Interfaces\AnalyzerInterface;
|
||||
use Intervention\Image\Interfaces\DecoderInterface;
|
||||
use Intervention\Image\Interfaces\DriverInterface;
|
||||
@ -50,10 +51,18 @@ abstract class AbstractDriver implements DriverInterface
|
||||
*
|
||||
* @see DriverInterface::specializeMultiple()
|
||||
*/
|
||||
public function specializeMultiple(array $objects): array
|
||||
public function specializeMultiple(array $specializables): array
|
||||
{
|
||||
return array_map(function ($classname) {
|
||||
return $this->specialize(new $classname());
|
||||
}, $objects);
|
||||
return array_map(function ($specializable) {
|
||||
return $this->specialize(
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,12 @@ interface DriverInterface
|
||||
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
|
||||
*/
|
||||
public function specializeMultiple(array $objects): array;
|
||||
public function specializeMultiple(array $specializables): array;
|
||||
|
||||
/**
|
||||
* Create new image instance with the current driver in given dimensions
|
||||
|
Loading…
x
Reference in New Issue
Block a user