Files
kupshop/bundles/KupShop/ContentBundle/Entity/Placeholder.php
2025-08-02 16:30:27 +02:00

41 lines
810 B
PHP

<?php
declare(strict_types=1);
namespace KupShop\ContentBundle\Entity;
class Placeholder implements \JsonSerializable
{
protected string $valueCache;
public function __construct(
public string $code,
public string $description,
public \Closure $loader,
) {
}
public function getValue(): string
{
if (!isset($this->valueCache)) {
$this->valueCache = (string) ($this->loader)() ?? '';
}
return $this->valueCache;
}
public function __serialize(): array
{
return [
'code' => $this->code,
'description' => $this->description,
'value' => $this->getValue(),
];
}
public function jsonSerialize(): mixed
{
return $this->__serialize();
}
}