Separation of concerns
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user