From 0d34dfb04e4dd84dc23c920fb5015df981a0f345 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Tue, 23 Mar 2021 01:57:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E5=AD=90=E5=85=83=E7=B4=A0=E7=BB=B4?= =?UTF-8?q?=E6=8A=A4=E5=85=B6=E7=88=B6=E5=85=83=E7=B4=A0=E7=9A=84=E5=BC=95?= =?UTF-8?q?=E7=94=A8=EF=BC=8C=E4=BF=AE=E5=A4=8D=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BD=8D=E7=BD=AE=E4=B9=A6=E5=86=99=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Data/SiteMeta.php | 27 +++++++++++++---------- src/Element/Book.php | 18 ++++++++++++--- src/Element/BookCollection.php | 20 ++++++++++++----- src/Element/BookContent/BookContented.php | 25 +++++++++++++++++++-- src/Element/BookContent/Chapter.php | 21 +++++++++++++----- src/Element/BookContent/Page.php | 16 ++++++++++---- src/Element/BookContent/Segment.php | 15 ++++++++++--- src/Element/Bookshelf.php | 4 ++-- src/Element/Link.php | 19 ++++++++++++---- src/Element/LinkCollection.php | 20 ++++++++++++----- 10 files changed, 140 insertions(+), 45 deletions(-) diff --git a/src/Data/SiteMeta.php b/src/Data/SiteMeta.php index 4b240d7..af85b9d 100644 --- a/src/Data/SiteMeta.php +++ b/src/Data/SiteMeta.php @@ -23,23 +23,26 @@ class SiteMeta { public static function getGitbookStylesheetsList (): array { return array( - "gitbook/style.css", - "gitbook/gitbook-plugin-highlight/website.css", - "gitbook/gitbook-plugin-search/search.css", - "gitbook/gitbook-plugin-fontsettings/website.css" + "/assets/gitbook/style.css", + "/assets/gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css", + "/assets/gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.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 { return array( - "gitbook/gitbook.js", - "gitbook/theme.js", - "gitbook/gitbook-plugin-search/search-engine.js", - "gitbook/gitbook-plugin-search/search.js", - "gitbook/gitbook-plugin-lunr/lunr.min.js", - "gitbook/gitbook-plugin-lunr/search-lunr.js", - "gitbook/gitbook-plugin-sharing/buttons.js", - "gitbook/gitbook-plugin-fontsettings/fontsettings.js" + "/assets/gitbook/gitbook.js", + "/assets/gitbook/theme.js", + "/assets/gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js", + "/assets/gitbook/gitbook-plugin-search/search-engine.js", + "/assets/gitbook/gitbook-plugin-search/search.js", + "/assets/gitbook/gitbook-plugin-lunr/lunr.min.js", + "/assets/gitbook/gitbook-plugin-lunr/search-lunr.js", + "/assets/gitbook/gitbook-plugin-sharing/buttons.js", + "/assets/gitbook/gitbook-plugin-fontsettings/fontsettings.js" ); } diff --git a/src/Element/Book.php b/src/Element/Book.php index 9732ef4..d2ab2d8 100644 --- a/src/Element/Book.php +++ b/src/Element/Book.php @@ -1,21 +1,26 @@ id = $id; $this->name = $name; + $this->parent = $parent; } /** * @param DOMNode $xmlData + * @param BookCollection $parent * @return Book * @throws Exception */ - public static function parse (DOMNode $xmlData): Book { + public static function parse (DOMNode $xmlData, BookCollection $parent): Book { if ($xmlData->hasAttributes()) { $attrName = $xmlData->attributes->getNamedItem("name"); $attrId = $xmlData->attributes->getNamedItem("id"); @@ -29,7 +34,7 @@ class Book { throw new Exception("Book xml data missing attributes"); if ($xmlData->hasChildNodes()) 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 { @@ -40,4 +45,11 @@ class Book { return $this->name; } + /** + * @return BookCollection|null + */ + public function getParent (): BookCollection { + return $this->parent; + } + } \ No newline at end of file diff --git a/src/Element/BookCollection.php b/src/Element/BookCollection.php index ed87e8e..b467de5 100644 --- a/src/Element/BookCollection.php +++ b/src/Element/BookCollection.php @@ -10,19 +10,22 @@ class BookCollection { /** @var Book[]|BookCollection[] */ 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->array = $a; + $this->parent = $parent; } /** * @param DOMNode $root + * @param BookCollection $parent * @param bool $isRoot * @return BookCollection * @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; if (!$isRoot) { if ($root->hasAttributes()) { @@ -31,14 +34,14 @@ class BookCollection { else $name = $attrName->nodeValue; } 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) { switch ($child->nodeName) { case "Book": - array_push($node->array, Book::parse($child)); + array_push($node->array, Book::parse($child, $node)); break; case "Collection": - array_push($node->array, BookCollection::parse($child)); + array_push($node->array, BookCollection::parse($child, $node)); break; case "#text": break; @@ -60,4 +63,11 @@ class BookCollection { return $this->array; } + /** + * @return BookCollection|null + */ + public function getParent (): BookCollection { + return $this->parent; + } + } diff --git a/src/Element/BookContent/BookContented.php b/src/Element/BookContent/BookContented.php index f4cc83d..adb8c0f 100644 --- a/src/Element/BookContent/BookContented.php +++ b/src/Element/BookContent/BookContented.php @@ -3,10 +3,23 @@ require_once "./src/Element/Book.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; + /** + * @param DOMNode $xmlData + * @return BookContented + * @throws Exception + */ public static function parse (DOMNode $xmlData): BookContented { if ($xmlData->hasAttributes() && $xmlData->hasChildNodes()) { $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\""); else $id = $attrId->nodeValue; $node = new BookContented($id, $name); - $node->childs = Chapter::parse($xmlData); + $node->childs = Chapter::parse($xmlData, null); } else throw new Exception("No child or attribute found on BookWithContent"); 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 { return $this->childs; } diff --git a/src/Element/BookContent/Chapter.php b/src/Element/BookContent/Chapter.php index a14e726..23389cb 100644 --- a/src/Element/BookContent/Chapter.php +++ b/src/Element/BookContent/Chapter.php @@ -9,29 +9,33 @@ class Chapter { /** @var Chapter[]|Page[] */ 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->childs = $array; + $this->parent = $parent; } /** * @param DOMNode $xmlData + * @param Chapter $parent * @return Chapter * @throws Exception */ - public static function parse (DOMNode $xmlData): Chapter { + public static function parse (DOMNode $xmlData, Chapter $parent): Chapter { if ($xmlData->hasAttributes()) { $attrName = $xmlData->attributes->getNamedItem("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"); for ($child = $xmlData->firstChild;$child != null ; $child = $child->nextSibling) { switch ($child->nodeName) { case "Page": - array_push($node->childs, Page::parse($child)); + array_push($node->childs, Page::parse($child, $node)); break; case "Chapter": - array_push($node->childs, self::parse($child)); + array_push($node->childs, self::parse($child, $node)); break; case "#text": break; @@ -53,4 +57,11 @@ class Chapter { return $this->childs; } + /** + * @return Chapter|null + */ + public function getParent (): Chapter { + return $this->parent; + } + } diff --git a/src/Element/BookContent/Page.php b/src/Element/BookContent/Page.php index 4138554..47b74c5 100644 --- a/src/Element/BookContent/Page.php +++ b/src/Element/BookContent/Page.php @@ -1,5 +1,6 @@ id = $id; $this->name = $name; + $this->parent = $parent; $this->segues = $childs; } /** * @param DOMNode $xmlData + * @param Chapter $parent * @return Page * @throws Exception */ - public static function parse (DOMNode $xmlData): Page { + public static function parse (DOMNode $xmlData, Chapter $parent): Page { if ($xmlData->hasAttributes()) { $attrName = $xmlData->attributes->getNamedItem("name"); $attrId = $xmlData->attributes->getNamedItem("id"); @@ -31,13 +35,13 @@ class Page { else $name = $attrName->nodeValue; if ($attrId == null) throw new Exception("Page xml data named \"$name\" missing attribute \"id\""); else $id = $attrId->nodeValue; - $node = new Page($id, $name); + $node = new Page($id, $name, $parent); } else throw new Exception("Book xml data missing attributes"); for ($child = $xmlData->firstChild;$child != null ; $child = $child->nextSibling) { switch ($child->nodeName) { case "Segment": - array_push($node->segues, Segment::parse($child)); + array_push($node->segues, Segment::parse($child, $node)); break; case "#text": break; @@ -63,4 +67,8 @@ class Page { return $this->segues; } + public function getParent (): Chapter { + return $this->parent; + } + } diff --git a/src/Element/BookContent/Segment.php b/src/Element/BookContent/Segment.php index eef059d..6d4be6a 100644 --- a/src/Element/BookContent/Segment.php +++ b/src/Element/BookContent/Segment.php @@ -1,21 +1,26 @@ id = $id; $this->name = $name; + $this->parent = $parent; } /** * @param DOMNode $xmlData + * @param Page $parent * @return Segment * @throws Exception */ - public static function parse (DOMNode $xmlData): Segment { + public static function parse (DOMNode $xmlData, Page $parent): Segment { if ($xmlData->hasAttributes()) { $attrName = $xmlData->attributes->getNamedItem("name"); $attrId = $xmlData->attributes->getNamedItem("id"); @@ -29,7 +34,7 @@ class Segment { throw new Exception("Segment xml data missing attributes"); if ($xmlData->hasChildNodes()) 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 { @@ -40,4 +45,8 @@ class Segment { return $this->name; } + public function getParent (): Page { + return $this->parent; + } + } \ No newline at end of file diff --git a/src/Element/Bookshelf.php b/src/Element/Bookshelf.php index d8aec05..99f197f 100644 --- a/src/Element/Bookshelf.php +++ b/src/Element/Bookshelf.php @@ -34,10 +34,10 @@ class Bookshelf { for ($rc = $dom->firstChild; $rc != null; $rc = $rc->nextSibling) { switch ($rc->nodeName) { case "links": - $return->links = LinkCollection::parse($rc, true); + $return->links = LinkCollection::parse($rc, null, true); break; case "books": - $return->books = BookCollection::parse($rc, true); + $return->books = BookCollection::parse($rc, null, true); break; case "rootBook": $return->rootBook = BookContented::parse($rc); diff --git a/src/Element/Link.php b/src/Element/Link.php index 10669e3..4f45516 100644 --- a/src/Element/Link.php +++ b/src/Element/Link.php @@ -1,22 +1,26 @@ name = $name; $this->href = $href; + $this->parent = $parent; } /** * @param DOMNode $xmlData + * @param LinkCollection $parent * @return Link * @throws Exception */ - public static function parse (DOMNode $xmlData): Link { + public static function parse (DOMNode $xmlData, LinkCollection $parent): Link { if ($xmlData->hasAttributes()) { $attrName = $xmlData->attributes->getNamedItem("name"); $attrHref = $xmlData->attributes->getNamedItem("href"); @@ -30,7 +34,7 @@ class Link { throw new Exception("Link xml data missing attributes"); if ($xmlData->hasChildNodes()) 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 { @@ -41,4 +45,11 @@ class Link { return $this->href; } + /** + * @return LinkCollection|null + */ + public function getParent (): LinkCollection { + return $this->parent; + } + } diff --git a/src/Element/LinkCollection.php b/src/Element/LinkCollection.php index 2bcb4c9..e43438e 100644 --- a/src/Element/LinkCollection.php +++ b/src/Element/LinkCollection.php @@ -10,19 +10,22 @@ class LinkCollection { /** @var Link[]|LinkCollection[] */ 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->array = $a; + $this->parent = $parent; } /** * @param DOMNode $root + * @param LinkCollection $parent * @param bool $isRoot * @return LinkCollection * @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; if (!$isRoot) { if ($root->hasAttributes()) { @@ -31,14 +34,14 @@ class LinkCollection { else $name = $attrName->nodeValue; } 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) { switch ($child->nodeName) { case "Link": - array_push($node->array, Link::parse($child)); + array_push($node->array, Link::parse($child, $node)); break; case "Collection": - array_push($node->array, LinkCollection::parse($child)); + array_push($node->array, LinkCollection::parse($child, $node)); break; case "#text": break; @@ -60,4 +63,11 @@ class LinkCollection { return $this->array; } + /** + * @return LinkCollection|null + */ + public function getParent (): LinkCollection { + return $this->parent; + } + }