Phase 0: Fundament für Inhaus
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

- 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>
This commit is contained in:
Friederich Loheide 2026-09-25 20:35:30 +00:00
parent 7197eaebf2
commit 9c0f8de791
15771 changed files with 1564103 additions and 5 deletions

View file

@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Traits;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Exceptions\StateException;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\SpecializableInterface;
use ReflectionClass;
trait CanBeDriverSpecialized
{
/**
* Cache for constructor parameter names keyed by class name.
*
* @var array<string, array<int, string>>
*/
private static array $parameterCache = [];
/**
* The driver with which the instance will be specialized.
*/
protected DriverInterface $driver;
/**
* {@inheritdoc}
*
* @see SpecializableInterface::specializationArguments()
*/
public function specializationArguments(): array
{
$class = $this::class;
if (!isset(self::$parameterCache[$class])) {
$names = [];
$reflectionClass = new ReflectionClass($class);
$constructor = $reflectionClass->getConstructor();
if ($constructor !== null) {
foreach ($constructor->getParameters() as $parameter) {
$names[] = $parameter->getName();
}
}
self::$parameterCache[$class] = $names;
}
$specializable = [];
foreach (self::$parameterCache[$class] as $name) {
$specializable[$name] = $this->{$name};
}
return $specializable;
}
/**
* {@inheritdoc}
*
* @see SpecializableInterface::driver()
*
* @throws StateException
*/
public function driver(): DriverInterface
{
if (!isset($this->driver)) {
throw new StateException(
'Use setDriver() on ' . $this::class . ' to provide an applicable ' . DriverInterface::class,
);
}
return $this->driver;
}
/**
* {@inheritdoc}
*
* @see SpecializableInterface::setDriver()
*
* @throws NotSupportedException
*/
public function setDriver(DriverInterface $driver): SpecializableInterface
{
if (!$this->belongsToDriver($driver)) {
throw new NotSupportedException(
"Class '" . $this::class . "' can not be used with " . $driver->id() . " driver",
);
}
$this->driver = $driver;
return $this;
}
/**
* Determine if the current object belongs to the given driver's namespace.
*/
protected function belongsToDriver(object $driver): bool
{
return str_starts_with(
$this::class,
substr($driver::class, 0, (int) strrpos($driver::class, '\\')), // driver namespace
);
}
}

View file

@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Traits;
use Intervention\Image\Exceptions\StreamException;
use Intervention\Image\Exceptions\InvalidArgumentException;
trait CanBuildStream
{
/**
* Transform the provided data into a stream resource with the data as its content.
*
* @param resource|string|null $data
* @throws InvalidArgumentException
* @throws StreamException
* @return resource
*/
public static function buildStreamOrFail(mixed $data = null)
{
$buildStrategy = match (true) {
is_null($data) => fn(mixed $data) => fopen('php://temp', 'r+'),
is_resource($data) && get_resource_type($data) === 'stream' => fn(mixed $data) => $data,
is_string($data) => function (mixed $data) {
$stream = fopen('php://temp', 'r+');
if ($stream === false) {
throw new StreamException('Failed to build stream from string');
}
fwrite($stream, $data);
return $stream;
},
default => throw new InvalidArgumentException(
'Unable to create stream from ' . gettype($data) . '. Use only null, string or resource.',
),
};
$stream = $buildStrategy($data);
if ($stream === false) {
throw new StreamException('Failed to build stream');
}
$rewind = rewind($stream);
if ($rewind === false) {
throw new StreamException('Failed to rewind stream');
}
return $stream;
}
}

View file

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Traits;
use DivisionByZeroError;
use Intervention\Image\Exceptions\RuntimeException;
trait CanConvertRange
{
/**
* Convert input in range (min) to (max) to the corresponding value
* in target range (targetMin) to (targetMax).
*
* @throws RuntimeException
*/
public static function convertRange(
float|int $input,
float|int $min,
float|int $max,
float|int $targetMin,
float|int $targetMax,
): float {
try {
return ((($input - $min) * ($targetMax - $targetMin)) / ($max - $min)) + $targetMin;
} catch (DivisionByZeroError) {
throw new RuntimeException('Division by zero');
}
}
}

View file

@ -0,0 +1,109 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Traits;
use Intervention\Image\Interfaces\DataUriInterface;
use Stringable;
trait CanDetectImageSources
{
/**
* Returns true if the specified content could be base64 encoded.
*
* This does not necessarily mean that the content actually meets this
* assumption, but only serves as an initial filter.
*/
protected function couldBeBase64Data(mixed $input): bool
{
if (!is_string($input) && !$input instanceof Stringable) {
return false;
}
$input = (string) $input;
if (str_ends_with($input, '=')) {
return true;
}
$decoded = base64_decode($input, strict: true);
if ($decoded === false) {
return false;
}
return base64_encode($decoded) === $input;
}
/**
* Returns true if the specified content could be binary data.
*
* This does not necessarily mean that the content actually meets this
* assumption, but only serves as an initial filter.
*/
protected function couldBeBinaryData(mixed $input): bool
{
if (!is_string($input) && !$input instanceof Stringable) {
return false;
}
$input = (string) $input;
// contains non printable ascii
if (preg_match('/[^ -~]/', $input) === 1) {
return true;
}
// contains only printable ascii
if (preg_match('/^[ -~]+$/', $input) === 1) {
return false;
}
return true;
}
/**
* Returns true if the specified content could be a data uri.
*
* This does not necessarily mean that the content actually meets this
* assumption, but only serves as an initial filter.
*/
protected function couldBeDataUrl(mixed $input): bool
{
if ($input instanceof DataUriInterface) {
return true;
}
return is_string($input) && str_starts_with($input, 'data:');
}
/**
* Returns true if the specified content could be a file path.
*
* This does not necessarily mean that the content actually meets this
* assumption, but only serves as an initial filter.
*/
protected function couldBeFilePath(mixed $input): bool
{
if (!is_string($input) && !$input instanceof Stringable) {
return false;
}
$input = (string) $input;
if (strlen($input) > PHP_MAXPATHLEN) {
return false;
}
if (str_starts_with($input, DIRECTORY_SEPARATOR)) {
return true;
}
if (preg_match('/[^ -~]/', $input) === 1) {
return false;
}
return true;
}
}

