Browse Source

Initial API redesign

Lots of things are probably (still) broken
master
J. King 4 years ago
parent
commit
378e924541
  1. 5
      .gitignore
  2. 5
      composer.json
  3. 67
      composer.lock
  4. 6
      lib/Category/Collection.php
  5. 47
      lib/Entry.php
  6. 57
      lib/Feed.php
  7. 3
      lib/Parser/Construct.php
  8. 36
      lib/Parser/Entry.php
  9. 39
      lib/Parser/Feed.php
  10. 7
      lib/Parser/JSON/Construct.php
  11. 26
      lib/Parser/JSON/Entry.php
  12. 24
      lib/Parser/JSON/Feed.php
  13. 3
      lib/Parser/JSON/Primitives/Construct.php
  14. 4
      lib/Parser/XML/Construct.php
  15. 23
      lib/Parser/XML/Entry.php
  16. 24
      lib/Parser/XML/Feed.php
  17. 7
      lib/Parser/XML/Primitives/Construct.php
  18. 5
      lib/Parser/XML/Primitives/Entry.php
  19. 5
      lib/Parser/XML/Primitives/Feed.php
  20. 2
      lib/Parser/XML/XPath.php
  21. 5
      vendor-bin/phpunit/composer.json
  22. 1600
      vendor-bin/phpunit/composer.lock

5
.gitignore

@ -1,3 +1,2 @@
vendor
samples
test.php
/vendor
/vendor-bin/*/vendor

5
composer.json

@ -13,7 +13,7 @@
],
"require": {
"php": "^7.0",
"php": "^7.1",
"ext-json": "*",
"ext-dom": "*",
"ext-intl": "*",
@ -23,5 +23,8 @@
"psr-4": {
"JKingWeb\\Lax\\": "lib/"
}
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.3"
}
}

67
composer.lock

@ -1,31 +1,31 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "ddf62aa3f11d886da2b7ba796090469f",
"content-hash": "4591fe69b23762fb439aec3883d74eeb",
"packages": [
{
"name": "sabre/uri",
"version": "2.1.1",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/sabre-io/uri.git",
"reference": "a42126042c7dcb53e2978dadb6d22574d1359b4c"
"reference": "059d11012603be2e32ddb7543602965563ddbb09"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sabre-io/uri/zipball/a42126042c7dcb53e2978dadb6d22574d1359b4c",
"reference": "a42126042c7dcb53e2978dadb6d22574d1359b4c",
"url": "https://api.github.com/repos/sabre-io/uri/zipball/059d11012603be2e32ddb7543602965563ddbb09",
"reference": "059d11012603be2e32ddb7543602965563ddbb09",
"shasum": ""
},
"require": {
"php": ">=7"
"php": "^7.1"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"sabre/cs": "~1.0.0"
"friendsofphp/php-cs-fixer": "~2.16.1",
"phpunit/phpunit": "^7 || ^8"
},
"type": "library",
"autoload": {
@ -55,19 +55,60 @@
"uri",
"url"
],
"time": "2017-02-20T20:02:35+00:00"
"time": "2020-01-31T18:53:43+00:00"
}
],
"packages-dev": [
{
"name": "bamarni/composer-bin-plugin",
"version": "v1.3.0",
"source": {
"type": "git",
"url": "https://github.com/bamarni/composer-bin-plugin.git",
"reference": "67f9d314dc7ecf7245b8637906e151ccc62b8d24"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bamarni/composer-bin-plugin/zipball/67f9d314dc7ecf7245b8637906e151ccc62b8d24",
"reference": "67f9d314dc7ecf7245b8637906e151ccc62b8d24",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.0"
},
"require-dev": {
"composer/composer": "dev-master",
"symfony/console": "^2.5 || ^3.0 || ^4.0"
},
"type": "composer-plugin",
"extra": {
"class": "Bamarni\\Composer\\Bin\\Plugin",
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"autoload": {
"psr-4": {
"Bamarni\\Composer\\Bin\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"time": "2019-03-17T12:38:04+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^7.0",
"php": "^7.1",
"ext-json": "*",
"ext-dom": "*"
"ext-dom": "*",
"ext-intl": "*"
},
"platform-dev": []
}

6
lib/Category/Collection.php

@ -27,7 +27,7 @@ class Collection extends \JKingWeb\Lax\Collection {
// if the category is blank or already in the output, skip it
continue;
} else {
$out[] = text;
$out[] = $text;
}
}
return $out;
@ -35,11 +35,11 @@ class Collection extends \JKingWeb\Lax\Collection {
/** Returns a collection filtered to include only the specified category domains */
public function filterForDomain(string ...$domain): self {
return $this->filter($role, "domain", true);
return $this->filter($domain, "domain", true);
}
/** Returns a collection filtered to exclude the specified category domains */
public function filterOutDomain(string ...$domain): self {
return $this->filter($role, "domain", false);
return $this->filter($domain, "domain", false);
}
}

