🆙 Add cms i using 🆙

This commit is contained in:
Remco
2025-11-25 22:42:56 +01:00
parent 94704e0925
commit d44196149e
35591 changed files with 3601123 additions and 0 deletions
@@ -0,0 +1,39 @@
<?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 League\Uri\Contracts\FragmentDirective;
use Stringable;
use function preg_match;
final class DirectiveString
{
/**
* Parse a Directive string representation.
*
* A Directive syntax is name[=value] where the
* separator `=` is not present when no value
* is attached to it
*/
public static function resolve(Stringable|string $directive): FragmentDirective
{
$directive = (string) $directive;
return match (true) {
1 === preg_match('/^text(?:=|$)/i', $directive) => TextDirective::fromString($directive),
default => GenericDirective::fromString($directive),
};
}
}
@@ -0,0 +1,96 @@
<?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 League\Uri\Contracts\FragmentDirective;
use League\Uri\Encoder;
use League\Uri\Exceptions\SyntaxError;
use Stringable;
use Throwable;
use function explode;
use function str_replace;
final class GenericDirective implements FragmentDirective
{
/**
* @param non-empty-string $name
*/
private function __construct(
private readonly string $name,
private readonly ?string $value = null,
) {
}
/**
* Create a new instance from a string without the Directive delimiter (:~:) or a separator (&).
*/
public static function fromString(Stringable|string $value): self
{
[$name, $value] = explode('=', (string) $value, 2) + [1 => null];
(null !== $name && '' !== $name && !str_contains($name, '&')) || throw new SyntaxError('The submitted text is not a valid directive.');
return new self($name, $value);
}
private static function decode(?string $value): ?string
{
return null !== $value ? str_replace('%20', ' ', (string) Encoder::decodeFragment($value)) : null;
}
public function name(): string
{
/** @var non-empty-string $name */
$name = (string) self::decode($this->name);
return $name;
}
public function value(): ?string
{
return self::decode($this->value);
}
public function toString(): string
{
$str = $this->name;
if (null === $this->value) {
return $str;
}
return $str.'='.$this->value;
}
public function __toString(): string
{
return $this->toString();
}
public function equals(mixed $directive): bool
{
if (!$directive instanceof Stringable && !is_string($directive)) {
return false;
}
if (!$directive instanceof FragmentDirective) {
try {
$directive = self::fromString($directive);
} catch (Throwable) {
return false;
}
}
return $directive->toString() === $this->toString();
}
}
@@ -0,0 +1,246 @@
<?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 League\Uri\Contracts\FragmentDirective;
use League\Uri\Encoder;
use League\Uri\Exceptions\SyntaxError;
use Stringable;
use Throwable;
use function explode;
use function is_string;
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(Stringable|string $value): self
{
[$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(Stringable|string $text): self
{
'' !== $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 equals(mixed $directive): bool
{
if (!$directive instanceof Stringable && !is_string($directive)) {
return false;
}
if (!$directive instanceof FragmentDirective) {
try {
$directive = self::fromString($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 non-empty-string $text
*/
public function startsWith(string $text): self
{
if ($this->start === $text) {
return $this;
}
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 ?non-empty-string $text
*/
public function endsWith(?string $text): self
{
if ($this->end === $text) {
return $this;
}
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 ?non-empty-string $text
*/
public function followedBy(?string $text): self
{
if ($this->suffix === $text) {
return $this;
}
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.
*
* @param ?non-empty-string $text
*/
public function precededBy(?string $text): self
{
if ($this->prefix === $text) {
return $this;
}
return new self($this->start, $this->end, $text, $this->suffix);
}
}