'required', 'email' => 'permit_empty|valid_email', 'url' => 'permit_empty|valid_url_strict', ]; protected const AUTHOR_STRING_PATTERN = '/^(?[^<>()]*)\s*(<(?.*)>)?\s*(\((?.*)\))?$/'; /** * @var array */ protected const CASTS = [ 'url' => URI::class, ]; protected string $name; protected ?string $email = null; protected ?URI $url = null; public function __construct(array|string $data) { if (is_string($data)) { $result = preg_match(self::AUTHOR_STRING_PATTERN, $data, $matches); if (! $result) { throw new Exception('Author string is not valid.'); } $data = [ 'name' => $matches['name'], 'email' => $matches['email'] ?? null, 'url' => $matches['url'] ?? null, ]; } parent::__construct($data); } }