dlindberg /
BlobChunk
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace dlindberg\BlobChunk\Parser; |
||
| 6 | |||
| 7 | use dlindberg\DOMDocumentFactory\DOMDocumentFactory as Doc; |
||
| 8 | use dlindberg\BlobChunk\Manager\CheckNode; |
||
| 9 | |||
| 10 | final class Parser extends BaseParser implements Parse |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var Parse |
||
| 14 | */ |
||
| 15 | public $pairNode; |
||
| 16 | /** |
||
| 17 | * @var Parse |
||
| 18 | */ |
||
| 19 | public $recursiveNode; |
||
| 20 | /** |
||
| 21 | * @var Parse |
||
| 22 | */ |
||
| 23 | public $rowCol; |
||
| 24 | /** |
||
| 25 | * @var Parse |
||
| 26 | */ |
||
| 27 | public $splitChunk; |
||
| 28 | |||
| 29 | public function __construct(CheckNode $manager) |
||
| 30 | { |
||
| 31 | parent::__construct($manager); |
||
| 32 | $this->pairNode = new PairNode($manager); |
||
| 33 | $this->recursiveNode = new RecursiveNode($manager); |
||
| 34 | $this->rowCol = new RowCol($manager); |
||
| 35 | $this->splitChunk = new SplitChunk($manager); |
||
| 36 | } |
||
| 37 | |||
| 38 | public function setDocFactory(Doc $factory): void |
||
| 39 | { |
||
| 40 | parent::setDocFactory($factory); |
||
| 41 | $this->pairNode->setDocFactory($factory); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 42 | $this->recursiveNode->setDocFactory($factory); |
||
| 43 | $this->rowCol->setDocFactory($factory); |
||
| 44 | $this->splitChunk->setDocFactory($factory); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function parse(\DOMElement $node): array |
||
| 48 | { |
||
| 49 | switch ($this->manager->getType($node)) { |
||
| 50 | case ('split'): |
||
| 51 | $content = $this->splitChunk->parse($node); |
||
| 52 | break; |
||
| 53 | case ('recursive'): |
||
| 54 | $content = $this->recursiveNode->parse($node); |
||
| 55 | break; |
||
| 56 | case ('rowCol'): |
||
| 57 | $this->manager->clearRowColParentNode(); |
||
| 58 | $content = $this->rowCol->parse($node); |
||
| 59 | break; |
||
| 60 | case ('pairs'): |
||
| 61 | $this->manager->clearPairParentNode(); |
||
| 62 | $content = $this->pairNode->parse($node); |
||
| 63 | break; |
||
| 64 | case ('special'): |
||
| 65 | default: |
||
| 66 | $content = $this->stringify($node); |
||
| 67 | break; |
||
| 68 | } |
||
| 69 | |||
| 70 | return [ |
||
| 71 | 'tag' => $node->nodeName, |
||
| 72 | 'type' => $this->manager->getType($node), |
||
| 73 | 'content' => $content, |
||
| 74 | ]; |
||
| 75 | } |
||
| 76 | } |
||
| 77 |