タグを保存前に正規化する
This commit is contained in:
@@ -23,4 +23,30 @@ class Metadata
|
||||
* チェックインタグと同様に保存されるため、スペースや改行文字を含めてはいけません。
|
||||
*/
|
||||
public $tags = [];
|
||||
|
||||
/**
|
||||
* 重複を排除し、正規化を行ったタグの集合を返します。
|
||||
* @return string[]
|
||||
*/
|
||||
public function normalizedTags(): array
|
||||
{
|
||||
$tags = [];
|
||||
foreach ($this->tags as $tag) {
|
||||
$tag = $this->sanitize($tag);
|
||||
$tag = $this->trim($tag);
|
||||
$tags[$tag] = true;
|
||||
}
|
||||
|
||||
return array_keys($tags);
|
||||
}
|
||||
|
||||
private function sanitize(string $value): string
|
||||
{
|
||||
return preg_replace('/\r?\n/u', ' ', $value);
|
||||
}
|
||||
|
||||
private function trim(string $value): string
|
||||
{
|
||||
return trim($value);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user