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