Use setter function when setting artwork tags

This commit is contained in:
Alex Cabal 2024-01-09 11:28:38 -06:00
parent 8a82524de7
commit 716fc8bea9
2 changed files with 23 additions and 21 deletions

View file

@ -56,6 +56,27 @@ class Artwork extends PropertiesBase{
protected ?User $_Reviewer = null;
protected ?ImageMimeType $_MimeType = null;
// *******
// SETTERS
// *******
protected function SetTags(string|array|null $tags): void{
if($tags === null || is_array($tags)){
$this->_Tags = $tags;
}
elseif(is_string($tags)){
$tags = array_map('trim', explode(',', $tags));
$tags = array_values(array_filter($tags));
$tags = array_unique($tags);
$this->_Tags = array_map(function ($str){
$tag = new ArtworkTag();
$tag->Name = $str;
return $tag;
}, $tags);
}
}
// *******
// GETTERS
// *******
@ -382,21 +403,6 @@ class Artwork extends PropertiesBase{
}
}
/** @return array<ArtworkTag> */
public static function ParseTags(?string $tags): array{
if(!$tags) return [];
$tags = array_map('trim', explode(',', $tags));
$tags = array_values(array_filter($tags));
$tags = array_unique($tags);
return array_map(function ($str){
$tag = new ArtworkTag();
$tag->Name = $str;
return $tag;
}, $tags);
}
/**
* @param array<mixed> $uploadedFile
* @throws \Exceptions\ValidationException