Loheide-eu-mitarbeiterplatt.../vendor/league/uri-components/Components/FragmentDirectives/TextDirective.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

286 lines
8.3 KiB
PHP

<?php
/**
* League.Uri (https://uri.thephpleague.com)
*
* (c) Ignace Nyamagana Butera <nyamsprod@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace League\Uri\Components\FragmentDirectives;
use BackedEnum;
use League\Uri\Contracts\FragmentDirective;
use League\Uri\Encoder;
use League\Uri\Exceptions\SyntaxError;
use League\Uri\StringCoercionMode;
use Stringable;
use Throwable;
use function explode;
use function preg_match;
use function str_replace;
final class TextDirective implements FragmentDirective
{
private const NAME = 'text';
private const REGEXP_PATTERN = '/^
(?:(?<prefix>.+?)-,)? # optional prefix up to first "-,"
(?<start>[^,]+?) # required start (up to "," or end)
(?:,(?<end>[^,-]*),?)? # optional end, stop before ",-" if present
(?:,-(?<suffix>.+))? # optional suffix (to end)
$/x';
/**
* @param non-empty-string $start
* @param ?non-empty-string $end
* @param ?non-empty-string $prefix
* @param ?non-empty-string $suffix
*/
public function __construct(
public readonly string $start,
public readonly ?string $end = null,
public readonly ?string $prefix = null,
public readonly ?string $suffix = null,
) {
('' !== $this->start && '' !== $this->end && '' !== $this->prefix && '' !== $this->suffix)
|| throw new SyntaxError('The start part can not be the empty string.');
}
/**
* Create a new instance from a string without the Directive delimiter (:~:) or a separator (&).
*/
public static function fromString(BackedEnum|Stringable|string $value): self
{
if ($value instanceof BackedEnum) {
$value = (string) $value->value;
}
[$name, $value] = explode('=', (string) $value, 2) + [1 => ''];
self::NAME === $name || throw new SyntaxError('The submitted text is not a text directive.');
return self::fromValue($value);
}
/**
* Create a new instance from a string without the Directive name and the separator (=).
*/
public static function fromValue(BackedEnum|Stringable|string $text): self
{
if ($text instanceof BackedEnum) {
$text = (string) $text->value;
}
'' !== $text || throw new SyntaxError('The text directive value can not be the empty string.');
1 === preg_match(self::REGEXP_PATTERN, (string) $text, $matches) || throw new SyntaxError('The text directive is malformed.');
if ('' === $matches['prefix']) {
$matches['prefix'] = null;
}
/** @var non-empty-string $start */
$start = (string) self::decode($matches['start']);
/** @var ?non-empty-string $prefix */
$prefix = self::decode($matches['prefix']);
/** @var ?non-empty-string $suffix */
$suffix = self::decode($matches['suffix'] ?? null);
$matches['end'] ??= null;
if ('' === $matches['end']) {
$matches['end'] = null;
}
/** @var ?non-empty-string $end */
$end = self::decode($matches['end']);
return new self($start, $end, $prefix, $suffix);
}
private static function encode(?string $value): ?string
{
return null !== $value ? strtr((string) Encoder::encodeQueryOrFragment($value), ['-' => '%2D', ',' => '%2C', '&' => '%26']) : null;
}
private static function decode(?string $value): ?string
{
if (null === $value) {
return null;
}
return str_replace('%20', ' ', (string) Encoder::decodeFragment($value));
}
public function name(): string
{
return self::NAME;
}
public function value(): string
{
$str = $this->start;
if (null !== $this->prefix) {
$str = $this->prefix.'-,'.$str;
}
if (null !== $this->end) {
$str .= ','.$this->end;
}
if (null !== $this->suffix) {
$str .= ',-'.$this->suffix;
}
return $str;
}
public function toString(): string
{
$encodedValue = (string) self::encode($this->start);
$prefix = self::encode($this->prefix);
if (null !== $prefix) {
$encodedValue = $prefix.'-,'.$encodedValue;
}
$end = self::encode($this->end);
if (null !== $end) {
$encodedValue .= ','.$end;
}
$suffix = self::encode($this->suffix);
if (null !== $suffix) {
$encodedValue .= ',-'.$suffix;
}
return self::NAME.'='.$encodedValue;
}
public function __toString(): string
{
return $this->toString();
}
public function toFragmentValue(): string
{
return ':~:'.$this->toString();
}
public function equals(mixed $directive): bool
{
if (null === $directive || ! StringCoercionMode::Native->isCoercible($directive)) {
return false;
}
if (!$directive instanceof FragmentDirective) {
try {
$directive = self::fromString((string) StringCoercionMode::Native->coerce($directive));
} catch (Throwable) {
return false;
}
}
return $directive->toString() === $this->toString();
}
/**
* Returns a new instance with a new start portion.
*
* The submitted string must be in its decoded form
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the new start portion.
*
* @param BackedEnum|Stringable|non-empty-string $text
*/
public function startsWith(BackedEnum|Stringable|string $text): self
{
if ($text instanceof BackedEnum) {
$text = $text->value;
}
$text = (string) $text;
if ($this->start === $text) {
return $this;
}
'' !== $text || throw new SyntaxError('The start part can not be the empty string.');
return new self($text, $this->end, $this->prefix, $this->suffix);
}
/**
* Returns a new instance with a new end portion.
*
* The submitted string must be in its decoded form
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the new end portion.
*
* @param BackedEnum|Stringable|non-empty-string|null $text
*/
public function endsWith(BackedEnum|Stringable|string|null $text): self
{
if ($text instanceof BackedEnum) {
$text = $text->value;
}
$text = (string) $text;
if ($this->end === $text) {
return $this;
}
'' !== $text || throw new SyntaxError('The end part can not be the empty string.');
return new self($this->start, $text, $this->prefix, $this->suffix);
}
/**
* Returns a new instance with a new suffix portion.
*
* The submitted string must be in its decoded form
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the new suffix portion.
*
* @param BackedEnum|Stringable|non-empty-string|null $text
*/
public function followedBy(BackedEnum|Stringable|string|null $text): self
{
if ($text instanceof BackedEnum) {
$text = $text->value;
}
$text = (string) $text;
if ($this->suffix === $text) {
return $this;
}
'' !== $text || throw new SyntaxError('The suffix part can not be the empty string.');
return new self($this->start, $this->end, $this->prefix, $text);
}
/**
* Returns a new instance with a new prefix portion.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the new prefix portion.
*/
public function precededBy(BackedEnum|Stringable|string|null $text): self
{
if ($text instanceof BackedEnum) {
$text = $text->value;
}
$text = (string) $text;
if ($this->prefix === $text) {
return $this;
}
'' !== $text || throw new SyntaxError('The prefix part can not be the empty string.');
return new self($this->start, $this->end, $text, $this->suffix);
}
}