✨ Starts refactoring reader

Still missing media:group
This commit is contained in:
Shikiryu committed 2023-04-06 00:38:26 +02:00
1 parent a55b05d734
commit 4783124a1d
12 files changed
+288 -111

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Shikiryu\SRSS\Entity;
use Shikiryu\SRSS\Entity\Channel\Image;
class Channel
{
public string $title;
public string $link;
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'];
}
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace Shikiryu\SRSS\Entity\Channel;
class Image
{
public string $url;
public string $title;
public string $link;
public int $width; // Maximum value for width is 144, default value is 88.
public int $height; //Maximum value for height is 400, default value is 31.
public string $description;
public array $required = ['url', 'title', 'link'];
}
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace Shikiryu\SRSS\Entity;
class Item
{
public ?string $title;
public ?string $link;
public ?string $description;
public ?string $author;
public ?string $category;
public ?string $comments;
public ?string $enclosure;
public ?string $guid;
public ?string $pubDate;
public ?string $source;
public array $required = ['description'];
}
+125
View File
@@ -0,0 +1,125 @@
<?php
namespace Shikiryu\SRSS\Entity\Media;
use DOMDocument;
use DOMElement;
use DOMNode;
use Shikiryu\SRSS\SRSSException;
use Shikiryu\SRSS\SRSSTools;
class Content extends DomDocument
{
protected array $possibilities = [
'url' => 'link',
'fileSize' => 'int', // TODO
'type' => 'media_type', // TODO
'medium' => 'media_medium', // TODO
'isDefault' => 'bool', // TODO
'expression' => 'medium_expression', // TODO
'bitrate' => 'int',
'framerate' => 'int',
'samplingrate' => 'float',
'channels' => 'int',
'duration' => 'int',
'height' => 'int',
'width' => 'int',
'lang' => '',
];
private array $attr = [];
private DOMNode $node;
/**
* Constructor
*
* @param DomNode $node
*/
public function __construct(?\DOMNode $node = null)
{
parent::__construct();
if ($node instanceof DOMElement) {
$this->node = $this->importNode($node, true);
} else {
$this->node = $this->importNode(new DomElement('item'));
}
$this->_loadAttributes();
}
/**
* @return void
*/
private function _loadAttributes(): void
{
foreach ($this->node->attributes as $attributes) {
if (array_key_exists($attributes->name, $this->possibilities)) {
$this->{$attributes->name} = $attributes->value;
}
}
}
/**
* main getter for properties
*
* @param $name
*
* @return null|string
* @throws SRSSException
*/
public function __get($name)
{
if (array_key_exists($name, $this->attr)) {
return $this->attr[$name];
}
if (array_key_exists($name, $this->possibilities)) {
$tmp = $this->node->getElementsByTagName($name);
if ($tmp->length !== 1) {
return null;
}
return $tmp->item(0)->nodeValue;
}
throw new SRSSException(sprintf('%s is not a possible item (%s)', $name, implode(', ', array_keys($this->possibilities))));
}
/**
* @param $name
*
* @return bool
*/
public function __isset($name)
{
return isset($this->attr[$name]);
}
/**
* main setter for properties
*
* @param $name
* @param $val
*
* @throws SRSSException
*/
public function __set($name, $val)
{
if (!array_key_exists($name, $this->possibilities)) {
throw new SRSSException(sprintf('%s is not a possible item (%s)', $name, implode(', ', array_keys($this->possibilities))));
}
$flag = $this->possibilities[$name];
if ($flag !== '') {
$val = SRSSTools::check($val, $flag);
}
if (!empty($val)) {
if ($this->$name === null) {
$this->node->appendChild(new DomElement($name, $val));
}
$this->attr[$name] = $val;
}
}
}
+8
View File
@@ -0,0 +1,8 @@
<?php
namespace Shikiryu\SRSS\Entity\Media;
class Group
{
}