Try to get stuff working
This commit is contained in:
43
src/Model/Metadata.php
Normal file
43
src/Model/Metadata.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pcm\MetadataBundle\Model;
|
||||
|
||||
use App\Exception\Dto\Metadata\MissingKeyException;
|
||||
use App\Interface\Dto\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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user