WIP on document conversion
This commit is contained in:
71
src/lib/Domain/Feed.php
Normal file
71
src/lib/Domain/Feed.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace FeedReaderCentral\Domain;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Exception;
|
||||
use FeedReaderCentral\Data;
|
||||
use FeedReaderCentral\Key;
|
||||
|
||||
/**
|
||||
* An RSS or Atom feed
|
||||
*/
|
||||
class Feed
|
||||
{
|
||||
/** @var int The ID of the feed */
|
||||
public int $id = 0;
|
||||
|
||||
/** @var int The ID of the user to whom this subscription belongs */
|
||||
public int $user_id = 0;
|
||||
|
||||
/** @var string The URL of the feed */
|
||||
public string $url = '';
|
||||
|
||||
/** @var string|null The title of this feed */
|
||||
public ?string $title = null;
|
||||
|
||||
/** @var string|null The date/time items in this feed were last updated */
|
||||
public ?string $updated_on = null;
|
||||
|
||||
/** @var string|null The date/time this feed was last checked */
|
||||
public ?string $checked_on = null;
|
||||
|
||||
/**
|
||||
* The date/time items in this feed were last updated
|
||||
*
|
||||
* @return DateTimeImmutable|null The updated date, or null if it is not set
|
||||
* @throws Exception If the date/time is an invalid format
|
||||
*/
|
||||
public function updatedOn(): ?DateTimeImmutable
|
||||
{
|
||||
return is_null($this->updated_on) ? null : new DateTimeImmutable($this->updated_on);
|
||||
}
|
||||
|
||||
/**
|
||||
* The date/time this feed was last checked
|
||||
*
|
||||
* @return DateTimeImmutable|null The last checked date, or null if it is not set
|
||||
* @throws Exception If the date/time is an invalid format
|
||||
*/
|
||||
public function checkedOn(): ?DateTimeImmutable
|
||||
{
|
||||
return is_null($this->checked_on) ? null : new DateTimeImmutable($this->checked_on);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a document from the parsed feed
|
||||
*
|
||||
* @param \FeedReaderCentral\Feed $feed The parsed feed
|
||||
* @return static The document constructed from the parsed feed
|
||||
*/
|
||||
public static function fromParsed(\FeedReaderCentral\Feed $feed): static
|
||||
{
|
||||
$it = new static();
|
||||
$it->user_id = $_SESSION[Key::USER_ID];
|
||||
$it->url = $feed->url;
|
||||
$it->title = $feed->title;
|
||||
$it->updated_on = $feed->updatedOn;
|
||||
$it->checked_on = Data::formatDate('now');
|
||||
|
||||
return $it;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user