🚧 Add complex types from docs

This commit is contained in:
Shikiryu 2023-04-12 00:28:14 +02:00
parent cb6fff0dae
commit cc7a1ec831
8 changed files with 283 additions and 14 deletions

View File

@ -3,6 +3,8 @@
namespace Shikiryu\SRSS\Entity;
use ReflectionException;
use Shikiryu\SRSS\Entity\Channel\Category;
use Shikiryu\SRSS\Entity\Channel\Cloud;
use Shikiryu\SRSS\Entity\Channel\Image;
use Shikiryu\SRSS\Validator\HasValidator;
use Shikiryu\SRSS\Validator\Validator;
@ -54,9 +56,9 @@ class Channel extends HasValidator implements SRSSElement
*/
public ?string $lastBuildDate = null;
/**
* TODO should be an array
* @var Category[]
*/
public ?string $category = null;
public ?array $category = null;
/**
* @nohtml
*/
@ -66,10 +68,9 @@ class Channel extends HasValidator implements SRSSElement
*/
public ?string $docs = null;
/**
* @var string|null
* TODO validator
* @var Cloud|null
*/
public ?string $cloud = null;
public ?Cloud $cloud = null;
/**
* @int
*/

View File

@ -0,0 +1,33 @@
<?php
namespace Shikiryu\SRSS\Entity\Channel;
use Shikiryu\SRSS\Entity\SRSSElement;
use Shikiryu\SRSS\Validator\HasValidator;
use Shikiryu\SRSS\Validator\Validator;
class Category extends HasValidator implements SRSSElement
{
/**
* @string
*/
public string $domain;
/**
* @string
*/
public string $value;
public function isValid(): bool
{
try {
return (new Validator())->isObjectValid($this);
} catch (\ReflectionException $e) {
return false;
}
}
public function toArray(): array
{
return get_object_vars($this);
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace Shikiryu\SRSS\Entity\Channel;
use Shikiryu\SRSS\Entity\SRSSElement;
use Shikiryu\SRSS\Validator\HasValidator;
use Shikiryu\SRSS\Validator\Validator;
class Cloud extends HasValidator implements SRSSElement
{
/**
* @string
*/
public string $domain;
/**
* @int
*/
public int $port;
/**
* @string
*/
public string $path;
/**
* @string
*/
public string $registerProcedure;
/**
* @string
*/
public string $protocol;
//<cloud domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="myCloud.rssPleaseNotify" protocol="xml-rpc" />
public function isValid(): bool
{
try {
return (new Validator())->isObjectValid($this);
} catch (\ReflectionException $e) {
return false;
}
}
public function toArray(): array
{
return get_object_vars($this);
}
}

View File

@ -2,6 +2,9 @@
namespace Shikiryu\SRSS\Entity;
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;
@ -28,27 +31,28 @@ class Item extends HasValidator implements SRSSElement
* @email
*/
public ?string $author = null;
/*
* TODO can be multiple with attributes and all
/**
* @var Category[]
*/
public ?string $category = null;
public ?array $category = null;
/**
* @url
*/
public ?string $comments = null;
/*
* TODO 1 attributes and 1 value
/**
* @var Enclosure|null
*/
public ?string $enclosure = null;
public ?Enclosure $enclosure = null;
public ?string $guid = null;
/**
* @date
*/
public ?string $pubDate = null;
/*
* TODO 1 attributes and 1 value
/**
* @var Source|null
*/
public ?string $source = null;
public ?Source $source = null;
/**
* @var Content[]

View File

@ -0,0 +1,33 @@
<?php
namespace Shikiryu\SRSS\Entity\Item;
use Shikiryu\SRSS\Entity\SRSSElement;
use Shikiryu\SRSS\Validator\HasValidator;
use Shikiryu\SRSS\Validator\Validator;
class Category extends HasValidator implements SRSSElement
{
/**
* @string
*/
public string $domain;
/**
* @string
*/
public string $value;
public function isValid(): bool
{
try {
return (new Validator())->isObjectValid($this);
} catch (\ReflectionException $e) {
return false;
}
}
public function toArray(): array
{
return get_object_vars($this);
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Shikiryu\SRSS\Entity\Item;
use Shikiryu\SRSS\Entity\SRSSElement;
use Shikiryu\SRSS\Validator\HasValidator;
use Shikiryu\SRSS\Validator\Validator;
class Enclosure extends HasValidator implements SRSSElement
{
/**
* @url
*/
public string $url;
/**
* @int
*/
public int $length;
/**
* @mediaType
*/
public string $type;
public function isValid(): bool
{
try {
return (new Validator())->isObjectValid($this);
} catch (\ReflectionException $e) {
return false;
}
}
public function toArray(): array
{
return get_object_vars($this);
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace Shikiryu\SRSS\Entity\Item;
use Shikiryu\SRSS\Entity\SRSSElement;
use Shikiryu\SRSS\Validator\HasValidator;
use Shikiryu\SRSS\Validator\Validator;
class Source extends HasValidator implements SRSSElement
{
/**
* @url
*/
public string $url;
/**
* @nohtml
*/
public string $source;
public function isValid(): bool
{
try {
return (new Validator())->isObjectValid($this);
} catch (\ReflectionException $e) {
return false;
}
}
public function toArray(): array
{
return get_object_vars($this);
}
}

78
tests/resources/cloud.xml Normal file
View File

@ -0,0 +1,78 @@
<?xml version="1.0"?>
<!-- RSS generated by Radio UserLand v8.0.5 on Mon, 13 Oct 2003 18:54:10 GMT -->
<rss version="2.0">
<channel>
<title>Dave&apos;s Handsome Radio Blog!</title>
<link>http://radio.weblogs.com/0001015/</link>
<description>A non-smoking weblog since June 14, 2002.</description>
<language>en-us</language>
<copyright>Copyright 2003 Dave Winer</copyright>
<lastBuildDate>Mon, 13 Oct 2003 18:54:10 GMT</lastBuildDate>
<docs>http://backend.userland.com/rss</docs>
<generator>Radio UserLand v8.0.5</generator>
<managingEditor>dave@userland.com</managingEditor>
<webMaster>dave@userland.com</webMaster>
<category domain="http://www.weblogs.com/rssUpdates/changes.xml">rssUpdates</category>
<skipHours>
<hour>0</hour>
<hour>23</hour>
<hour>1</hour>
<hour>2</hour>
<hour>3</hour>
<hour>22</hour>
<hour>17</hour>
<hour>11</hour>
</skipHours>
<cloud domain="radio.xmlstoragesystem.com" port="80" path="/RPC2" registerProcedure="xmlStorageSystem.rssPleaseNotify" protocol="xml-rpc"/>
<ttl>60</ttl>
<item>
<link>http://radio.weblogs.com/0001015/2003/10/13.html#a1866</link>
<description>&lt;A href=&quot;http://andrea.editthispage.com/&quot;&gt;&lt;IMG height=100 alt=&quot;A picture named andrea.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/13/andrea.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://andrea.editthispage.com/&quot;&gt;&lt;IMG height=100 alt=&quot;A picture named andrea.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/13/andrea.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://andrea.editthispage.com/&quot;&gt;&lt;IMG height=100 alt=&quot;A picture named andrea.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/13/andrea.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://andrea.editthispage.com/&quot;&gt;&lt;IMG height=100 alt=&quot;A picture named andrea.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/13/andrea.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://andrea.editthispage.com/&quot;&gt;&lt;IMG height=100 alt=&quot;A picture named andrea.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/13/andrea.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;</description>
<guid>http://radio.weblogs.com/0001015/2003/10/13.html#a1866</guid>
<pubDate>Mon, 13 Oct 2003 18:54:09 GMT</pubDate>
<comments>http://blogs.law.harvard.edu/comments?u=1015&amp;amp;p=1866&amp;amp;link=http%3A%2F%2Fradio.weblogs.com%2F0001015%2F2003%2F10%2F13.html%23a1866</comments>
</item>
<item>
<link>http://radio.weblogs.com/0001015/2003/10/12.html#a1865</link>
<description>&lt;A href=&quot;http://blogs.law.harvard.edu/crimson1/pictures/viewer$747&quot;&gt;&lt;IMG height=89 alt=&quot;A picture named cousinJoey.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/12/cousinJoey.jpg&quot; width=65 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://blogs.law.harvard.edu/crimson1/pictures/viewer$747&quot;&gt;&lt;IMG height=89 alt=&quot;A picture named cousinJoey.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/12/cousinJoey.jpg&quot; width=65 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://blogs.law.harvard.edu/crimson1/pictures/viewer$747&quot;&gt;&lt;IMG height=89 alt=&quot;A picture named cousinJoey.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/12/cousinJoey.jpg&quot; width=65 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://blogs.law.harvard.edu/crimson1/pictures/viewer$747&quot;&gt;&lt;IMG height=89 alt=&quot;A picture named cousinJoey.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/12/cousinJoey.jpg&quot; width=65 align=right vspace=5 border=0&gt;&lt;/A&gt;</description>
<guid>http://radio.weblogs.com/0001015/2003/10/12.html#a1865</guid>
<pubDate>Sun, 12 Oct 2003 20:42:30 GMT</pubDate>
<comments>http://blogs.law.harvard.edu/comments?u=1015&amp;amp;p=1865&amp;amp;link=http%3A%2F%2Fradio.weblogs.com%2F0001015%2F2003%2F10%2F12.html%23a1865</comments>
</item>
<item>
<link>http://radio.weblogs.com/0001015/2003/10/08.html#a1864</link>
<description>&lt;A href=&quot;http://radio.weblogs.com/0001015/images/2002/06/04/yourarespecial.gif&quot;&gt;&lt;IMG height=52 alt=&quot;You are so special.&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2002/06/04/mrrogers.gif&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://radio.weblogs.com/0001015/images/2002/06/04/yourarespecial.gif&quot;&gt;&lt;IMG height=52 alt=&quot;You are so special.&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2002/06/04/mrrogers.gif&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://radio.weblogs.com/0001015/images/2002/06/04/yourarespecial.gif&quot;&gt;&lt;IMG height=52 alt=&quot;You are so special.&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2002/06/04/mrrogers.gif&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://radio.weblogs.com/0001015/images/2002/06/04/yourarespecial.gif&quot;&gt;&lt;IMG height=52 alt=&quot;You are so special.&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2002/06/04/mrrogers.gif&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://radio.weblogs.com/0001015/images/2002/06/04/yourarespecial.gif&quot;&gt;&lt;IMG height=52 alt=&quot;You are so special.&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2002/06/04/mrrogers.gif&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;</description>
<guid>http://radio.weblogs.com/0001015/2003/10/08.html#a1864</guid>
<pubDate>Wed, 08 Oct 2003 13:22:16 GMT</pubDate>
<comments>http://blogs.law.harvard.edu/comments?u=1015&amp;amp;p=1864&amp;amp;link=http%3A%2F%2Fradio.weblogs.com%2F0001015%2F2003%2F10%2F08.html%23a1864</comments>
</item>
<item>
<link>http://radio.weblogs.com/0001015/2003/10/06.html#a1863</link>
<description>&lt;A href=&quot;http://www.state.gov/secretary/rm/2003/17300.htm&quot;&gt;&lt;IMG height=51 alt=&quot;A picture named powell.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/06/powell.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://www.state.gov/secretary/rm/2003/17300.htm&quot;&gt;&lt;IMG height=51 alt=&quot;A picture named powell.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/06/powell.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://www.state.gov/secretary/rm/2003/17300.htm&quot;&gt;&lt;IMG height=51 alt=&quot;A picture named powell.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/06/powell.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://www.state.gov/secretary/rm/2003/17300.htm&quot;&gt;&lt;IMG height=51 alt=&quot;A picture named powell.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/06/powell.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://www.state.gov/secretary/rm/2003/17300.htm&quot;&gt;&lt;IMG height=51 alt=&quot;A picture named powell.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/06/powell.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;</description>
<guid>http://radio.weblogs.com/0001015/2003/10/06.html#a1863</guid>
<pubDate>Mon, 06 Oct 2003 13:37:40 GMT</pubDate>
<comments>http://blogs.law.harvard.edu/comments?u=1015&amp;amp;p=1863&amp;amp;link=http%3A%2F%2Fradio.weblogs.com%2F0001015%2F2003%2F10%2F06.html%23a1863</comments>
</item>
<item>
<link>http://radio.weblogs.com/0001015/2003/10/01.html#a1862</link>
<description>&lt;A href=&quot;http://127.0.0.1:5335/xxx&quot;&gt;&lt;IMG height=80 alt=&quot;A picture named retard.gif&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/01/retard.gif&quot; width=53 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://127.0.0.1:5335/xxx&quot;&gt;&lt;IMG height=80 alt=&quot;A picture named retard.gif&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/01/retard.gif&quot; width=53 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://127.0.0.1:5335/xxx&quot;&gt;&lt;IMG height=80 alt=&quot;A picture named retard.gif&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/01/retard.gif&quot; width=53 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://127.0.0.1:5335/xxx&quot;&gt;&lt;IMG height=80 alt=&quot;A picture named retard.gif&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/01/retard.gif&quot; width=53 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://127.0.0.1:5335/xxx&quot;&gt;&lt;IMG height=80 alt=&quot;A picture named retard.gif&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/10/01/retard.gif&quot; width=53 align=right vspace=5 border=0&gt;&lt;/A&gt;</description>
<guid>http://radio.weblogs.com/0001015/2003/10/01.html#a1862</guid>
<pubDate>Wed, 01 Oct 2003 18:26:11 GMT</pubDate>
<comments>http://blogs.law.harvard.edu/comments?u=1015&amp;amp;p=1862&amp;amp;link=http%3A%2F%2Fradio.weblogs.com%2F0001015%2F2003%2F10%2F01.html%23a1862</comments>
</item>
<item>
<link>http://radio.weblogs.com/0001015/2003/09/26.html#a1861</link>
<description>&lt;A href=&quot;http://127.0.0.1:5335/xxx&quot;&gt;&lt;IMG height=77 alt=&quot;A picture named allen.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/09/26/allen.jpg&quot; width=65 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://127.0.0.1:5335/xxx&quot;&gt;&lt;IMG height=77 alt=&quot;A picture named allen.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/09/26/allen.jpg&quot; width=65 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://127.0.0.1:5335/xxx&quot;&gt;&lt;IMG height=77 alt=&quot;A picture named allen.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/09/26/allen.jpg&quot; width=65 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://127.0.0.1:5335/xxx&quot;&gt;&lt;IMG height=77 alt=&quot;A picture named allen.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/09/26/allen.jpg&quot; width=65 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://127.0.0.1:5335/xxx&quot;&gt;&lt;IMG height=77 alt=&quot;A picture named allen.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/09/26/allen.jpg&quot; width=65 align=right vspace=5 border=0&gt;&lt;/A&gt;</description>
<guid>http://radio.weblogs.com/0001015/2003/09/26.html#a1861</guid>
<pubDate>Fri, 26 Sep 2003 13:29:36 GMT</pubDate>
<comments>http://blogs.law.harvard.edu/comments?u=1015&amp;amp;p=1861&amp;amp;link=http%3A%2F%2Fradio.weblogs.com%2F0001015%2F2003%2F09%2F26.html%23a1861</comments>
</item>
<item>
<link>http://radio.weblogs.com/0001015/2003/09/25.html#a1860</link>
<description>&lt;A href=&quot;http://www.command-post.org/2004/2_archives/008524.html&quot;&gt;&lt;IMG height=61 alt=&quot;A picture named clark.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/09/25/clark.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://www.command-post.org/2004/2_archives/008524.html&quot;&gt;&lt;IMG height=61 alt=&quot;A picture named clark.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/09/25/clark.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://www.command-post.org/2004/2_archives/008524.html&quot;&gt;&lt;IMG height=61 alt=&quot;A picture named clark.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/09/25/clark.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://www.command-post.org/2004/2_archives/008524.html&quot;&gt;&lt;IMG height=61 alt=&quot;A picture named clark.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/09/25/clark.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;&lt;A href=&quot;http://www.command-post.org/2004/2_archives/008524.html&quot;&gt;&lt;IMG height=61 alt=&quot;A picture named clark.jpg&quot; hspace=15 src=&quot;http://radio.weblogs.com/0001015/images/2003/09/25/clark.jpg&quot; width=45 align=right vspace=5 border=0&gt;&lt;/A&gt;</description>
<guid>http://radio.weblogs.com/0001015/2003/09/25.html#a1860</guid>
<pubDate>Thu, 25 Sep 2003 14:08:26 GMT</pubDate>
<comments>http://blogs.law.harvard.edu/comments?u=1015&amp;amp;p=1860&amp;amp;link=http%3A%2F%2Fradio.weblogs.com%2F0001015%2F2003%2F09%2F25.html%23a1860</comments>
</item>
</channel>
</rss>