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
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:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
30
vendor/spomky-labs/cbor-php/src/OtherObject/BreakObject.php
vendored
Normal file
30
vendor/spomky-labs/cbor-php/src/OtherObject/BreakObject.php
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use CBOR\OtherObject as Base;
|
||||
|
||||
final class BreakObject extends Base
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(self::OBJECT_BREAK, null);
|
||||
}
|
||||
|
||||
public static function create(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public static function supportedAdditionalInformation(): array
|
||||
{
|
||||
return [self::OBJECT_BREAK];
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data): Base
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
}
|
||||
79
vendor/spomky-labs/cbor-php/src/OtherObject/DoublePrecisionFloatObject.php
vendored
Normal file
79
vendor/spomky-labs/cbor-php/src/OtherObject/DoublePrecisionFloatObject.php
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use CBOR\Normalizable;
|
||||
use CBOR\OtherObject as Base;
|
||||
use InvalidArgumentException;
|
||||
use function strlen;
|
||||
|
||||
final class DoublePrecisionFloatObject extends Base implements Normalizable
|
||||
{
|
||||
use FloatBitsTrait;
|
||||
|
||||
public static function supportedAdditionalInformation(): array
|
||||
{
|
||||
return [self::OBJECT_DOUBLE_PRECISION_FLOAT];
|
||||
}
|
||||
|
||||
public static function createFromFloat(float $number): self
|
||||
{
|
||||
$value = match (true) {
|
||||
is_nan($number) => self::hex2binSafe('7FF8000000000000'),
|
||||
is_infinite($number) && $number > 0 => self::hex2binSafe('7FF0000000000000'),
|
||||
is_infinite($number) && $number < 0 => self::hex2binSafe('FFF0000000000000'),
|
||||
default => (static fn (): string => unpack('S', "\x01\x00")[1] === 1 ? strrev(pack('d', $number)) : pack(
|
||||
'd',
|
||||
$number
|
||||
))(),
|
||||
};
|
||||
|
||||
return new self(self::OBJECT_DOUBLE_PRECISION_FLOAT, $value);
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data): Base
|
||||
{
|
||||
return new self($additionalInformation, $data);
|
||||
}
|
||||
|
||||
public static function create(string $value): self
|
||||
{
|
||||
if (strlen($value) !== 8) {
|
||||
throw new InvalidArgumentException('The value is not a valid double precision floating point');
|
||||
}
|
||||
|
||||
return new self(self::OBJECT_DOUBLE_PRECISION_FLOAT, $value);
|
||||
}
|
||||
|
||||
public function normalize(): float
|
||||
{
|
||||
return $this->value('E');
|
||||
}
|
||||
|
||||
public function getExponent(): int
|
||||
{
|
||||
return $this->bits('J') >> 52 & 0b11111111111;
|
||||
}
|
||||
|
||||
public function getMantissa(): int
|
||||
{
|
||||
return $this->bits('J') & 0xFFFFFFFFFFFFF;
|
||||
}
|
||||
|
||||
public function getSign(): int
|
||||
{
|
||||
// "J" is unpacked signed, so the sign bit of the binary64 payload is the sign of the PHP integer.
|
||||
return $this->bits('J') < 0 ? -1 : 1;
|
||||
}
|
||||
|
||||
private static function hex2binSafe(string $hex): string
|
||||
{
|
||||
$result = hex2bin($hex);
|
||||
if ($result === false) {
|
||||
throw new InvalidArgumentException('Invalid hex string');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
36
vendor/spomky-labs/cbor-php/src/OtherObject/FalseObject.php
vendored
Normal file
36
vendor/spomky-labs/cbor-php/src/OtherObject/FalseObject.php
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use CBOR\Normalizable;
|
||||
use CBOR\OtherObject as Base;
|
||||
|
||||
final class FalseObject extends Base implements Normalizable
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(self::OBJECT_FALSE, null);
|
||||
}
|
||||
|
||||
public static function create(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public static function supportedAdditionalInformation(): array
|
||||
{
|
||||
return [self::OBJECT_FALSE];
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data): Base
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public function normalize(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
57
vendor/spomky-labs/cbor-php/src/OtherObject/FloatBitsTrait.php
vendored
Normal file
57
vendor/spomky-labs/cbor-php/src/OtherObject/FloatBitsTrait.php
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use function is_float;
|
||||
use function is_int;
|
||||
|
||||
/**
|
||||
* Reads the IEEE 754 payload of a float object as native machine values.
|
||||
*
|
||||
* CBOR stores floats big-endian, which is exactly what unpack() consumes: "E" and "G" hand back the binary64 and
|
||||
* binary32 values themselves, and "J", "N" and "n" the raw bit pattern the sign, exponent and mantissa accessors sit
|
||||
* on. Both used to go through brick/math, which cost six BigInteger allocations for every float normalized.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
trait FloatBitsTrait
|
||||
{
|
||||
/**
|
||||
* The payload read as the floating point value it encodes.
|
||||
*/
|
||||
private function value(string $format): float
|
||||
{
|
||||
return (float) $this->unpackPayload($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* The payload read as its raw bit pattern, big-endian.
|
||||
*/
|
||||
private function bits(string $format): int
|
||||
{
|
||||
return (int) $this->unpackPayload($format);
|
||||
}
|
||||
|
||||
private function unpackPayload(string $format): int|float
|
||||
{
|
||||
$data = $this->data;
|
||||
if ($data === null) {
|
||||
throw new InvalidArgumentException('Invalid data');
|
||||
}
|
||||
|
||||
$unpacked = unpack($format, $data);
|
||||
if ($unpacked === false) {
|
||||
throw new InvalidArgumentException('Invalid data');
|
||||
}
|
||||
|
||||
$value = $unpacked[1];
|
||||
if (! is_int($value) && ! is_float($value)) {
|
||||
throw new InvalidArgumentException('Invalid data');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
26
vendor/spomky-labs/cbor-php/src/OtherObject/GenericObject.php
vendored
Normal file
26
vendor/spomky-labs/cbor-php/src/OtherObject/GenericObject.php
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use CBOR\OtherObject as Base;
|
||||
use InvalidArgumentException;
|
||||
use function ord;
|
||||
|
||||
final class GenericObject extends Base
|
||||
{
|
||||
public static function supportedAdditionalInformation(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data): Base
|
||||
{
|
||||
if ($data !== null && ord($data) < 32) {
|
||||
throw new InvalidArgumentException('Invalid simple value. Content data should not be present.');
|
||||
}
|
||||
|
||||
return new self($additionalInformation, $data);
|
||||
}
|
||||
}
|
||||
165
vendor/spomky-labs/cbor-php/src/OtherObject/HalfPrecisionFloatObject.php
vendored
Normal file
165
vendor/spomky-labs/cbor-php/src/OtherObject/HalfPrecisionFloatObject.php
vendored
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use CBOR\Normalizable;
|
||||
use CBOR\OtherObject as Base;
|
||||
use const INF;
|
||||
use InvalidArgumentException;
|
||||
use const NAN;
|
||||
use function ord;
|
||||
use function strlen;
|
||||
|
||||
final class HalfPrecisionFloatObject extends Base implements Normalizable
|
||||
{
|
||||
use FloatBitsTrait;
|
||||
|
||||
public static function supportedAdditionalInformation(): array
|
||||
{
|
||||
return [self::OBJECT_HALF_PRECISION_FLOAT];
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a PHP float as an IEEE 754 binary16 value: 1 sign bit, 5 exponent bits (bias 15) and 10 mantissa bits.
|
||||
*
|
||||
* The conversion reads the binary64 representation of the argument directly and rounds to nearest, ties to even,
|
||||
* as IEEE 754 mandates. Going through binary32 first would round twice and would therefore be off by one unit in
|
||||
* the last place for the values that sit exactly halfway between two binary16 neighbours.
|
||||
*/
|
||||
public static function createFromFloat(float $number): self
|
||||
{
|
||||
if (is_nan($number)) {
|
||||
// RFC 8949: canonical NaN is 0xf97e00 (quiet NaN with zero payload)
|
||||
return self::createFromBits(0x7E00);
|
||||
}
|
||||
|
||||
// abs() and comparisons cannot tell -0.0 from 0.0, so every bit is read from the packed representation.
|
||||
$packed = pack('E', $number);
|
||||
$signBit = (ord($packed[0]) & 0x80) === 0 ? 0 : 1 << 15;
|
||||
|
||||
if (is_infinite($number)) {
|
||||
return self::createFromBits($signBit | 0x7C00);
|
||||
}
|
||||
|
||||
// Magnitude of the binary64 value: 11 exponent bits (bias 1023) followed by 52 mantissa bits.
|
||||
$bits = ord($packed[0]) & 0x7F;
|
||||
for ($index = 1; $index < 8; $index++) {
|
||||
$bits = ($bits << 8) | ord($packed[$index]);
|
||||
}
|
||||
$doubleExponent = $bits >> 52;
|
||||
$doubleMantissa = $bits & 0x000FFFFFFFFFFFFF;
|
||||
|
||||
// Zero, or a subnormal binary64 below 2^-1022, which is far under half of the smallest binary16 subnormal.
|
||||
if ($doubleExponent === 0) {
|
||||
return self::createFromBits($signBit);
|
||||
}
|
||||
|
||||
// Significand with its implicit leading bit: abs($number) === $significand * 2 ** ($doubleExponent - 1075).
|
||||
$significand = $doubleMantissa | (1 << 52);
|
||||
|
||||
// Exponent field the value would carry as a normal binary16 number.
|
||||
$halfExponent = $doubleExponent - 1023 + 15;
|
||||
|
||||
// Too large for binary16, before rounding is even considered.
|
||||
if ($halfExponent >= 0x1F) {
|
||||
return self::createFromBits($signBit | 0x7C00);
|
||||
}
|
||||
|
||||
if ($halfExponent > 0) {
|
||||
// Normal: keep 11 significant bits (the implicit one plus 10) out of the 53 the significand holds.
|
||||
$halfSignificand = self::roundToNearestEven($significand, 42);
|
||||
if ($halfSignificand === 0x800) {
|
||||
// Rounding carried out of the mantissa and into the exponent.
|
||||
$halfSignificand >>= 1;
|
||||
$halfExponent++;
|
||||
if ($halfExponent >= 0x1F) {
|
||||
return self::createFromBits($signBit | 0x7C00);
|
||||
}
|
||||
}
|
||||
|
||||
return self::createFromBits($signBit | ($halfExponent << 10) | ($halfSignificand & 0x3FF));
|
||||
}
|
||||
|
||||
// Subnormal: express the value as a multiple of 2^-24, the smallest binary16 step.
|
||||
$shift = 43 - $halfExponent;
|
||||
if ($shift > 53) {
|
||||
// Strictly below half of the smallest subnormal, so it rounds to zero.
|
||||
return self::createFromBits($signBit);
|
||||
}
|
||||
|
||||
// A carry out of the 10 mantissa bits spills into the exponent field, which yields the smallest normal.
|
||||
return self::createFromBits($signBit | self::roundToNearestEven($significand, $shift));
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data): Base
|
||||
{
|
||||
return new self($additionalInformation, $data);
|
||||
}
|
||||
|
||||
public static function create(string $value): self
|
||||
{
|
||||
if (strlen($value) !== 2) {
|
||||
throw new InvalidArgumentException('The value is not a valid half precision floating point');
|
||||
}
|
||||
|
||||
return new self(self::OBJECT_HALF_PRECISION_FLOAT, $value);
|
||||
}
|
||||
|
||||
public function normalize(): float
|
||||
{
|
||||
// PHP has no native binary16, so the value is still assembled by hand -- but from the raw bits rather than
|
||||
// from three brick/math round trips.
|
||||
$bits = $this->bits('n');
|
||||
$exponent = $bits >> 10 & 0b11111;
|
||||
$mantissa = $bits & 0b1111111111;
|
||||
$sign = ($bits >> 15 & 1) === 1 ? -1 : 1;
|
||||
|
||||
if ($exponent === 0) {
|
||||
$val = $mantissa * 2 ** (-24);
|
||||
} elseif ($exponent !== 0b11111) {
|
||||
$val = ($mantissa + (1 << 10)) * 2 ** ($exponent - 25);
|
||||
} else {
|
||||
$val = $mantissa === 0 ? INF : NAN;
|
||||
}
|
||||
|
||||
return (float) ($sign * $val);
|
||||
}
|
||||
|
||||
public function getExponent(): int
|
||||
{
|
||||
return $this->bits('n') >> 10 & 0b11111;
|
||||
}
|
||||
|
||||
public function getMantissa(): int
|
||||
{
|
||||
return $this->bits('n') & 0b1111111111;
|
||||
}
|
||||
|
||||
public function getSign(): int
|
||||
{
|
||||
return ($this->bits('n') >> 15 & 1) === 1 ? -1 : 1;
|
||||
}
|
||||
|
||||
private static function createFromBits(int $bits): self
|
||||
{
|
||||
return new self(self::OBJECT_HALF_PRECISION_FLOAT, pack('n', $bits));
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop the $shift lowest bits of $significand, rounding to nearest and breaking ties towards the even value.
|
||||
*/
|
||||
private static function roundToNearestEven(int $significand, int $shift): int
|
||||
{
|
||||
$kept = $significand >> $shift;
|
||||
$dropped = $significand & ((1 << $shift) - 1);
|
||||
$halfway = 1 << ($shift - 1);
|
||||
|
||||
if ($dropped > $halfway || ($dropped === $halfway && ($kept & 1) === 1)) {
|
||||
$kept++;
|
||||
}
|
||||
|
||||
return $kept;
|
||||
}
|
||||
}
|
||||
36
vendor/spomky-labs/cbor-php/src/OtherObject/NullObject.php
vendored
Normal file
36
vendor/spomky-labs/cbor-php/src/OtherObject/NullObject.php
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use CBOR\Normalizable;
|
||||
use CBOR\OtherObject as Base;
|
||||
|
||||
final class NullObject extends Base implements Normalizable
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(self::OBJECT_NULL, null);
|
||||
}
|
||||
|
||||
public static function create(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public static function supportedAdditionalInformation(): array
|
||||
{
|
||||
return [self::OBJECT_NULL];
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data): Base
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public function normalize(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
17
vendor/spomky-labs/cbor-php/src/OtherObject/OtherObjectInterface.php
vendored
Normal file
17
vendor/spomky-labs/cbor-php/src/OtherObject/OtherObjectInterface.php
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use CBOR\CBORObject;
|
||||
|
||||
interface OtherObjectInterface extends CBORObject
|
||||
{
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public static function supportedAdditionalInformation(): array;
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data): self;
|
||||
}
|
||||
64
vendor/spomky-labs/cbor-php/src/OtherObject/OtherObjectManager.php
vendored
Normal file
64
vendor/spomky-labs/cbor-php/src/OtherObject/OtherObjectManager.php
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use function array_key_exists;
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class OtherObjectManager implements OtherObjectManagerInterface
|
||||
{
|
||||
/**
|
||||
* @var array<int, class-string<OtherObjectInterface>>
|
||||
*/
|
||||
private array $classes = [];
|
||||
|
||||
/**
|
||||
* @param class-string<OtherObjectInterface>[] $classes
|
||||
*/
|
||||
public function __construct(array $classes = [])
|
||||
{
|
||||
foreach ($classes as $class) {
|
||||
$this->add($class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<OtherObjectInterface>[] $classes
|
||||
*/
|
||||
public static function create(array $classes = []): self
|
||||
{
|
||||
return new self($classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<OtherObjectInterface> $class
|
||||
*/
|
||||
public function add(string $class): self
|
||||
{
|
||||
foreach ($class::supportedAdditionalInformation() as $ai) {
|
||||
if ($ai < 0) {
|
||||
throw new InvalidArgumentException('Invalid additional information.');
|
||||
}
|
||||
$this->classes[$ai] = $class;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<OtherObjectInterface>
|
||||
*/
|
||||
public function getClassForValue(int $value): string
|
||||
{
|
||||
return array_key_exists($value, $this->classes) ? $this->classes[$value] : GenericObject::class;
|
||||
}
|
||||
|
||||
public function createObjectForValue(int $value, ?string $data): OtherObjectInterface
|
||||
{
|
||||
$class = $this->getClassForValue($value);
|
||||
|
||||
return $class::createFromLoadedData($value, $data);
|
||||
}
|
||||
}
|
||||
10
vendor/spomky-labs/cbor-php/src/OtherObject/OtherObjectManagerInterface.php
vendored
Normal file
10
vendor/spomky-labs/cbor-php/src/OtherObject/OtherObjectManagerInterface.php
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
interface OtherObjectManagerInterface
|
||||
{
|
||||
public function createObjectForValue(int $value, ?string $data): OtherObjectInterface;
|
||||
}
|
||||
73
vendor/spomky-labs/cbor-php/src/OtherObject/SimpleObject.php
vendored
Normal file
73
vendor/spomky-labs/cbor-php/src/OtherObject/SimpleObject.php
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use CBOR\Normalizable;
|
||||
use CBOR\OtherObject as Base;
|
||||
use CBOR\Utils;
|
||||
use function chr;
|
||||
use InvalidArgumentException;
|
||||
use function ord;
|
||||
use function strlen;
|
||||
|
||||
final class SimpleObject extends Base implements Normalizable
|
||||
{
|
||||
public static function supportedAdditionalInformation(): array
|
||||
{
|
||||
return [...range(0, 19), 24];
|
||||
}
|
||||
|
||||
public static function create(int $value): self|FalseObject|TrueObject|NullObject|UndefinedObject
|
||||
{
|
||||
switch (true) {
|
||||
case $value >= 0 && $value <= 19:
|
||||
return new self($value, null);
|
||||
case $value === 20:
|
||||
return FalseObject::create();
|
||||
case $value === 21:
|
||||
return TrueObject::create();
|
||||
case $value === 22:
|
||||
return NullObject::create();
|
||||
case $value === 23:
|
||||
return UndefinedObject::create();
|
||||
case $value <= 31:
|
||||
throw new InvalidArgumentException('Invalid simple value. Shall be between 32 and 255.');
|
||||
case $value <= 255:
|
||||
return new self(24, chr($value));
|
||||
default:
|
||||
throw new InvalidArgumentException('The value is not a valid simple value.');
|
||||
}
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data): Base
|
||||
{
|
||||
if ($additionalInformation === 24) {
|
||||
if ($data === null) {
|
||||
throw new InvalidArgumentException('Invalid simple value. Content data is missing.');
|
||||
}
|
||||
if (strlen($data) !== 1) {
|
||||
throw new InvalidArgumentException('Invalid simple value. Content data is too long.');
|
||||
}
|
||||
if (ord($data) < 32) {
|
||||
throw new InvalidArgumentException('Invalid simple value. Content data must be between 32 and 255.');
|
||||
}
|
||||
} elseif ($additionalInformation < 20) {
|
||||
if ($data !== null) {
|
||||
throw new InvalidArgumentException('Invalid simple value. Content data should not be present.');
|
||||
}
|
||||
}
|
||||
|
||||
return new self($additionalInformation, $data);
|
||||
}
|
||||
|
||||
public function normalize(): int
|
||||
{
|
||||
if ($this->data === null) {
|
||||
return $this->getAdditionalInformation();
|
||||
}
|
||||
|
||||
return Utils::binToInt($this->data);
|
||||
}
|
||||
}
|
||||
78
vendor/spomky-labs/cbor-php/src/OtherObject/SinglePrecisionFloatObject.php
vendored
Normal file
78
vendor/spomky-labs/cbor-php/src/OtherObject/SinglePrecisionFloatObject.php
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use CBOR\Normalizable;
|
||||
use CBOR\OtherObject as Base;
|
||||
use InvalidArgumentException;
|
||||
use function strlen;
|
||||
|
||||
final class SinglePrecisionFloatObject extends Base implements Normalizable
|
||||
{
|
||||
use FloatBitsTrait;
|
||||
|
||||
public static function supportedAdditionalInformation(): array
|
||||
{
|
||||
return [self::OBJECT_SINGLE_PRECISION_FLOAT];
|
||||
}
|
||||
|
||||
public static function createFromFloat(float $number): self
|
||||
{
|
||||
$value = match (true) {
|
||||
is_nan($number) => self::hex2binSafe('7FC00000'),
|
||||
is_infinite($number) && $number > 0 => self::hex2binSafe('7F800000'),
|
||||
is_infinite($number) && $number < 0 => self::hex2binSafe('FF800000'),
|
||||
default => (static fn (): string => unpack('S', "\x01\x00")[1] === 1 ? strrev(pack('f', $number)) : pack(
|
||||
'f',
|
||||
$number
|
||||
))(),
|
||||
};
|
||||
|
||||
return new self(self::OBJECT_SINGLE_PRECISION_FLOAT, $value);
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data): Base
|
||||
{
|
||||
return new self($additionalInformation, $data);
|
||||
}
|
||||
|
||||
public static function create(string $value): self
|
||||
{
|
||||
if (strlen($value) !== 4) {
|
||||
throw new InvalidArgumentException('The value is not a valid single precision floating point');
|
||||
}
|
||||
|
||||
return new self(self::OBJECT_SINGLE_PRECISION_FLOAT, $value);
|
||||
}
|
||||
|
||||
public function normalize(): float
|
||||
{
|
||||
return $this->value('G');
|
||||
}
|
||||
|
||||
public function getExponent(): int
|
||||
{
|
||||
return $this->bits('N') >> 23 & 0b11111111;
|
||||
}
|
||||
|
||||
public function getMantissa(): int
|
||||
{
|
||||
return $this->bits('N') & 0x7FFFFF;
|
||||
}
|
||||
|
||||
public function getSign(): int
|
||||
{
|
||||
return ($this->bits('N') >> 31 & 1) === 1 ? -1 : 1;
|
||||
}
|
||||
|
||||
private static function hex2binSafe(string $hex): string
|
||||
{
|
||||
$result = hex2bin($hex);
|
||||
if ($result === false) {
|
||||
throw new InvalidArgumentException('Invalid hex string');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
36
vendor/spomky-labs/cbor-php/src/OtherObject/TrueObject.php
vendored
Normal file
36
vendor/spomky-labs/cbor-php/src/OtherObject/TrueObject.php
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use CBOR\Normalizable;
|
||||
use CBOR\OtherObject as Base;
|
||||
|
||||
final class TrueObject extends Base implements Normalizable
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(self::OBJECT_TRUE, null);
|
||||
}
|
||||
|
||||
public static function create(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public static function supportedAdditionalInformation(): array
|
||||
{
|
||||
return [self::OBJECT_TRUE];
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data): Base
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public function normalize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
40
vendor/spomky-labs/cbor-php/src/OtherObject/UndefinedObject.php
vendored
Normal file
40
vendor/spomky-labs/cbor-php/src/OtherObject/UndefinedObject.php
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CBOR\OtherObject;
|
||||
|
||||
use CBOR\Normalizable;
|
||||
use CBOR\OtherObject as Base;
|
||||
|
||||
final class UndefinedObject extends Base implements Normalizable
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(self::OBJECT_UNDEFINED, null);
|
||||
}
|
||||
|
||||
public static function create(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public static function supportedAdditionalInformation(): array
|
||||
{
|
||||
return [self::OBJECT_UNDEFINED];
|
||||
}
|
||||
|
||||
public static function createFromLoadedData(int $additionalInformation, ?string $data): Base
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP has no counterpart for the CBOR "undefined" simple value, so it normalizes to null. Use the object itself
|
||||
* when the distinction with an explicit CBOR "null" matters.
|
||||
*/
|
||||
public function normalize(): mixed
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue