| 1 | <?php |
||
| 7 | abstract class AbstractNode |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var AbstractParentNode |
||
| 11 | */ |
||
| 12 | protected $parent; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var bool |
||
| 16 | */ |
||
| 17 | protected $allowSerializeEmpty; |
||
| 18 | |||
| 19 | 21 | protected function __construct() |
|
| 20 | { |
||
| 21 | 21 | } |
|
| 22 | |||
| 23 | 1 | public function __clone() |
|
| 24 | { |
||
| 25 | 1 | $this->parent = null; |
|
| 26 | 1 | } |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @param AbstractParentNode $parent |
||
| 30 | * |
||
| 31 | * @throws \InvalidArgumentException |
||
| 32 | */ |
||
| 33 | 21 | public function setParent(AbstractParentNode $parent) |
|
| 34 | { |
||
| 35 | 21 | if (null !== $this->parent) { |
|
| 36 | 1 | throw new \InvalidArgumentException('Node already got a parent!'); |
|
| 37 | } |
||
| 38 | |||
| 39 | 21 | $this->parent = $parent; |
|
| 40 | 21 | } |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @return AbstractParentNode|null |
||
| 44 | */ |
||
| 45 | 1 | public function getParent() |
|
| 46 | { |
||
| 47 | 1 | return $this->parent; |
|
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return bool |
||
| 52 | */ |
||
| 53 | 5 | public function isAllowSerializeEmpty(): bool |
|
| 54 | { |
||
| 55 | 5 | return $this->allowSerializeEmpty; |
|
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return \stdClass|array|null |
||
| 60 | */ |
||
| 61 | abstract public function serializeEmpty(); |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return \stdClass|array|string|float|int|bool|null |
||
| 65 | */ |
||
| 66 | abstract public function serialize(); |
||
| 67 | } |
||
| 68 |