<?php
namespace App\Utils\BaseParser\TextParser\Types; class ContainerRepeatableRegexp extends \App\Utils\BaseParser\TextParser\BlockAbstract { protected $matcher = null; public function __construct($options = [], $parent = null) { $this->matcher = new \App\Utils\BaseParser\Utils\Extractor\Single(); parent::__construct($options, $parent); if(!$this->options['blockRepeats']) { throw new \Exception("This container should be repeatable"); } } public function isValid() { \Engine\Debug\ParserCallTrace\ParserCallTrace::getInstance()->logCallStart($this, __METHOD__, func_get_args()); \Engine\Debug\ParserCallTrace\ParserCallTrace::getInstance()->logInput([ 'key' => $this->options['key'], 'rawData' => $this->rawData, ]); \Engine\Debug\ParserCallTrace\ParserCallTrace::getInstance()->logInput([ ], 'regexp'); $ret = $this->matcher->contains($this->options['isValid'], $this->rawData); \Engine\Debug\ParserCallTrace\ParserCallTrace::getInstance()->logOutput([ 'return' => $ret, ]); \Engine\Debug\ParserCallTrace\ParserCallTrace::getInstance()->logCallEnd(); return $ret; } protected function _extract(\App\Utils\BaseParser\TextParser\ExtractedBlock $ret, $originalRawData) { $remainingRawData = $originalRawData; $this->rawData = $remainingRawData; $repIndex = 0; $repLoop = true; $ret->extractedData = []; while ($repLoop) { $repLoop = false; if ($this->isValid()) { $repLoop = true; } if ($repIndex<$this->options['blockRepeats'][0]) { $repLoop = true; } if ($repLoop) { $exret = new \App\Utils\BaseParser\TextParser\ExtractedBlock(); $exret->remainingGlobalData = $remainingRawData; $exret = $this->_extract_children($exret, $this->options['children'], $remainingRawData, [$this, "_extract_children_callback_associativeArray"]); $ret->extractedData[] = $exret->extractedData; $remainingRawData = $exret->remainingGlobalData; $this->rawData = $remainingRawData; } $repIndex++; if ($repIndex>=$this->options['blockRepeats'][1]) { $repLoop = false; } } $ret->remainingGlobalData = $remainingRawData; return $ret; } } 