1
0
mirror of https://github.com/Chouchen/ShikiryuRSS.git synced 2024-05-18 18:01:31 +02:00
ShikiryuRSS/src/Entity/Item.php

95 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace Shikiryu\SRSS\Entity;
2023-04-12 15:28:38 +02:00
use ReflectionException;
use Shikiryu\SRSS\Entity\Item\Category;
use Shikiryu\SRSS\Entity\Item\Enclosure;
use Shikiryu\SRSS\Entity\Item\Source;
use Shikiryu\SRSS\Entity\Media\Content;
use Shikiryu\SRSS\Validator\HasValidator;
use Shikiryu\SRSS\Validator\Validator;
/**
* https://cyber.harvard.edu/rss/rss.html#hrelementsOfLtitemgt
* @property null|string title
* @property null|string link
* @property null|string description
* @property null|string author
* @property null|array category
* @property null|string comments
* @property null|Enclosure enclosure
* @property null|string guid
* @property null|string pubDate
* @property null|Source source
* @property array medias
*/
class Item extends HasValidator implements SRSSElement
{
/**
2023-04-17 14:28:01 +02:00
* @validate requiredOr description
* @format html
*/
2023-04-17 14:28:01 +02:00
protected ?string $title = null;
/**
2023-04-17 14:28:01 +02:00
* @validate url
* @format url
*/
2023-04-17 14:28:01 +02:00
protected ?string $link = null;
/**
2023-04-17 14:28:01 +02:00
* @validate requiredOr title
* @format html
*/
2023-04-17 14:28:01 +02:00
protected ?string $description = null;
/**
2023-04-17 14:28:01 +02:00
* @validate email
* @format email
*/
2023-04-17 14:28:01 +02:00
protected ?string $author = null;
/**
* @var Category[]
*/
2023-04-17 14:28:01 +02:00
protected ?array $category = null;
/**
2023-04-17 14:28:01 +02:00
* @validate url
* @format url
*/
2023-04-17 14:28:01 +02:00
protected ?string $comments = null;
/**
* @var Enclosure|null
*/
2023-04-17 14:28:01 +02:00
protected ?Enclosure $enclosure = null;
protected ?string $guid = null;
/**
2023-04-17 14:28:01 +02:00
* @validate date
* @format date
*/
2023-04-17 14:28:01 +02:00
protected ?string $pubDate = null;
/**
* @var Source|null
*/
2023-04-17 14:28:01 +02:00
protected ?Source $source = null;
2023-04-06 11:07:06 +02:00
/**
* @var Content[]
* @contentMedia
2023-04-06 11:07:06 +02:00
*/
2023-04-17 14:28:01 +02:00
protected array $medias = [];
2023-04-06 11:07:06 +02:00
public function isValid(): bool
{
try {
return (new Validator())->isObjectValid($this);
2023-04-12 15:28:38 +02:00
} catch (ReflectionException) {
return false;
}
2023-04-06 11:07:06 +02:00
}
public function toArray(): array
{
$vars = get_object_vars($this);
unset($vars['validated']);
return $vars;
2023-04-06 11:07:06 +02:00
}
}