🦺 Add validator

This commit is contained in:
Shikiryu committed 2023-04-07 00:35:20 +02:00
1 parent bc0e818bbc
commit fec8c122e3
9 files changed
+276 -55

No files matched your search

+84 -20
View File
@@ -2,39 +2,103 @@
namespace Shikiryu\SRSS\Entity;
use ReflectionException;
use Shikiryu\SRSS\Entity\Channel\Image;
use Shikiryu\SRSS\Validator\HasValidator;
use Shikiryu\SRSS\Validator\Validator;
class Channel implements SRSSElement
/**
* https://cyber.harvard.edu/rss/rss.html#requiredChannelElements
*/
class Channel extends HasValidator implements SRSSElement
{
/**
* @required
* @nohtml
*/
public string $title;
/**
* @required
* @url
*/
public string $link;
/**
* @required
*/
public string $description;
public ?string $language;
public ?string $copyright;
public ?string $managingEditor;
public ?string $webMaster;
public ?string $pubDate;
public ?string $lastBuildDate;
public ?string $category;
public ?string $generator;
public ?string $docs;
public ?string $cloud;
public ?string $ttl;
public ?Image $image;
public ?string $rating;
public ?string $textInput;
public ?string $skipHours;
public ?string $skipDays;
public array $required = ['title', 'link', 'description'];
/**
* @lang
*/
public ?string $language = null;
/**
* @nohtml
*/
public ?string $copyright = null;
/**
* @nohtml
*/
public ?string $managingEditor = null;
/**
* @nohtml
*/
public ?string $webMaster = null;
/**
* @date
*/
public ?string $pubDate = null;
/**
* @date
*/
public ?string $lastBuildDate = null;
/**
* TODO should be an array
*/
public ?string $category = null;
/**
* @nohtml
*/
public ?string $generator = null;
/**
* @url
*/
public ?string $docs = null;
/**
* @var string|null
* TODO validator
*/
public ?string $cloud = null;
/**
* @int
*/
public ?string $ttl = null;
public ?Image $image = null;
public ?string $rating = null;
/**
* @var string|null
* The purpose of the <textInput> element is something of a mystery. You can use it to specify a search engine box. Or to allow a reader to provide feedback. Most aggregators ignore it.
*/
public ?string $textInput = null;
/**
* @hour
*/
public ?string $skipHours = null;
/**
* @day
*/
public ?string $skipDays = null;
/**
* @return bool
* @throws ReflectionException
*/
public function isValid(): bool
{
return count(array_filter($this->required, fn($field) => !empty($this->{$field}))) === 0;
$annotation_validation = new Validator();
return $annotation_validation->isObjectValid($this);
}
/**