1
0
mirror of https://github.com/suk-ws/ph-Bookshelf.git synced 2025-02-12 18:59:54 +08:00
ph-Bookshelf/src/Element/LinkCollection.php
Eyre_S a401c4cc55
构建了XML格式的书架和书籍元数据对象及其解析,添加git eol=LF 限制
- 总共添加的对象:
  - Bookshelf
  - LinkCollection
  - Link
  - BookCollection
  - Book
  - BookContented
  - Chapter
  - Page
  - Segment
2021-03-20 22:18:15 +08:00

41 lines
852 B
PHP

<?php
require_once "./src/Element/Link.php";
class LinkCollection {
/** @var Link[]|LinkCollection[] */
private array $array;
private function __construct (array $a) {
$this->array = $a;
}
public static function parse (DOMNode $root): LinkCollection {
$node = new LinkCollection(array());
for ($child = $root->firstChild; $child != null; $child = $child->nextSibling) {
switch ($child->nodeName) {
case "Link":
array_push($node->array, Link::parse($child));
break;
case "Collection":
array_push($node->array, LinkCollection::parse($child));
break;
case "#text":
break;
default:
echo "ERROR UNSUPPORTED NODE TYPE ON LINK COLLECTION\n";
}
}
return $node;
}
/**
* @return Link[]|LinkCollection[]
*/
public function getCollection (): array {
return $this->array;
}
}