2024-04-09 12:31:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Lib\Definitions;
|
|
|
|
|
|
|
|
|
|
use App\Enums\Settings\MenuNodeType;
|
|
|
|
|
use App\Lib\Link;
|
|
|
|
|
|
|
|
|
|
/**
|
2024-04-25 11:48:49 +02:00
|
|
|
* @property-read string $type The node menu type.
|
|
|
|
|
* @property-read string $title The node menu title.
|
|
|
|
|
* @property-read \App\Lib\Link $link The node menu link.
|
|
|
|
|
* @property-read boolean $published The node menu publish status.
|
2024-04-09 12:31:45 +02:00
|
|
|
* @package App\Lib\Definitions
|
|
|
|
|
*/
|
|
|
|
|
class MenuNode extends \stdClass
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Get property
|
|
|
|
|
*
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws \TypeError If prop is undefined.
|
|
|
|
|
*/
|
|
|
|
|
public function __get(string $name)
|
|
|
|
|
{
|
2024-04-25 11:48:49 +02:00
|
|
|
if (in_array($name, ['type', 'title', 'link', 'published'])) {
|
2024-04-09 12:31:45 +02:00
|
|
|
return $this->{$name};
|
|
|
|
|
}
|
|
|
|
|
throw new \TypeError("undefined property {$name}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make and instance
|
|
|
|
|
*
|
2024-04-25 11:48:49 +02:00
|
|
|
* @param integer $type The node menu type.
|
|
|
|
|
* @param boolean $published The node menu published.
|
|
|
|
|
* @param string $title The node menu title.
|
|
|
|
|
* @param array $link The node menu link.
|
2024-04-09 12:31:45 +02:00
|
|
|
* @return \App\Lib\Definitions\MenuNode
|
|
|
|
|
* @throws \RuntimeException If $type or $data is wrong.
|
|
|
|
|
*/
|
2024-04-25 11:48:49 +02:00
|
|
|
public static function make(int $type, bool $published, string $title, array $link): self
|
2024-04-09 12:31:45 +02:00
|
|
|
{
|
|
|
|
|
self::assertTypeIsCorrect($type);
|
|
|
|
|
|
|
|
|
|
$menuNode = new self();
|
|
|
|
|
// @phpstan-ignore-next-line
|
|
|
|
|
$menuNode->type = MenuNodeType::make($type);
|
|
|
|
|
// @phpstan-ignore-next-line
|
2024-04-25 11:48:49 +02:00
|
|
|
$menuNode->published = $published;
|
|
|
|
|
// @phpstan-ignore-next-line
|
2024-04-11 09:37:38 +02:00
|
|
|
$menuNode->title = $title;
|
|
|
|
|
// @phpstan-ignore-next-line
|
2024-04-09 12:31:45 +02:00
|
|
|
$menuNode->link = new Link(...$link);
|
|
|
|
|
return $menuNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assert Type is correct
|
|
|
|
|
*
|
|
|
|
|
* @param integer $type
|
|
|
|
|
* @return void
|
|
|
|
|
* @throws \RuntimeException If $type is wrong.
|
|
|
|
|
*/
|
|
|
|
|
public static function assertTypeIsCorrect(int $type)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$type = MenuNodeType::make($type);
|
|
|
|
|
} catch (\BadMethodCallException $e) {
|
|
|
|
|
throw new \RuntimeException($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|