1533aca44SAndreas Gohr<?php 2533aca44SAndreas Gohr 3533aca44SAndreas Gohrnamespace dokuwiki\Parsing\Handler; 4533aca44SAndreas Gohr 5533aca44SAndreas Gohr/** 6533aca44SAndreas Gohr * Basic implementation of the rewriter interface to be specialized by children 7533aca44SAndreas Gohr */ 8533aca44SAndreas Gohrabstract class AbstractRewriter implements ReWriterInterface 9533aca44SAndreas Gohr{ 10533aca44SAndreas Gohr /** @var CallWriterInterface original CallWriter */ 11533aca44SAndreas Gohr protected $callWriter; 12533aca44SAndreas Gohr 13533aca44SAndreas Gohr /** @var array[] list of calls */ 14bcaec9f4SAndreas Gohr public $calls = []; 15533aca44SAndreas Gohr 16533aca44SAndreas Gohr /** @inheritdoc */ 17533aca44SAndreas Gohr public function __construct(CallWriterInterface $callWriter) 18533aca44SAndreas Gohr { 19533aca44SAndreas Gohr $this->callWriter = $callWriter; 20533aca44SAndreas Gohr } 21533aca44SAndreas Gohr 22533aca44SAndreas Gohr /** @inheritdoc */ 23533aca44SAndreas Gohr public function writeCall($call) 24533aca44SAndreas Gohr { 25533aca44SAndreas Gohr $this->calls[] = $call; 26533aca44SAndreas Gohr } 27533aca44SAndreas Gohr 28533aca44SAndreas Gohr /** * @inheritdoc */ 29533aca44SAndreas Gohr public function writeCalls($calls) 30533aca44SAndreas Gohr { 31533aca44SAndreas Gohr $this->calls = array_merge($this->calls, $calls); 32533aca44SAndreas Gohr } 33533aca44SAndreas Gohr 34533aca44SAndreas Gohr /** @inheritDoc */ 35533aca44SAndreas Gohr public function getCallWriter() 36533aca44SAndreas Gohr { 37533aca44SAndreas Gohr return $this->callWriter; 38533aca44SAndreas Gohr } 39*8c5fa126SAndreas Gohr 40*8c5fa126SAndreas Gohr /** 41*8c5fa126SAndreas Gohr * Return the instruction name for this block's closing call. 42*8c5fa126SAndreas Gohr */ 43*8c5fa126SAndreas Gohr abstract protected function getClosingCall(): string; 44*8c5fa126SAndreas Gohr 45*8c5fa126SAndreas Gohr /** @inheritdoc */ 46*8c5fa126SAndreas Gohr public function finalise() 47*8c5fa126SAndreas Gohr { 48*8c5fa126SAndreas Gohr $last_call = end($this->calls); 49*8c5fa126SAndreas Gohr $this->writeCall([$this->getClosingCall(), [], $last_call[2]]); 50*8c5fa126SAndreas Gohr 51*8c5fa126SAndreas Gohr $this->process(); 52*8c5fa126SAndreas Gohr $this->callWriter->finalise(); 53*8c5fa126SAndreas Gohr unset($this->callWriter); 54*8c5fa126SAndreas Gohr } 55533aca44SAndreas Gohr} 56