2018-04-15 02:05:41 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\MetadataResolver;
|
|
|
|
|
2019-01-15 23:56:04 +09:00
|
|
|
use Carbon\Carbon;
|
|
|
|
|
2018-04-15 02:05:41 +09:00
|
|
|
class Metadata
|
|
|
|
{
|
2019-04-29 12:26:29 +09:00
|
|
|
/** @var string タイトル */
|
2018-04-15 02:05:41 +09:00
|
|
|
public $title = '';
|
2019-04-29 12:26:29 +09:00
|
|
|
|
|
|
|
/** @var string 概要 */
|
2018-04-15 02:05:41 +09:00
|
|
|
public $description = '';
|
2019-04-29 12:26:29 +09:00
|
|
|
|
|
|
|
/** @var string サムネイルのURL */
|
2018-04-15 02:05:41 +09:00
|
|
|
public $image = '';
|
2019-04-29 12:26:29 +09:00
|
|
|
|
|
|
|
/** @var Carbon|null メタデータの有効期限 */
|
2019-01-15 23:56:04 +09:00
|
|
|
public $expires_at = null;
|
2019-04-29 12:26:29 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string[] タグ
|
|
|
|
* チェックインタグと同様に保存されるため、スペースや改行文字を含めてはいけません。
|
|
|
|
*/
|
|
|
|
public $tags = [];
|
2020-02-22 14:39:25 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 重複を排除し、正規化を行ったタグの集合を返します。
|
|
|
|
* @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);
|
|
|
|
}
|
2019-01-15 00:05:01 +09:00
|
|
|
}
|