1*be906b56SAndreas Gohr<?php 2*be906b56SAndreas Gohr 3*be906b56SAndreas Gohrnamespace dokuwiki\Parsing\ParserMode; 4*be906b56SAndreas Gohr 5*be906b56SAndreas Gohruse dokuwiki\Parsing\Lexer\Lexer; 6*be906b56SAndreas Gohr 7*be906b56SAndreas Gohrclass Entity extends AbstractMode 8*be906b56SAndreas Gohr{ 9*be906b56SAndreas Gohr 10*be906b56SAndreas Gohr protected $entities = array(); 11*be906b56SAndreas Gohr protected $pattern = ''; 12*be906b56SAndreas Gohr 13*be906b56SAndreas Gohr /** 14*be906b56SAndreas Gohr * Entity constructor. 15*be906b56SAndreas Gohr * @param string[] $entities 16*be906b56SAndreas Gohr */ 17*be906b56SAndreas Gohr public function __construct($entities) 18*be906b56SAndreas Gohr { 19*be906b56SAndreas Gohr $this->entities = $entities; 20*be906b56SAndreas Gohr } 21*be906b56SAndreas Gohr 22*be906b56SAndreas Gohr 23*be906b56SAndreas Gohr /** @inheritdoc */ 24*be906b56SAndreas Gohr public function preConnect() 25*be906b56SAndreas Gohr { 26*be906b56SAndreas Gohr if (!count($this->entities) || $this->pattern != '') return; 27*be906b56SAndreas Gohr 28*be906b56SAndreas Gohr $sep = ''; 29*be906b56SAndreas Gohr foreach ($this->entities as $entity) { 30*be906b56SAndreas Gohr $this->pattern .= $sep. Lexer::escape($entity); 31*be906b56SAndreas Gohr $sep = '|'; 32*be906b56SAndreas Gohr } 33*be906b56SAndreas Gohr } 34*be906b56SAndreas Gohr 35*be906b56SAndreas Gohr /** @inheritdoc */ 36*be906b56SAndreas Gohr public function connectTo($mode) 37*be906b56SAndreas Gohr { 38*be906b56SAndreas Gohr if (!count($this->entities)) return; 39*be906b56SAndreas Gohr 40*be906b56SAndreas Gohr if (strlen($this->pattern) > 0) { 41*be906b56SAndreas Gohr $this->Lexer->addSpecialPattern($this->pattern, $mode, 'entity'); 42*be906b56SAndreas Gohr } 43*be906b56SAndreas Gohr } 44*be906b56SAndreas Gohr 45*be906b56SAndreas Gohr /** @inheritdoc */ 46*be906b56SAndreas Gohr public function getSort() 47*be906b56SAndreas Gohr { 48*be906b56SAndreas Gohr return 260; 49*be906b56SAndreas Gohr } 50*be906b56SAndreas Gohr} 51