mirror of
https://github.com/suk-ws/ph-Bookshelf.git
synced 2024-12-05 09:26:52 +08:00
使子元素维护其父元素的引用,修复资源文件位置书写的错误
This commit is contained in:
parent
fa218dc2b0
commit
0d34dfb04e
@ -23,23 +23,26 @@ class SiteMeta {
|
|||||||
|
|
||||||
public static function getGitbookStylesheetsList (): array {
|
public static function getGitbookStylesheetsList (): array {
|
||||||
return array(
|
return array(
|
||||||
"gitbook/style.css",
|
"/assets/gitbook/style.css",
|
||||||
"gitbook/gitbook-plugin-highlight/website.css",
|
"/assets/gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css",
|
||||||
"gitbook/gitbook-plugin-search/search.css",
|
"/assets/gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css",
|
||||||
"gitbook/gitbook-plugin-fontsettings/website.css"
|
"/assets/gitbook/gitbook-plugin-highlight/website.css",
|
||||||
|
"/assets/gitbook/gitbook-plugin-search/search.css",
|
||||||
|
"/assets/gitbook/gitbook-plugin-fontsettings/website.css"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getGitbookJavascriptList (): array {
|
public static function getGitbookJavascriptList (): array {
|
||||||
return array(
|
return array(
|
||||||
"gitbook/gitbook.js",
|
"/assets/gitbook/gitbook.js",
|
||||||
"gitbook/theme.js",
|
"/assets/gitbook/theme.js",
|
||||||
"gitbook/gitbook-plugin-search/search-engine.js",
|
"/assets/gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js",
|
||||||
"gitbook/gitbook-plugin-search/search.js",
|
"/assets/gitbook/gitbook-plugin-search/search-engine.js",
|
||||||
"gitbook/gitbook-plugin-lunr/lunr.min.js",
|
"/assets/gitbook/gitbook-plugin-search/search.js",
|
||||||
"gitbook/gitbook-plugin-lunr/search-lunr.js",
|
"/assets/gitbook/gitbook-plugin-lunr/lunr.min.js",
|
||||||
"gitbook/gitbook-plugin-sharing/buttons.js",
|
"/assets/gitbook/gitbook-plugin-lunr/search-lunr.js",
|
||||||
"gitbook/gitbook-plugin-fontsettings/fontsettings.js"
|
"/assets/gitbook/gitbook-plugin-sharing/buttons.js",
|
||||||
|
"/assets/gitbook/gitbook-plugin-fontsettings/fontsettings.js"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once "./src/Element/BookCollection.php";
|
||||||
|
|
||||||
class Book {
|
class Book {
|
||||||
|
|
||||||
private string $id;
|
private string $id;
|
||||||
private string $name;
|
private string $name;
|
||||||
|
private BookCollection $parent;
|
||||||
|
|
||||||
public function __construct (string $id, string $name) {
|
public function __construct (string $id, string $name, BookCollection $parent) {
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
|
$this->parent = $parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DOMNode $xmlData
|
* @param DOMNode $xmlData
|
||||||
|
* @param BookCollection $parent
|
||||||
* @return Book
|
* @return Book
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function parse (DOMNode $xmlData): Book {
|
public static function parse (DOMNode $xmlData, BookCollection $parent): Book {
|
||||||
if ($xmlData->hasAttributes()) {
|
if ($xmlData->hasAttributes()) {
|
||||||
$attrName = $xmlData->attributes->getNamedItem("name");
|
$attrName = $xmlData->attributes->getNamedItem("name");
|
||||||
$attrId = $xmlData->attributes->getNamedItem("id");
|
$attrId = $xmlData->attributes->getNamedItem("id");
|
||||||
@ -29,7 +34,7 @@ class Book {
|
|||||||
throw new Exception("Book xml data missing attributes");
|
throw new Exception("Book xml data missing attributes");
|
||||||
if ($xmlData->hasChildNodes())
|
if ($xmlData->hasChildNodes())
|
||||||
throw new Exception("Book xml with id \"$id\" have some children which are not supported");
|
throw new Exception("Book xml with id \"$id\" have some children which are not supported");
|
||||||
return new Book($id, $name);
|
return new Book($id, $name, $parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId (): string {
|
public function getId (): string {
|
||||||
@ -40,4 +45,11 @@ class Book {
|
|||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return BookCollection|null
|
||||||
|
*/
|
||||||
|
public function getParent (): BookCollection {
|
||||||
|
return $this->parent;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -10,19 +10,22 @@ class BookCollection {
|
|||||||
|
|
||||||
/** @var Book[]|BookCollection[] */
|
/** @var Book[]|BookCollection[] */
|
||||||
private array $array;
|
private array $array;
|
||||||
|
private BookCollection $parent;
|
||||||
|
|
||||||
private function __construct (string $name, array $a) {
|
private function __construct (string $name, array $a, BookCollection $parent) {
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->array = $a;
|
$this->array = $a;
|
||||||
|
$this->parent = $parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DOMNode $root
|
* @param DOMNode $root
|
||||||
|
* @param BookCollection $parent
|
||||||
* @param bool $isRoot
|
* @param bool $isRoot
|
||||||
* @return BookCollection
|
* @return BookCollection
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function parse (DOMNode $root, bool $isRoot = false): BookCollection {
|
public static function parse (DOMNode $root, BookCollection $parent, bool $isRoot = false): BookCollection {
|
||||||
$name = BookCollection::ROOT;
|
$name = BookCollection::ROOT;
|
||||||
if (!$isRoot) {
|
if (!$isRoot) {
|
||||||
if ($root->hasAttributes()) {
|
if ($root->hasAttributes()) {
|
||||||
@ -31,14 +34,14 @@ class BookCollection {
|
|||||||
else $name = $attrName->nodeValue;
|
else $name = $attrName->nodeValue;
|
||||||
} else throw new Exception("BookCollection (not root) xml data missing attributes");
|
} else throw new Exception("BookCollection (not root) xml data missing attributes");
|
||||||
}
|
}
|
||||||
$node = new BookCollection($name, array());
|
$node = new BookCollection($name, array(), $parent);
|
||||||
for ($child = $root->firstChild; $child != null; $child = $child->nextSibling) {
|
for ($child = $root->firstChild; $child != null; $child = $child->nextSibling) {
|
||||||
switch ($child->nodeName) {
|
switch ($child->nodeName) {
|
||||||
case "Book":
|
case "Book":
|
||||||
array_push($node->array, Book::parse($child));
|
array_push($node->array, Book::parse($child, $node));
|
||||||
break;
|
break;
|
||||||
case "Collection":
|
case "Collection":
|
||||||
array_push($node->array, BookCollection::parse($child));
|
array_push($node->array, BookCollection::parse($child, $node));
|
||||||
break;
|
break;
|
||||||
case "#text":
|
case "#text":
|
||||||
break;
|
break;
|
||||||
@ -60,4 +63,11 @@ class BookCollection {
|
|||||||
return $this->array;
|
return $this->array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return BookCollection|null
|
||||||
|
*/
|
||||||
|
public function getParent (): BookCollection {
|
||||||
|
return $this->parent;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,23 @@
|
|||||||
require_once "./src/Element/Book.php";
|
require_once "./src/Element/Book.php";
|
||||||
require_once "./src/Element/BookContent/Chapter.php";
|
require_once "./src/Element/BookContent/Chapter.php";
|
||||||
|
|
||||||
class BookContented extends Book {
|
class BookContented {
|
||||||
|
|
||||||
|
private string $id;
|
||||||
|
private string $name;
|
||||||
|
|
||||||
|
public function __construct (string $id, string $name) {
|
||||||
|
$this->id = $id;
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
private Chapter $childs;
|
private Chapter $childs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param DOMNode $xmlData
|
||||||
|
* @return BookContented
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public static function parse (DOMNode $xmlData): BookContented {
|
public static function parse (DOMNode $xmlData): BookContented {
|
||||||
if ($xmlData->hasAttributes() && $xmlData->hasChildNodes()) {
|
if ($xmlData->hasAttributes() && $xmlData->hasChildNodes()) {
|
||||||
$attrName = $xmlData->attributes->getNamedItem("name");
|
$attrName = $xmlData->attributes->getNamedItem("name");
|
||||||
@ -18,7 +31,7 @@ class BookContented extends Book {
|
|||||||
if ($attrId == null) throw new Exception("BookWithContent xml data named \"$name\" missing attribute \"id\"");
|
if ($attrId == null) throw new Exception("BookWithContent xml data named \"$name\" missing attribute \"id\"");
|
||||||
else $id = $attrId->nodeValue;
|
else $id = $attrId->nodeValue;
|
||||||
$node = new BookContented($id, $name);
|
$node = new BookContented($id, $name);
|
||||||
$node->childs = Chapter::parse($xmlData);
|
$node->childs = Chapter::parse($xmlData, null);
|
||||||
} else
|
} else
|
||||||
throw new Exception("No child or attribute found on BookWithContent");
|
throw new Exception("No child or attribute found on BookWithContent");
|
||||||
return $node;
|
return $node;
|
||||||
@ -38,6 +51,14 @@ class BookContented extends Book {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getId (): string {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName (): string {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
public function getChilds (): Chapter {
|
public function getChilds (): Chapter {
|
||||||
return $this->childs;
|
return $this->childs;
|
||||||
}
|
}
|
||||||
|
@ -9,29 +9,33 @@ class Chapter {
|
|||||||
/** @var Chapter[]|Page[] */
|
/** @var Chapter[]|Page[] */
|
||||||
private array $childs;
|
private array $childs;
|
||||||
|
|
||||||
private function __construct (string $name, array $array) {
|
private Chapter $parent;
|
||||||
|
|
||||||
|
private function __construct (string $name, array $array, Chapter $parent) {
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->childs = $array;
|
$this->childs = $array;
|
||||||
|
$this->parent = $parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DOMNode $xmlData
|
* @param DOMNode $xmlData
|
||||||
|
* @param Chapter $parent
|
||||||
* @return Chapter
|
* @return Chapter
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function parse (DOMNode $xmlData): Chapter {
|
public static function parse (DOMNode $xmlData, Chapter $parent): Chapter {
|
||||||
if ($xmlData->hasAttributes()) {
|
if ($xmlData->hasAttributes()) {
|
||||||
$attrName = $xmlData->attributes->getNamedItem("name");
|
$attrName = $xmlData->attributes->getNamedItem("name");
|
||||||
if ($attrName == null) throw new Exception("Chapter xml data missing attribute \"name\"");
|
if ($attrName == null) throw new Exception("Chapter xml data missing attribute \"name\"");
|
||||||
else $node = new Chapter($xmlData->attributes->getNamedItem("name")->nodeValue, array());
|
else $node = new Chapter($xmlData->attributes->getNamedItem("name")->nodeValue, array(), $parent);
|
||||||
} else throw new Exception("Chapter xml data missing attributes");
|
} else throw new Exception("Chapter xml data missing attributes");
|
||||||
for ($child = $xmlData->firstChild;$child != null ; $child = $child->nextSibling) {
|
for ($child = $xmlData->firstChild;$child != null ; $child = $child->nextSibling) {
|
||||||
switch ($child->nodeName) {
|
switch ($child->nodeName) {
|
||||||
case "Page":
|
case "Page":
|
||||||
array_push($node->childs, Page::parse($child));
|
array_push($node->childs, Page::parse($child, $node));
|
||||||
break;
|
break;
|
||||||
case "Chapter":
|
case "Chapter":
|
||||||
array_push($node->childs, self::parse($child));
|
array_push($node->childs, self::parse($child, $node));
|
||||||
break;
|
break;
|
||||||
case "#text":
|
case "#text":
|
||||||
break;
|
break;
|
||||||
@ -53,4 +57,11 @@ class Chapter {
|
|||||||
return $this->childs;
|
return $this->childs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Chapter|null
|
||||||
|
*/
|
||||||
|
public function getParent (): Chapter {
|
||||||
|
return $this->parent;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once "./src/Element/BookContent/Chapter.php";
|
||||||
require_once "./src/Element/BookContent/Segment.php";
|
require_once "./src/Element/BookContent/Segment.php";
|
||||||
|
|
||||||
class Page {
|
class Page {
|
||||||
@ -9,19 +10,22 @@ class Page {
|
|||||||
|
|
||||||
/** @var Segment[] */
|
/** @var Segment[] */
|
||||||
private array $segues;
|
private array $segues;
|
||||||
|
private Chapter $parent;
|
||||||
|
|
||||||
public function __construct (string $id, string $name, array $childs = array()) {
|
public function __construct (string $id, string $name, Chapter $parent, array $childs = array()) {
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
|
$this->parent = $parent;
|
||||||
$this->segues = $childs;
|
$this->segues = $childs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DOMNode $xmlData
|
* @param DOMNode $xmlData
|
||||||
|
* @param Chapter $parent
|
||||||
* @return Page
|
* @return Page
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function parse (DOMNode $xmlData): Page {
|
public static function parse (DOMNode $xmlData, Chapter $parent): Page {
|
||||||
if ($xmlData->hasAttributes()) {
|
if ($xmlData->hasAttributes()) {
|
||||||
$attrName = $xmlData->attributes->getNamedItem("name");
|
$attrName = $xmlData->attributes->getNamedItem("name");
|
||||||
$attrId = $xmlData->attributes->getNamedItem("id");
|
$attrId = $xmlData->attributes->getNamedItem("id");
|
||||||
@ -31,13 +35,13 @@ class Page {
|
|||||||
else $name = $attrName->nodeValue;
|
else $name = $attrName->nodeValue;
|
||||||
if ($attrId == null) throw new Exception("Page xml data named \"$name\" missing attribute \"id\"");
|
if ($attrId == null) throw new Exception("Page xml data named \"$name\" missing attribute \"id\"");
|
||||||
else $id = $attrId->nodeValue;
|
else $id = $attrId->nodeValue;
|
||||||
$node = new Page($id, $name);
|
$node = new Page($id, $name, $parent);
|
||||||
} else
|
} else
|
||||||
throw new Exception("Book xml data missing attributes");
|
throw new Exception("Book xml data missing attributes");
|
||||||
for ($child = $xmlData->firstChild;$child != null ; $child = $child->nextSibling) {
|
for ($child = $xmlData->firstChild;$child != null ; $child = $child->nextSibling) {
|
||||||
switch ($child->nodeName) {
|
switch ($child->nodeName) {
|
||||||
case "Segment":
|
case "Segment":
|
||||||
array_push($node->segues, Segment::parse($child));
|
array_push($node->segues, Segment::parse($child, $node));
|
||||||
break;
|
break;
|
||||||
case "#text":
|
case "#text":
|
||||||
break;
|
break;
|
||||||
@ -63,4 +67,8 @@ class Page {
|
|||||||
return $this->segues;
|
return $this->segues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getParent (): Chapter {
|
||||||
|
return $this->parent;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once "./src/Element/BookContent/Page.php";
|
||||||
|
|
||||||
class Segment {
|
class Segment {
|
||||||
|
|
||||||
private string $id;
|
private string $id;
|
||||||
private string $name;
|
private string $name;
|
||||||
|
private Page $parent;
|
||||||
|
|
||||||
public function __construct ($id, $name) {
|
public function __construct (string $id, string $name, Page $parent) {
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
|
$this->parent = $parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DOMNode $xmlData
|
* @param DOMNode $xmlData
|
||||||
|
* @param Page $parent
|
||||||
* @return Segment
|
* @return Segment
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function parse (DOMNode $xmlData): Segment {
|
public static function parse (DOMNode $xmlData, Page $parent): Segment {
|
||||||
if ($xmlData->hasAttributes()) {
|
if ($xmlData->hasAttributes()) {
|
||||||
$attrName = $xmlData->attributes->getNamedItem("name");
|
$attrName = $xmlData->attributes->getNamedItem("name");
|
||||||
$attrId = $xmlData->attributes->getNamedItem("id");
|
$attrId = $xmlData->attributes->getNamedItem("id");
|
||||||
@ -29,7 +34,7 @@ class Segment {
|
|||||||
throw new Exception("Segment xml data missing attributes");
|
throw new Exception("Segment xml data missing attributes");
|
||||||
if ($xmlData->hasChildNodes())
|
if ($xmlData->hasChildNodes())
|
||||||
throw new Exception("Segment xml named \"$name\" have some children which are not supported");
|
throw new Exception("Segment xml named \"$name\" have some children which are not supported");
|
||||||
return new Segment($id, $name);
|
return new Segment($id, $name, $parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId (): string {
|
public function getId (): string {
|
||||||
@ -40,4 +45,8 @@ class Segment {
|
|||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getParent (): Page {
|
||||||
|
return $this->parent;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -34,10 +34,10 @@ class Bookshelf {
|
|||||||
for ($rc = $dom->firstChild; $rc != null; $rc = $rc->nextSibling) {
|
for ($rc = $dom->firstChild; $rc != null; $rc = $rc->nextSibling) {
|
||||||
switch ($rc->nodeName) {
|
switch ($rc->nodeName) {
|
||||||
case "links":
|
case "links":
|
||||||
$return->links = LinkCollection::parse($rc, true);
|
$return->links = LinkCollection::parse($rc, null, true);
|
||||||
break;
|
break;
|
||||||
case "books":
|
case "books":
|
||||||
$return->books = BookCollection::parse($rc, true);
|
$return->books = BookCollection::parse($rc, null, true);
|
||||||
break;
|
break;
|
||||||
case "rootBook":
|
case "rootBook":
|
||||||
$return->rootBook = BookContented::parse($rc);
|
$return->rootBook = BookContented::parse($rc);
|
||||||
|
@ -1,22 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once "./src/Element/LinkCollection.php";
|
||||||
|
|
||||||
class Link {
|
class Link {
|
||||||
|
|
||||||
private string $name;
|
private string $name;
|
||||||
|
|
||||||
private string $href;
|
private string $href;
|
||||||
|
private LinkCollection $parent;
|
||||||
|
|
||||||
public function __construct (string $name, string $href) {
|
public function __construct (string $name, string $href, LinkCollection $parent) {
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->href = $href;
|
$this->href = $href;
|
||||||
|
$this->parent = $parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DOMNode $xmlData
|
* @param DOMNode $xmlData
|
||||||
|
* @param LinkCollection $parent
|
||||||
* @return Link
|
* @return Link
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function parse (DOMNode $xmlData): Link {
|
public static function parse (DOMNode $xmlData, LinkCollection $parent): Link {
|
||||||
if ($xmlData->hasAttributes()) {
|
if ($xmlData->hasAttributes()) {
|
||||||
$attrName = $xmlData->attributes->getNamedItem("name");
|
$attrName = $xmlData->attributes->getNamedItem("name");
|
||||||
$attrHref = $xmlData->attributes->getNamedItem("href");
|
$attrHref = $xmlData->attributes->getNamedItem("href");
|
||||||
@ -30,7 +34,7 @@ class Link {
|
|||||||
throw new Exception("Link xml data missing attributes");
|
throw new Exception("Link xml data missing attributes");
|
||||||
if ($xmlData->hasChildNodes())
|
if ($xmlData->hasChildNodes())
|
||||||
throw new Exception("Link xml named \"$name\" have some children which are not supported");
|
throw new Exception("Link xml named \"$name\" have some children which are not supported");
|
||||||
return new Link($name, $href);
|
return new Link($name, $href, $parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName (): string {
|
public function getName (): string {
|
||||||
@ -41,4 +45,11 @@ class Link {
|
|||||||
return $this->href;
|
return $this->href;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return LinkCollection|null
|
||||||
|
*/
|
||||||
|
public function getParent (): LinkCollection {
|
||||||
|
return $this->parent;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,19 +10,22 @@ class LinkCollection {
|
|||||||
|
|
||||||
/** @var Link[]|LinkCollection[] */
|
/** @var Link[]|LinkCollection[] */
|
||||||
private array $array;
|
private array $array;
|
||||||
|
private LinkCollection $parent;
|
||||||
|
|
||||||
private function __construct (string $name, array $a) {
|
private function __construct (string $name, array $a, LinkCollection $parent) {
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->array = $a;
|
$this->array = $a;
|
||||||
|
$this->parent = $parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DOMNode $root
|
* @param DOMNode $root
|
||||||
|
* @param LinkCollection $parent
|
||||||
* @param bool $isRoot
|
* @param bool $isRoot
|
||||||
* @return LinkCollection
|
* @return LinkCollection
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function parse (DOMNode $root, bool $isRoot = false): LinkCollection {
|
public static function parse (DOMNode $root, LinkCollection $parent, bool $isRoot = false): LinkCollection {
|
||||||
$name = LinkCollection::ROOT;
|
$name = LinkCollection::ROOT;
|
||||||
if (!$isRoot) {
|
if (!$isRoot) {
|
||||||
if ($root->hasAttributes()) {
|
if ($root->hasAttributes()) {
|
||||||
@ -31,14 +34,14 @@ class LinkCollection {
|
|||||||
else $name = $attrName->nodeValue;
|
else $name = $attrName->nodeValue;
|
||||||
} else throw new Exception("LinkCollection (not root) xml data missing attributes");
|
} else throw new Exception("LinkCollection (not root) xml data missing attributes");
|
||||||
}
|
}
|
||||||
$node = new LinkCollection($name, array());
|
$node = new LinkCollection($name, array(), $parent);
|
||||||
for ($child = $root->firstChild; $child != null; $child = $child->nextSibling) {
|
for ($child = $root->firstChild; $child != null; $child = $child->nextSibling) {
|
||||||
switch ($child->nodeName) {
|
switch ($child->nodeName) {
|
||||||
case "Link":
|
case "Link":
|
||||||
array_push($node->array, Link::parse($child));
|
array_push($node->array, Link::parse($child, $node));
|
||||||
break;
|
break;
|
||||||
case "Collection":
|
case "Collection":
|
||||||
array_push($node->array, LinkCollection::parse($child));
|
array_push($node->array, LinkCollection::parse($child, $node));
|
||||||
break;
|
break;
|
||||||
case "#text":
|
case "#text":
|
||||||
break;
|
break;
|
||||||
@ -60,4 +63,11 @@ class LinkCollection {
|
|||||||
return $this->array;
|
return $this->array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return LinkCollection|null
|
||||||
|
*/
|
||||||
|
public function getParent (): LinkCollection {
|
||||||
|
return $this->parent;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user