View file

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Traits;
use Intervention\Image\Interfaces\ColorChannelInterface;
use Intervention\Image\Interfaces\ColorInterface;
trait CanHashColor
{
/**
* Build hash for color.
*/
protected function hashColor(ColorInterface $color): string
{
$channelValues = array_map(
fn(ColorChannelInterface $channel): int|float => $channel->value(),
$color->channels(),
);
return md5($color->colorspace()::class . implode(',', $channelValues));
}
}

View file

@ -0,0 +1,132 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Traits;
use Intervention\Image\Exceptions\DirectoryNotFoundException;
use Intervention\Image\Exceptions\FileNotFoundException;
use Intervention\Image\Exceptions\FileNotReadableException;
use Intervention\Image\Exceptions\InvalidArgumentException;
use SplFileInfo;
use Stringable;
trait CanParseFilePath
{
/**
* Parse and return existing file path or throw exception.
*
* @throws InvalidArgumentException
* @throws DirectoryNotFoundException
* @throws FileNotFoundException
* @throws FileNotReadableException
*/
protected static function readableFilePathOrFail(mixed $path): string
{
if (!is_string($path) && !$path instanceof Stringable) {
throw new InvalidArgumentException('Path must be either of type string or instance of Stringable');
}
$path = (string) $path;
if ($path === '') {
throw new InvalidArgumentException('Path must not be an empty string');
}
if (strlen($path) > PHP_MAXPATHLEN) {
throw new InvalidArgumentException(
"Path is longer than the configured max. value of " . PHP_MAXPATHLEN,
);
}
// get info on path
$dirname = pathinfo($path, PATHINFO_DIRNAME);
$basename = pathinfo($path, PATHINFO_BASENAME);
if (!is_dir($dirname)) {
throw new DirectoryNotFoundException('Directory "' . $dirname . '" not found');
}
// file must exit
if (!file_exists($path)) {
throw new FileNotFoundException('File "' . $basename . '" not found in directory "' . $dirname . '"');
}
if (!is_file($path)) {
throw new FileNotFoundException('"' . $basename . '" is no file in directory "' . $dirname . '"');
}
if (!is_readable($dirname)) {
throw new FileNotReadableException('Directory "' . $dirname . '" is not readable');
}
if (!is_readable($path)) {
throw new FileNotReadableException('File "' . $path . '" is not readable');
}
$realpath = realpath($path);
if ($realpath === false) {
throw new FileNotReadableException('File "' . $path . '" is not readable');
}
return $realpath;
}
/**
* Read real path from given SplFileInfo object or throw exeption.
*
* @throws InvalidArgumentException
* @throws DirectoryNotFoundException
* @throws FileNotFoundException
* @throws FileNotReadableException
*/
protected static function filePathFromSplFileInfoOrFail(SplFileInfo $splFileInfo): string
{
$path = $splFileInfo->getPathname();
$dirname = pathinfo($path, PATHINFO_DIRNAME);
$basename = pathinfo($path, PATHINFO_BASENAME);
if ($path === '') {
throw new InvalidArgumentException('Path contained in SplFileInfo must not be an empty string');
}
if (!is_dir($dirname)) {
throw new DirectoryNotFoundException(
'The directory "' . $dirname . '" contained in SplFileInfo does not exist',
);
}
if (!file_exists($path)) {
throw new FileNotFoundException(
'File "' . $basename . '" contained in SplFileInfo was not found in directory "' . $dirname . '"',
);
}
if (!is_file($path)) {
throw new FileNotFoundException(
'File "' . $basename . '" contained in SplFileInfo is no file in directory "' . $dirname . '"',
);
}
if (!is_readable($dirname)) {
throw new FileNotReadableException(
'Directory "' . $dirname . '" contained in SplFileInfo is not readable',
);
}
if (!is_readable($path)) {
throw new FileNotReadableException(
'File "' . $path . '" contained in SplFileInfo is not readable',
);
}
$realpath = $splFileInfo->getRealPath();
if ($realpath === false) {
throw new FileNotReadableException('Failed to read file "' . $path . '" from ' . SplFileInfo::class);
}
return $realpath;
}
}

View file

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Traits;
use Intervention\Image\Exceptions\InvalidArgumentException;
use Intervention\Image\Interfaces\DriverInterface;
trait CanResolveDriver
{
/**
* Resolve given string or driver to a driver instance with given options.
*
* @throws InvalidArgumentException
*/
protected static function resolveDriver(string|DriverInterface $driver, mixed ...$options): DriverInterface
{
if (is_string($driver) && !class_exists($driver)) {
throw new InvalidArgumentException(
'Argument $driver must be existing class name',
);
}
if (is_string($driver) && !is_subclass_of($driver, DriverInterface::class)) {
throw new InvalidArgumentException(
'Argument $driver must be an implementation of ' . DriverInterface::class,
);
}
$driver = is_string($driver) ? new $driver() : $driver;
$driver->config()->setOptions(...$options);
return $driver;
}
}