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