Entity.php 989 B

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