[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Configurator/Items/AttributeFilters/ -> HashmapFilter.php (source)

   1  <?php
   2  
   3  /*
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2019 The s9e Authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Configurator\Items\AttributeFilters;
   9  use InvalidArgumentException;
  10  use RuntimeException;
  11  use s9e\TextFormatter\Configurator\Helpers\ContextSafeness;
  12  use s9e\TextFormatter\Configurator\Items\AttributeFilter;
  13  use s9e\TextFormatter\Configurator\JavaScript\Dictionary;
  14  class HashmapFilter extends AttributeFilter
  15  {
  16  	public function __construct(array $map = \null, $strict = \false)
  17      {
  18          parent::__construct('s9e\\TextFormatter\\Parser\\AttributeFilters\\HashmapFilter::filter');
  19          $this->resetParameters();
  20          $this->addParameterByName('attrValue');
  21          $this->addParameterByName('map');
  22          $this->addParameterByName('strict');
  23          $this->setJS('HashmapFilter.filter');
  24          if (isset($map))
  25              $this->setMap($map, $strict);
  26      }
  27  	public function asConfig()
  28      {
  29          if (!isset($this->vars['map']))
  30              throw new RuntimeException("Hashmap filter is missing a 'map' value");
  31          return parent::asConfig();
  32      }
  33  	public function setMap(array $map, $strict = \false)
  34      {
  35          if (!\is_bool($strict))
  36              throw new InvalidArgumentException('Argument 2 passed to ' . __METHOD__ . ' must be a boolean');
  37          if (!$strict)
  38              $map = $this->optimizeLooseMap($map);
  39          \ksort($map);
  40          $this->vars['map']    = new Dictionary($map);
  41          $this->vars['strict'] = $strict;
  42          $this->resetSafeness();
  43          if (!empty($this->vars['strict']))
  44          {
  45              $this->evaluateSafenessInCSS();
  46              $this->evaluateSafenessInJS();
  47          }
  48      }
  49  	protected function evaluateSafenessInCSS()
  50      {
  51          $disallowedChars = ContextSafeness::getDisallowedCharactersInCSS();
  52          foreach ($this->vars['map'] as $value)
  53              foreach ($disallowedChars as $char)
  54                  if (\strpos($value, $char) !== \false)
  55                      return;
  56          $this->markAsSafeInCSS();
  57      }
  58  	protected function evaluateSafenessInJS()
  59      {
  60          $disallowedChars = ContextSafeness::getDisallowedCharactersInJS();
  61          foreach ($this->vars['map'] as $value)
  62              foreach ($disallowedChars as $char)
  63                  if (\strpos($value, $char) !== \false)
  64                      return;
  65          $this->markAsSafeInJS();
  66      }
  67  	protected function optimizeLooseMap(array $map)
  68      {
  69          foreach ($map as $k => $v)
  70              if ($k === $v)
  71                  unset($map[$k]);
  72          return $map;
  73      }
  74  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1