J. King
4 years ago
8 changed files with 89 additions and 87 deletions
@ -0,0 +1,36 @@ |
|||
<?php |
|||
/** @license MIT |
|||
* Copyright 2018 J. King et al. |
|||
* See LICENSE and AUTHORS files for details */ |
|||
|
|||
declare(strict_types=1); |
|||
namespace MensBeam\Lax\Parser; |
|||
|
|||
use MensBeam\Lax\Feed as FeedStruct; |
|||
use MensBeam\Lax\Entry as EntryStruct; |
|||
|
|||
trait AbstractEntry { |
|||
public function __construct($data, FeedStruct $feed) { |
|||
$this->data = $data; |
|||
$this->feed = $feed; |
|||
$this->url = $feed->meta->url ? (string) $feed->meta->url : null; |
|||
} |
|||
|
|||
public function parse(EntryStruct $entry = null): EntryStruct { |
|||
$entry = $this->init($entry ?? new EntryStruct); |
|||
$entry->lang = $this->getLang(); |
|||
$entry->id = $this->getId(); |
|||
$entry->link = $this->getLink(); |
|||
$entry->relatedLink = $this->getRelatedLink(); |
|||
$entry->title = $this->getTitle(); |
|||
$entry->dateModified = $this->getDateModified(); |
|||
$entry->dateCreated = $this->getDateCreated(); |
|||
$entry->content = $this->getContent(); |
|||
$entry->summary = $this->getSummary(); |
|||
$entry->banner = $this->getBanner(); |
|||
$entry->people = $this->getPeople(); |
|||
$entry->categories = $this->getCategories(); |
|||
$entry->enclosures = $this->getEnclosures(); |
|||
return $entry; |
|||
} |
|||
} |
@ -0,0 +1,41 @@ |
|||
<?php |
|||
/** @license MIT |
|||
* Copyright 2018 J. King et al. |
|||
* See LICENSE and AUTHORS files for details */ |
|||
|
|||
declare(strict_types=1); |
|||
namespace MensBeam\Lax\Parser; |
|||
|
|||
use MensBeam\Lax\Url; |
|||
use MensBeam\Lax\Feed as FeedStruct; |
|||
|
|||
trait AbstractFeed { |
|||
/** Constructs a feed parser */ |
|||
public function __construct(string $data, string $contentType = null, string $url = null) { |
|||
$this->data = $data; |
|||
$this->contentType = $contentType; |
|||
if (strlen($url ?? "")) { |
|||
$this->url = $url; |
|||
} |
|||
} |
|||
|
|||
/** Parses the feed to extract data */ |
|||
public function parse(FeedStruct $feed = null): FeedStruct { |
|||
$feed = $this->init($feed ?? new FeedStruct); |
|||
$feed->meta->url = strlen($this->url ?? "") ? new Url($this->url) : null; |
|||
$feed->sched = $this->getSchedule(); |
|||
$feed->id = $this->getId(); |
|||
$feed->lang = $this->getLang(); |
|||
$feed->url = $this->getUrl(); |
|||
$feed->link = $this->getLink(); |
|||
$feed->title = $this->getTitle(); |
|||
$feed->summary = $this->getSummary(); |
|||
$feed->dateModified = $this->getDateModified(); |
|||
$feed->icon = $this->getIcon(); |
|||
$feed->image = $this->getImage(); |
|||
$feed->people = $this->getPeople(); |
|||
$feed->categories = $this->getCategories(); |
|||
$feed->entries = $this->getEntries($feed); |
|||
return $feed; |
|||
} |
|||
} |
Loading…
Reference in new issue