mirror of
https://github.com/suk-ws/ph-Bookshelf.git
synced 2024-12-05 01:16:53 +08:00
修复了Collection和Chapter在其特殊父类中的null值调用的问题
This commit is contained in:
parent
0d34dfb04e
commit
9d86fd5e53
@ -10,9 +10,9 @@ class BookCollection {
|
||||
|
||||
/** @var Book[]|BookCollection[] */
|
||||
private array $array;
|
||||
private BookCollection $parent;
|
||||
private ?BookCollection $parent;
|
||||
|
||||
private function __construct (string $name, array $a, BookCollection $parent) {
|
||||
private function __construct (string $name, array $a, ?BookCollection $parent) {
|
||||
$this->name = $name;
|
||||
$this->array = $a;
|
||||
$this->parent = $parent;
|
||||
@ -20,12 +20,12 @@ class BookCollection {
|
||||
|
||||
/**
|
||||
* @param DOMNode $root
|
||||
* @param BookCollection $parent
|
||||
* @param ?BookCollection $parent
|
||||
* @param bool $isRoot
|
||||
* @return BookCollection
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function parse (DOMNode $root, BookCollection $parent, bool $isRoot = false): BookCollection {
|
||||
public static function parse (DOMNode $root, ?BookCollection $parent, bool $isRoot = false): BookCollection {
|
||||
$name = BookCollection::ROOT;
|
||||
if (!$isRoot) {
|
||||
if ($root->hasAttributes()) {
|
||||
|
@ -9,9 +9,9 @@ class Chapter {
|
||||
/** @var Chapter[]|Page[] */
|
||||
private array $childs;
|
||||
|
||||
private Chapter $parent;
|
||||
private ?Chapter $parent;
|
||||
|
||||
private function __construct (string $name, array $array, Chapter $parent) {
|
||||
private function __construct (string $name, array $array, ?Chapter $parent) {
|
||||
$this->name = $name;
|
||||
$this->childs = $array;
|
||||
$this->parent = $parent;
|
||||
@ -19,11 +19,11 @@ class Chapter {
|
||||
|
||||
/**
|
||||
* @param DOMNode $xmlData
|
||||
* @param Chapter $parent
|
||||
* @param ?Chapter $parent
|
||||
* @return Chapter
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function parse (DOMNode $xmlData, Chapter $parent): 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\"");
|
||||
|
@ -10,9 +10,9 @@ class LinkCollection {
|
||||
|
||||
/** @var Link[]|LinkCollection[] */
|
||||
private array $array;
|
||||
private LinkCollection $parent;
|
||||
private ?LinkCollection $parent;
|
||||
|
||||
private function __construct (string $name, array $a, LinkCollection $parent) {
|
||||
private function __construct (string $name, array $a, ?LinkCollection $parent) {
|
||||
$this->name = $name;
|
||||
$this->array = $a;
|
||||
$this->parent = $parent;
|
||||
@ -20,12 +20,12 @@ class LinkCollection {
|
||||
|
||||
/**
|
||||
* @param DOMNode $root
|
||||
* @param LinkCollection $parent
|
||||
* @param ?LinkCollection $parent
|
||||
* @param bool $isRoot
|
||||
* @return LinkCollection
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function parse (DOMNode $root, LinkCollection $parent, bool $isRoot = false): LinkCollection {
|
||||
public static function parse (DOMNode $root, ?LinkCollection $parent, bool $isRoot = false): LinkCollection {
|
||||
$name = LinkCollection::ROOT;
|
||||
if (!$isRoot) {
|
||||
if ($root->hasAttributes()) {
|
||||
|
Loading…
Reference in New Issue
Block a user