20250712 1.1.1 Beta 4

This commit is contained in:
2025-07-12 16:27:53 +03:00
parent 3fbb7dc81c
commit 117deab9d8
9 changed files with 326 additions and 887 deletions

56
tests/data/D.php Normal file
View File

@@ -0,0 +1,56 @@
<?php
namespace goodboyalex\php_components_pack\tests\data;
use Closure;
use goodboyalex\php_components_pack\extensions\TypeExtension;
class D
{
public string $stringD;
public int $intD;
public bool $boolD;
public A $a;
public B $b;
public C $c;
public function __construct (string $string = "", int $int = 0, bool $bool = false, ?A $a = null, ?B $b = null,
?C $c = null)
{
$this->stringD = $string;
$this->intD = $int;
$this->boolD = $bool;
$this->a = $a ?? new A();
$this->b = $b ?? new B();
$this->c = $c ?? new C();
}
public static function CLOSURE_FROM_ARRAY (): Closure
{
return fn (array $classArray): object
=> $classArray['type_class'] == C::class
? self::CLOSURE_FROM_FOR_C($classArray["type_value"]) : TypeExtension::FromArray($classArray);
}
private static function CLOSURE_FROM_FOR_C (string $serializedC): object
{
$classC = new C();
$classC->UnSerialize($serializedC);
return $classC;
}
public static function CLOSURE_TO_ARRAY (): Closure
{
return fn (object $class): array => $class instanceof C ? self::CLOSURE_TO_FOR_C($class)
: TypeExtension::ToArray($class);
}
private static function CLOSURE_TO_FOR_C (C $class): array
{
return [
"type_class" => C::class,
"type_value" => $class->Serialize()
];
}
}