1
0
mirror of https://github.com/suk-ws/ph-Bookshelf.git synced 2024-12-05 09:26:52 +08:00

修复 BookCollection 和 LinkCollection 缺失 name 的bug

This commit is contained in:
A.C.Sukazyo Eyre 2021-03-20 22:39:24 +08:00
parent a401c4cc55
commit 74784f83a3
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
3 changed files with 22 additions and 8 deletions

View File

@ -4,15 +4,22 @@ require_once "./src/Element/Book.php";
class BookCollection {
const ROOT = "::root";
private string $name;
/** @var Book[]|BookCollection[] */
private array $array;
private function __construct (array $a) {
private function __construct (string $name, array $a) {
$this->name = $name;
$this->array = $a;
}
public static function parse (DOMNode $root): BookCollection {
$node = new BookCollection(array());
public static function parse (DOMNode $root, bool $isRoot = false): BookCollection {
$name = LinkCollection::ROOT;
if (!$isRoot) $name = $root->attributes->getNamedItem("name")->nodeValue;
$node = new BookCollection($name, array());
for ($child = $root->firstChild; $child != null; $child = $child->nextSibling) {
switch ($child->nodeName) {
case "Book":

View File

@ -29,10 +29,10 @@ class Bookshelf {
for ($rc = $dom->firstChild; $rc != null; $rc = $rc->nextSibling) {
switch ($rc->nodeName) {
case "links":
$return->links = LinkCollection::parse($rc);
$return->links = LinkCollection::parse($rc, true);
break;
case "books":
$return->books = BookCollection::parse($rc);
$return->books = BookCollection::parse($rc, true);
break;
case "rootBook":
$return->rootBook = BookContented::parse($rc);

View File

@ -4,15 +4,22 @@ require_once "./src/Element/Link.php";
class LinkCollection {
const ROOT = "::root";
private string $name;
/** @var Link[]|LinkCollection[] */
private array $array;
private function __construct (array $a) {
private function __construct (string $name, array $a) {
$this->name = $name;
$this->array = $a;
}
public static function parse (DOMNode $root): LinkCollection {
$node = new LinkCollection(array());
public static function parse (DOMNode $root, bool $isRoot = false): LinkCollection {
$name = LinkCollection::ROOT;
if (!$isRoot) $name = $root->attributes->getNamedItem("name")->nodeValue;
$node = new LinkCollection($name, array());
for ($child = $root->firstChild; $child != null; $child = $child->nextSibling) {
switch ($child->nodeName) {
case "Link":