20250721 1.2 Бета 1
This commit is contained in:
43
sources/traits/GUID/GUIDArrayableTrait.php
Normal file
43
sources/traits/GUID/GUIDArrayableTrait.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace goodboyalex\php_components_pack\traits\GUID;
|
||||
|
||||
use goodboyalex\php_components_pack\exceptions\TypeException;
|
||||
use goodboyalex\php_components_pack\types\GUID;
|
||||
|
||||
/**
|
||||
* Часть кода класса GUID, отвечающая за реализацию интерфейса IArrayable.
|
||||
*
|
||||
* @author Александр Бабаев
|
||||
* @package php_components_pack
|
||||
* @version 1.0
|
||||
* @since 1.2
|
||||
*/
|
||||
trait GUIDArrayableTrait
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function ToArray (): array
|
||||
{
|
||||
return [
|
||||
"type_class" => GUID::class,
|
||||
"value" => $this->Value
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws TypeException Если тип не соответствует.
|
||||
*/
|
||||
public function FromArray (array $array): void
|
||||
{
|
||||
// Проверка типа
|
||||
if (!isset($array["type_class"]) || $array["type_class"] != GUID::class)
|
||||
// - если тип не соответствует, выбрасываем исключение
|
||||
throw new TypeException($array["type_class"] ?? "", 'Неверный тип данных / Wrong data type.');
|
||||
|
||||
// Получаем значение GUID
|
||||
$this->Value = $array["value"];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user