Separation of concerns

This commit is contained in:
2021-04-08 15:36:57 +02:00
parent cc2696668c
commit afff03166e
15 changed files with 155 additions and 96 deletions

View File

@@ -31,19 +31,28 @@ class Metadata
public ?string $title = null;
public ?string $userproperties = null;
public function fillWith(array $array): Metadata
private function __construct(array $array)
{
$slugify = new Slugify(['separator' => '_']);
$notEmpty = static fn(string $v) => trim($v) !== '';
$array = array_filter($array, static fn(string $v) => trim($v) !== '');
$array = array_filter($array, $notEmpty);
foreach ($array as $key => $value) {
$key = $slugify->slugify($key);
if (property_exists(__CLASS__, $key)) {
$this->{$key} = trim($value);
}
}
}
return $this;
public static function fill(array $data): Metadata
{
return new self($data);
}
public static function empty(): Metadata
{
return new self([]);
}
public function toArray(): array