47
lib/Entry.php

@ -6,12 +6,7 @@
declare(strict_types=1);
namespace JKingWeb\Lax;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
abstract class Entry {
protected $feed;
class Entry {
public $link;
public $relatedLink;
public $title;
@ -21,44 +16,4 @@ abstract class Entry {
public $author;
public $dateModified;
public $dateCreated;
/** Parses the feed to extract sundry metadata */
protected function parse() {
$this->id = $this->getId();
$this->link = $this->getLink();
$this->relatedLink = $this->getRelatedLink();
$this->title = $this->getTitle();
$this->people = $this->getPeople();
$this->author = $this->people->primary() ?? $this->feed->author;
$this->dateModified = $this->getDateModified();
$this->dateCreated = $this->getDateCreated();
// do a second pass on missing data we'd rather fill in
$this->title = strlen($this->title) ? $this->title : $this->link;
// do extra stuff just to test it
$this->categories = $this->getCategories();
}
/** General function to fetch the entry title */
abstract public function getTitle(): string;
/** General function to fetch the categories of an entry */
abstract public function getCategories(): CategoryCollection;
/** General function to fetch the entry identifier */
abstract public function getId(): string;
/** General function to fetch a collection of people associated with an entry */
abstract public function getPeople(): PersonCollection;
/** General function to fetch the entry's modification date */
abstract public function getDateModified();
/** General function to fetch the entry's creation date */
abstract public function getDateCreated();
/** General function to fetch the Web URL of the entry */
abstract public function getLink(): string;
/** General function to fetch the URL of a article related to the entry */
abstract public function getRelatedLink(): string;
}

57
lib/Feed.php

@ -6,12 +6,7 @@
declare(strict_types=1);
namespace JKingWeb\Lax;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
abstract class Feed {
protected $reqUrl;
class Feed {
public $type;
public $version;
public $url;
@ -24,51 +19,11 @@ abstract class Feed {
public $dateModified;
public $entries;
/** Constructs a parsed feed */
abstract public function __construct(string $data, string $contentType = "", string $url = "");
/** Parses the feed to extract sundry metadata */
protected function parse() {
$this->id = $this->getId();
$this->url = $this->getUrl();
$this->link = $this->getLink();
$this->title = $this->getTitle();
$this->summary = $this->getSummary();
$this->people = $this->getPeople();
$this->author = $this->people->primary();
$this->dateModified = $this->getDateModified();
$this->entries = $this->getEntries();
// do a second pass on missing data we'd rather fill in
$this->link = strlen($this->link) ? $this->link : $this->url;
$this->title = strlen($this->title) ? $this->title : $this->link;
// do extra stuff just to test it
$this->categories = $this->getCategories();
private function __construct() {
}
/** General function to fetch the canonical feed URL */
abstract public function getUrl(): string;
/** General function to fetch the feed title */
abstract public function getTitle(): string;
/** General function to fetch the feed's Web-representation URL */
abstract public function getLink(): string;
/** General function to fetch the description of a feed */
abstract public function getSummary(): string;
/** General function to fetch the categories of a feed */
abstract public function getCategories(): CategoryCollection;
/** General function to fetch the feed identifier */
abstract public function getId(): string;
/** General function to fetch a collection of people associated with a feed */
abstract public function getPeople(): PersonCollection;
/** General function to fetch the feed's modification date */
abstract public function getDateModified();
/** General function to fetch the feed's modification date */
abstract public function getEntries() : array;
public static function parse(string $data, ?string $contentType = null, ?string $url = null): self {
$out = new self;
return $out;
}
}

3
lib/Construct.php → lib/Parser/Construct.php

@ -4,9 +4,8 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax;
namespace JKingWeb\Lax\Parser;
use JKingWeb\Lax\Person\Person;
use JKingWeb\Lax\Date;
trait Construct {

36
lib/Parser/Entry.php

@ -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 JKingWeb\Lax\Parser;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
interface Entry {
/** General function to fetch the entry title */
abstract public function getTitle(): string;
/** General function to fetch the categories of an entry */
abstract public function getCategories(): CategoryCollection;
/** General function to fetch the entry identifier */
abstract public function getId(): string;
/** General function to fetch a collection of people associated with an entry */
abstract public function getPeople(): PersonCollection;
/** General function to fetch the entry's modification date */
abstract public function getDateModified();
/** General function to fetch the entry's creation date */
abstract public function getDateCreated();
/** General function to fetch the Web URL of the entry */
abstract public function getLink(): string;
/** General function to fetch the URL of a article related to the entry */
abstract public function getRelatedLink(): string;
}

39
lib/Parser/Feed.php

@ -0,0 +1,39 @@
<?php
/** @license MIT
* Copyright 2018 J. King et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\Parser;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
interface Feed {
/** General function to fetch the canonical feed URL */
abstract public function getUrl(): string;
/** General function to fetch the feed title */
abstract public function getTitle(): string;
/** General function to fetch the feed's Web-representation URL */
abstract public function getLink(): string;
/** General function to fetch the description of a feed */
abstract public function getSummary(): string;
/** General function to fetch the categories of a feed */
abstract public function getCategories(): CategoryCollection;
/** General function to fetch the feed identifier */
abstract public function getId(): string;
/** General function to fetch a collection of people associated with a feed */
abstract public function getPeople(): PersonCollection;
/** General function to fetch the feed's modification date */
abstract public function getDateModified();
/** General function to fetch the feed's modification date */
abstract public function getEntries() : array;
}

7
lib/JSON/Construct.php → lib/Parser/JSON/Construct.php

@ -4,13 +4,10 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\JSON;
use JKingWeb\Lax\Person\Person;
use JKingWeb\Lax\Person\Collection as PersonCollection;
namespace JKingWeb\Lax\Parser\JSON;
trait Construct {
use \JKingWeb\Lax\Construct;
use \JKingWeb\Lax\Parser\Construct;
/** @var object */
protected $json;

26
lib/JSON/Entry.php → lib/Parser/JSON/Entry.php

@ -4,22 +4,22 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\JSON;
namespace JKingWeb\Lax\Parser\JSON;
use JKingWeb\Lax\Person\Person;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
use JKingWeb\Lax\Category\Category;
class Entry extends \JKingWeb\Lax\Entry {
class Entry implements \JKingWeb\Lax\Parser\Entry {
use Construct;
use Primitives\Construct;
protected $url;
/** Constructs a parsed feed */
public function __construct($data, \JKingWeb\Lax\Feed $feed) {
public function __construct($data, \JKingWeb\Lax\Parser\Feed $feed) {
$this->init($data, $feed);
$this->parse();
}
/** Performs initialization of the instance */
@ -29,6 +29,24 @@ class Entry extends \JKingWeb\Lax\Entry {
$this->url = $feed->url;
}
/** Parses the feed to extract sundry metadata */
protected function parse(\stdClass $data, \JKingWeb\Lax\Feed $feed): \JKingWeb\Lax\Entry {
$entry = new \JKingWeb\Lax\Entry;
$entry->id = $this->getId();
$entry->link = $this->getLink();
$entry->relatedLink = $this->getRelatedLink();
$entry->title = $this->getTitle();
$entry->people = $this->getPeople();
$entry->author = $this->people->primary() ?? $this->feed->author;
$entry->dateModified = $this->getDateModified();
$entry->dateCreated = $this->getDateCreated();
// do a second pass on missing data we'd rather fill in
$entry->title = strlen($this->title) ? $this->title : $this->link;
// do extra stuff just to test it
$entry->categories = $this->getCategories();
return $entry;
}
/** General function to fetch the categories of an entry */
public function getCategories(): CategoryCollection {
$out = new CategoryCollection;

24
lib/JSON/Feed.php → lib/Parser/JSON/Feed.php

@ -4,20 +4,19 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\JSON;
namespace JKingWeb\Lax\Parser\JSON;
use JKingWeb\Lax\Person\Person;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
class Feed extends \JKingWeb\Lax\Feed {
class Feed implements \JKingWeb\Lax\Parser\Feed {
use Construct;
use Primitives\Construct;
/** Constructs a parsed feed */
public function __construct(string $data, string $contentType = "", string $url = "") {
$this->init($data, $contentType);
$this->parse();
}
/** Performs initialization of the instance */
@ -29,6 +28,25 @@ class Feed extends \JKingWeb\Lax\Feed {
$this->version = $this->fetchMember("version", "str") ?? "";
}
/** Parses the feed to extract sundry metadata */
public function parse(\JKingWeb\Lax\Feed $feed): \JKingWeb\Lax\Feed {
$feed->id = $this->getId();
$feed->url = $this->getUrl();
$feed->link = $this->getLink();
$feed->title = $this->getTitle();
$feed->summary = $this->getSummary();
$feed->people = $this->getPeople();
$feed->author = $this->people->primary();
$feed->dateModified = $this->getDateModified();
$feed->entries = $this->getEntries();
// do a second pass on missing data we'd rather fill in
$feed->link = strlen($this->link) ? $this->link : $this->url;
$feed->title = strlen($this->title) ? $this->title : $this->link;
// do extra stuff just to test it
$feed->categories = $this->getCategories();
return $feed;
}
/** General function to fetch the canonical feed URL
*
* If the feed does not include a canonical URL, the request URL is returned instead

3
lib/JSON/Primitives/Construct.php → lib/Parser/JSON/Primitives/Construct.php

@ -4,14 +4,13 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\JSON\Primitives;
namespace JKingWeb\Lax\Parser\JSON\Primitives;
use JKingWeb\Lax\Person\Person;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
trait Construct {
/** Primitive function to fetch the author from v1 JSON feeds */
protected function getPeopleV1() {
$author = $this->fetchMember("author", "object");

4
lib/XML/Construct.php → lib/Parser/XML/Construct.php

@ -4,13 +4,13 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\XML;
namespace JKingWeb\Lax\Parser\XML;
use JKingWeb\Lax\Person\Person;
use JKingWeb\Lax\Person\Collection as PersonCollection;
trait Construct {
use \JKingWeb\Lax\Construct;
use \JKingWeb\Lax\Parser\Construct;
/** @var \DOMDocument */
public $document;

23
lib/XML/Entry.php → lib/Parser/XML/Entry.php

@ -4,12 +4,12 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\XML;
namespace JKingWeb\Lax\Parser\XML;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
class Entry extends \JKingWeb\Lax\Entry {
class Entry implements \JKingWeb\Lax\Parser\Entry {
use Construct;
use Primitives\Construct;
use Primitives\Entry;
@ -17,7 +17,6 @@ class Entry extends \JKingWeb\Lax\Entry {
/** Constructs a parsed feed */
public function __construct(\DOMElement $data, Feed $feed, XPath $xpath = null) {
$this->init($data, $feed, $xpath);
$this->parse();
}
/** Performs initialization of the instance */
@ -26,6 +25,24 @@ class Entry extends \JKingWeb\Lax\Entry {
$this->subject = $node;
$this->feed = $feed;
}
/** Parses the feed to extract sundry metadata */
protected function parse(\DOMElement $data, \JKingWeb\Lax\Feed $feed): \JKingWeb\Lax\Entry {
$entry = new \JKingWeb\Lax\Entry;
$entry->id = $this->getId();
$entry->link = $this->getLink();
$entry->relatedLink = $this->getRelatedLink();
$entry->title = $this->getTitle();
$entry->people = $this->getPeople();
$entry->author = $this->people->primary() ?? $this->feed->author;
$entry->dateModified = $this->getDateModified();
$entry->dateCreated = $this->getDateCreated();
// do a second pass on missing data we'd rather fill in
$entry->title = strlen($this->title) ? $this->title : $this->link;
// do extra stuff just to test it
$entry->categories = $this->getCategories();
return $entry;
}
/** General function to fetch the entry title */
public function getTitle(): string {

24
lib/XML/Feed.php → lib/Parser/XML/Feed.php

@ -4,12 +4,12 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\XML;
namespace JKingWeb\Lax\Parser\XML;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
class Feed extends \JKingWeb\Lax\Feed {
class Feed implements \JKingWeb\Lax\Parser\Feed {
use Construct;
use Primitives\Construct;
use Primitives\Feed;
@ -17,7 +17,6 @@ class Feed extends \JKingWeb\Lax\Feed {
/** Constructs a parsed feed */
public function __construct(string $data, string $contentType = "", string $url = "") {
$this->init($data, $contentType, $url);
$this->parse();
}
/** Performs initialization of the instance */
@ -54,6 +53,25 @@ class Feed extends \JKingWeb\Lax\Feed {
}
$this->url = $url;
}
/** Parses the feed to extract sundry metadata */
public function parse(\JKingWeb\Lax\Feed $feed): \JKingWeb\Lax\Feed {
$feed->id = $this->getId();
$feed->url = $this->getUrl();
$feed->link = $this->getLink();
$feed->title = $this->getTitle();
$feed->summary = $this->getSummary();
$feed->people = $this->getPeople();
$feed->author = $this->people->primary();
$feed->dateModified = $this->getDateModified();
$feed->entries = $this->getEntries();
// do a second pass on missing data we'd rather fill in
$feed->link = strlen($this->link) ? $this->link : $this->url;
$feed->title = strlen($this->title) ? $this->title : $this->link;
// do extra stuff just to test it
$feed->categories = $this->getCategories();
return $feed;
}
/** General function to fetch the canonical feed URL
*

7
lib/XML/Primitives/Construct.php → lib/Parser/XML/Primitives/Construct.php

@ -4,16 +4,15 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\XML\Primitives;
namespace JKingWeb\Lax\Parser\XML\Primitives;
use JKingWeb\Lax\Person\Person;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Category;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
use JKingWeb\Lax\XML\Entry as FeedEntry;
use JKingWeb\Lax\Parser\XML\Entry as FeedEntry;
trait Construct {
/** Primitive to fetch an Atom feed/entry title
*
* This fetches the title in plain text rather than HTML, even if HTML is provided in the feed/entry
@ -95,7 +94,7 @@ trait Construct {
protected function getCategoriesDC() {
$out = new CategoryCollection;
foreach ($this->fetchTextMulti("dc:subject") ?? [] as $text) {
if (strlen($ctext)) {
if (strlen($text)) {
$c = new Category;
$c->name = $text;
$out[] = $c;

5
lib/XML/Primitives/Entry.php → lib/Parser/XML/Primitives/Entry.php

@ -4,13 +4,12 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\XML\Primitives;
namespace JKingWeb\Lax\Parser\XML\Primitives;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\XML\XPath;
use JKingWeb\Lax\Parser\XML\XPath;
trait Entry {
/** Primitive to fetch a collection of authors associated with an Atom entry
*
* This differs from feeds in that an entry's <source> element (which possibly contains metadata for the source feed) is checked for authors if the entry itself has none

5
lib/XML/Primitives/Feed.php → lib/Parser/XML/Primitives/Feed.php

@ -4,13 +4,12 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\XML\Primitives;
namespace JKingWeb\Lax\Parser\XML\Primitives;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\XML\XPath;
use JKingWeb\Lax\Parser\XML\XPath;
trait Feed {
/** Primitive to fetch an Atom feed summary
*
* Atom does not have a 'description' element like the RSSes, but it does have 'subtitle', which fills roughly the same function

2
lib/XML/XPath.php → lib/Parser/XML/XPath.php

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Lax\XML;
namespace JKingWeb\Lax\Parser\XML;
class XPath extends \DOMXpath {
const NS = [

5
vendor-bin/phpunit/composer.json

@ -0,0 +1,5 @@
{
"require-dev": {
"phpunit/phpunit": "^9.0"
}
}

1600
vendor-bin/phpunit/composer.lock

File diff suppressed because it is too large
Loading…
Cancel
Save