diff --git a/README.md b/README.md index 505c39a..50da901 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,9 @@ - 使用其它 Webserver,可以自行查询如何将 .htaccess 规则转换为你所使用的网站配置并写进你的网站配置当中 - PHP 版本 8.0 以上 (旧版可能可以使用,但未经完全测试) - - PHP 模块 `xml` (旧版可能叫做 `dom`) + - PHP 模块 `xml` (也可能叫做 `dom`) - PHP 模块 `mbstring` + - PHP 模块 `fileinfo` - composer 工具以安装项目依赖 - 在 php.ini 中设置 `display_errors` 以及 `display_startup_errors` 为 `Off` (或者关闭 `E_WARNING` 及以下 log) (这是由于最开始写代码极不上心导致很多地方都会有可能报出 warn,输出在屏幕上会导致很糟糕的使用体验) diff --git a/composer.json b/composer.json index 0aa877d..9645576 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,17 @@ "email": "email@example.com" } ], + "autoload": { + "psr-4": { + "SukWs\\Bookshelf\\": "src" + } + }, "require": { "php": ">=8.0", "ext-xml": "*", + "ext-dom": "*", "ext-mbstring": "*", + "ext-fileinfo": "*", "league/commonmark": ">=2.3.8" } } \ No newline at end of file diff --git a/constant.php b/constant.php index b8983f8..d4f6824 100644 --- a/constant.php +++ b/constant.php @@ -2,6 +2,6 @@ const APP_NAME = "ph-Bookshelf"; -const VERSION = "0.3.0.15"; +const VERSION = "0.3.1"; const CHANNEL = "suk-ws"; const BRANCH = "master"; diff --git a/index.php b/index.php index c24b53f..c036fe4 100644 --- a/index.php +++ b/index.php @@ -1,13 +1,12 @@ getChilds()->getChilds()[0]; + PageMeta::$page = PageMeta::$book->getChilds()->getChildren()[0]; } } else { // 主页面 PageMeta::$book = SiteMeta::getBookshelf()->getRootBook(); - PageMeta::$page = PageMeta::$book->getChilds()->getChilds()[0]; + PageMeta::$page = PageMeta::$book->getChilds()->getChildren()[0]; PageMeta::$isMainPage = true; } diff --git a/src/Data/PageMeta.php b/src/Data/PageMeta.php index 70fdf4c..c1bf95f 100644 --- a/src/Data/PageMeta.php +++ b/src/Data/PageMeta.php @@ -1,8 +1,9 @@ parent; } diff --git a/src/Element/BookCollection.php b/src/Element/BookCollection.php index 788082e..0da485f 100644 --- a/src/Element/BookCollection.php +++ b/src/Element/BookCollection.php @@ -1,7 +1,10 @@ firstChild; $child != null; $child = $child->nextSibling) { switch ($child->nodeName) { case "Book": - array_push($node->array, Book::parse($child, $node)); + $node->array[] = Book::parse($child, $node); break; case "Collection": - array_push($node->array, BookCollection::parse($child, $node)); + $node->array[] = BookCollection::parse($child, $node); break; case "#comment": break; case "#text": if (empty(trim($child->nodeValue))) break; + throw new Exception("Unsupported element type \"$child->nodeName\" in BookCollection named \"$name\""); default: throw new Exception("Unsupported element type \"$child->nodeName\" in BookCollection named \"$name\""); } @@ -69,7 +73,7 @@ class BookCollection { /** * @return BookCollection|null */ - public function getParent (): BookCollection { + public function getParent (): ?BookCollection { return $this->parent; } diff --git a/src/Element/BookContent/BookContented.php b/src/Element/BookContent/BookContented.php index 412cbab..91da22b 100644 --- a/src/Element/BookContent/BookContented.php +++ b/src/Element/BookContent/BookContented.php @@ -1,8 +1,11 @@ name = $name; - $this->childs = $array; + $this->children = $array; $this->parent = $parent; } @@ -32,15 +36,16 @@ class Chapter { for ($child = $xmlData->firstChild;$child != null ; $child = $child->nextSibling) { switch ($child->nodeName) { case "Page": - array_push($node->childs, Page::parse($child, $node)); + $node->children[] = Page::parse($child, $node); break; case "Chapter": - array_push($node->childs, self::parse($child, $node)); + $node->children[] = self::parse($child, $node); break; case "#comment": break; case "#text": if (empty(trim($child->nodeValue))) break; + throw new Exception("Unsupported element type \"$child->nodeName\" in Chapter \"$node->name\""); default: throw new Exception("Unsupported element type \"$child->nodeName\" in Chapter \"$node->name\""); } @@ -55,14 +60,14 @@ class Chapter { /** * @return Chapter[]|Page[] */ - public function getChilds (): array { - return $this->childs; + public function getChildren (): array { + return $this->children; } /** * @return Chapter|null */ - public function getParent (): Chapter { + public function getParent (): ?Chapter { return $this->parent; } @@ -76,7 +81,7 @@ class Chapter { $this->getPage(PageMeta::$page->getId())==null?"":" active", $this->name ); - foreach ($this->childs as $node) { + foreach ($this->children as $node) { $str .= $node->getSummaryHtml(); } if ($this->parent != null) $str .= ""; @@ -85,7 +90,7 @@ class Chapter { public function getPage (string $id): ?Page { - foreach ($this->childs as $node) { + foreach ($this->children as $node) { if ($node instanceof Page && $node->getId() == $id) return $node; else if ($node instanceof Chapter) { diff --git a/src/Element/BookContent/Page.php b/src/Element/BookContent/Page.php index e59621a..a900875 100644 --- a/src/Element/BookContent/Page.php +++ b/src/Element/BookContent/Page.php @@ -1,8 +1,11 @@ attributes, $node->configurations, array("name", "id")); } else 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) { case "#text": default: diff --git a/src/Element/Bookshelf.php b/src/Element/Bookshelf.php index 5bf3f60..4ce01e3 100644 --- a/src/Element/Bookshelf.php +++ b/src/Element/Bookshelf.php @@ -1,8 +1,12 @@ nodeValue))) break; + throw new Exception("Unsupported element type \"$rc->nodeName\" in root child of Bookshelf"); default: throw new Exception("Unsupported element type \"$rc->nodeName\" in root child of Bookshelf"); } @@ -64,7 +69,7 @@ class Bookshelf { /** * @throws Exception */ - public static function parseConfiguration(DOMNode $dom, array &$configurations) { + public static function parseConfiguration(DOMNode $dom, array &$configurations): void { for ($rc = $dom->firstChild; $rc != null; $rc = $rc->nextSibling) { if ($rc->nodeName == "#text") { if (!empty(trim($rc->nodeValue))) @@ -87,7 +92,7 @@ class Bookshelf { } } - public static function parseConfigurationAttr (DOMNamedNodeMap $attributes, array &$configurations, array $ignores = array()) { + public static function parseConfigurationAttr (DOMNamedNodeMap $attributes, array &$configurations, array $ignores = array()): void { foreach ($attributes as $attr) { if (in_array($attr->name, $ignores)) continue; $configurations[$attr->name] = $attr->value; diff --git a/src/Element/Link.php b/src/Element/Link.php index 46aab9d..11588c5 100644 --- a/src/Element/Link.php +++ b/src/Element/Link.php @@ -1,6 +1,9 @@ parent; } diff --git a/src/Element/LinkCollection.php b/src/Element/LinkCollection.php index 589e47f..a49ce7d 100644 --- a/src/Element/LinkCollection.php +++ b/src/Element/LinkCollection.php @@ -1,6 +1,9 @@ firstChild; $child != null; $child = $child->nextSibling) { switch ($child->nodeName) { case "Link": - array_push($node->array, Link::parse($child, $node)); + $node->array[] = Link::parse($child, $node); break; case "Collection": - array_push($node->array, LinkCollection::parse($child, $node)); + $node->array[] = LinkCollection::parse($child, $node); break; case "#comment": break; case "#text": if (empty(trim($child->nodeValue))) break; + throw new Exception("Unsupported element type \"$child->nodeName\" in LinkCollection named \"$name\""); default: throw new Exception("Unsupported element type \"$child->nodeName\" in LinkCollection named \"$name\""); } @@ -68,7 +72,7 @@ class LinkCollection { /** * @return LinkCollection|null */ - public function getParent (): LinkCollection { + public function getParent (): ?LinkCollection { return $this->parent; } diff --git a/src/Utils/Markdown/CommonMarkExtensions/ExtensionRef.php b/src/Utils/Markdown/CommonMarkExtensions/ExtensionRef.php index 7ab72f6..fc1100b 100644 --- a/src/Utils/Markdown/CommonMarkExtensions/ExtensionRef.php +++ b/src/Utils/Markdown/CommonMarkExtensions/ExtensionRef.php @@ -1,5 +1,7 @@ - + + - + + ">
diff --git a/template/nav.php b/template/nav.php index 8770322..94464ce 100644 --- a/template/nav.php +++ b/template/nav.php @@ -1,5 +1,5 @@ - - + +