Loheide-eu-mitarbeiterplatt.../vendor/intervention/image/src/InputHandler.php
Friederich Loheide 9c0f8de791
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Phase 0: Fundament für Inhaus
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3)
- Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung
- Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü
- Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person
- Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“
- Benutzerverwaltung im Admin, Zugang vorläufig über is_admin
- vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/
- PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung
- VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 20:35:30 +00:00

165 lines
5.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Intervention\Image;
use Generator;
use Intervention\Image\Colors\Cmyk\Decoders\StringColorDecoder as CmykStringColorDecoder;
use Intervention\Image\Colors\Hsl\Decoders\StringColorDecoder as HslStringColorDecoder;
use Intervention\Image\Colors\Hsv\Decoders\StringColorDecoder as HsvStringColorDecoder;
use Intervention\Image\Colors\Oklab\Decoders\StringColorDecoder as OklabStringColorDecoder;
use Intervention\Image\Colors\Oklch\Decoders\StringColorDecoder as OklchStringColorDecoder;
use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder as RgbHexColorDecoder;
use Intervention\Image\Colors\Rgb\Decoders\NamedColorDecoder;
use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder as RgbStringColorDecoder;
use Intervention\Image\Decoders\Base64ImageDecoder;
use Intervention\Image\Decoders\BinaryImageDecoder;
use Intervention\Image\Decoders\ColorObjectDecoder;
use Intervention\Image\Decoders\DataUriImageDecoder;
use Intervention\Image\Decoders\EncodedImageObjectDecoder;
use Intervention\Image\Decoders\FilePathImageDecoder;
use Intervention\Image\Decoders\StreamImageDecoder;
use Intervention\Image\Decoders\ImageObjectDecoder;
use Intervention\Image\Decoders\NativeObjectDecoder;
use Intervention\Image\Decoders\SplFileInfoImageDecoder;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\InvalidArgumentException;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\InputHandlerInterface;
class InputHandler implements InputHandlerInterface
{
/**
* All available image decoders.
*/
public const array IMAGE_DECODERS = [
ImageObjectDecoder::class,
NativeObjectDecoder::class,
StreamImageDecoder::class,
SplFileInfoImageDecoder::class,
EncodedImageObjectDecoder::class,
DataUriImageDecoder::class,
Base64ImageDecoder::class,
BinaryImageDecoder::class,
FilePathImageDecoder::class,
];
/**
* All available color decoders.
*/
public const array COLOR_DECODERS = [
NamedColorDecoder::class,
ColorObjectDecoder::class,
RgbHexColorDecoder::class,
RgbStringColorDecoder::class,
CmykStringColorDecoder::class,
HsvStringColorDecoder::class,
HslStringColorDecoder::class,
OklabStringColorDecoder::class,
OklchStringColorDecoder::class,
];
/**
* Create new input handler instance with given decoder classnames.
*
* @param array<string|DecoderInterface> $decoders
*/
public function __construct(
protected array $decoders = [],
protected ?DriverInterface $driver = null,
) {
//
}
/**
* Static factory method to create input handler for both image and color handling.
*
* @param array<string|DecoderInterface> $decoders
*/
public static function usingDecoders(array $decoders, ?DriverInterface $driver = null): self
{
return new self($decoders, $driver);
}
/**
* {@inheritdoc}
*
* @see InputHandlerInterface::handle()
*
* @throws InvalidArgumentException
* @throws NotSupportedException
* @throws DriverException
*/
public function handle(mixed $input): ImageInterface|ColorInterface
{
if ($input === null) {
throw new InvalidArgumentException('Unable to decode from null');
}
if ($input === '') {
throw new InvalidArgumentException('Unable to decode from empty string');
}
// if handler has only one single decoder run it can run directly
if (count($this->decoders) === 1) {
return $this->decoders()->current()->decode($input);
}
// multiple decoders: try to find the matching decoder for the input
foreach ($this->decoders() as $decoder) {
if ($decoder->supports($input)) {
return $decoder->decode($input);
}
}
throw new NotSupportedException('Unprocessable input');
}
/**
* Yield all decoders.
*
* @throws InvalidArgumentException
* @throws DriverException
*/
private function decoders(): Generator
{
foreach ($this->decoders as $decoder) {
yield $this->decoder($decoder);
}
}
/**
* Resolve the given classname or object to a decoder object.
*
* @throws InvalidArgumentException
* @throws DriverException
*/
private function decoder(string|DecoderInterface $decoder): DecoderInterface
{
if (is_string($decoder)) {
if (!is_subclass_of($decoder, DecoderInterface::class)) {
throw new InvalidArgumentException('Decoder must implement ' . DecoderInterface::class);
}
$decoder = new $decoder();
}
if ($this->driver === null) {
return $decoder;
}
try {
return $this->driver->specializeDecoder($decoder);
} catch (NotSupportedException $e) {
throw new DriverException(
'Failed to resolve decoder ' . $decoder::class . ' with driver ' . $this->driver::class,
previous: $e,
);
}
}
}