Files
pcm-metadata-bundle/src/Model/Metadata.php
2025-11-27 14:54:54 +00:00

44 lines
856 B
PHP

<?php
declare(strict_types=1);
namespace Pcm\MetadataBundle\Model;
use Pcm\MetadataBundle\Exception\MissingKeyException;
use Pcm\MetadataBundle\Interface\MetadataInterface;
/**
* Store scalar metadata on an entity.
*/
final class Metadata implements MetadataInterface
{
/**
* @param array<string, scalar|scalar[]> &$metadata
*/
public function __construct(private array &$metadata)
{
}
public function get(string $key): mixed
{
if (!$this->has($key)) {
throw new MissingKeyException($key);
}
return $this->metadata[$key];
}
public function set(string $key, mixed $value): static
{
$this->metadata[$key] = $value;
return $this;
}
public function has(string $key): bool
{
return array_key_exists($key, $this->metadata);
}
}