mirror of
https://code.castopod.org/adaures/castopod
synced 2025-05-13 17:55:47 +00:00

- enhance plugin card ui - refactor components to be more consistent - invert toggler label for better UX - edit view components regex
57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Plugins\Manifest;
|
|
|
|
use CodeIgniter\HTTP\URI;
|
|
use Exception;
|
|
|
|
/**
|
|
* @property string $name
|
|
* @property ?string $email
|
|
* @property ?URI $url
|
|
*/
|
|
class Person extends ManifestObject
|
|
{
|
|
protected const VALIDATION_RULES = [
|
|
'name' => 'required',
|
|
'email' => 'permit_empty|valid_email',
|
|
'url' => 'permit_empty|valid_url_strict',
|
|
];
|
|
|
|
protected const AUTHOR_STRING_PATTERN = '/^(?<name>[^<>()]*)\s*(<(?<email>.*)>)?\s*(\((?<url>.*)\))?$/';
|
|
|
|
/**
|
|
* @var array<string,array{string}|string>
|
|
*/
|
|
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'],
|
|
'url' => $matches['url'],
|
|
];
|
|
}
|
|
|
|
parent::__construct($data);
|
|
}
|
|
}
|