[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Plugins/Keywords/ -> Configurator.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\Plugins\Keywords;
   9  use s9e\TextFormatter\Configurator\Collections\NormalizedList;
  10  use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
  11  use s9e\TextFormatter\Configurator\Items\Regexp;
  12  use s9e\TextFormatter\Configurator\Traits\CollectionProxy;
  13  use s9e\TextFormatter\Plugins\ConfiguratorBase;
  14  class Configurator extends ConfiguratorBase
  15  {
  16      use CollectionProxy;
  17      protected $attrName = 'value';
  18      public $caseSensitive = \true;
  19      protected $collection;
  20      public $onlyFirst = \false;
  21      protected $tagName = 'KEYWORD';
  22  	protected function setUp()
  23      {
  24          $this->collection = new NormalizedList;
  25          $this->configurator->tags->add($this->tagName)->attributes->add($this->attrName);
  26      }
  27  	public function asConfig()
  28      {
  29          if (!\count($this->collection))
  30              return;
  31          $config = [
  32              'attrName' => $this->attrName,
  33              'tagName'  => $this->tagName
  34          ];
  35          if (!empty($this->onlyFirst))
  36              $config['onlyFirst'] = $this->onlyFirst;
  37          $keywords = \array_unique(\iterator_to_array($this->collection));
  38          \sort($keywords);
  39          $groups   = [];
  40          $groupKey = 0;
  41          $groupLen = 0;
  42          foreach ($keywords as $keyword)
  43          {
  44              $keywordLen  = 4 + \strlen($keyword);
  45              $groupLen   += $keywordLen;
  46              if ($groupLen > 30000)
  47              {
  48                  $groupLen = $keywordLen;
  49                  ++$groupKey;
  50              }
  51              $groups[$groupKey][] = $keyword;
  52          }
  53          foreach ($groups as $keywords)
  54          {
  55              $regexp = RegexpBuilder::fromList(
  56                  $keywords,
  57                  ['caseInsensitive' => !$this->caseSensitive]
  58              );
  59              $regexp = '/\\b' . $regexp . '\\b/S';
  60              if (!$this->caseSensitive)
  61                  $regexp .= 'i';
  62              if (\preg_match('/[^[:ascii:]]/', $regexp))
  63                  $regexp .= 'u';
  64              $config['regexps'][] = new Regexp($regexp, \true);
  65          }
  66          return $config;
  67      }
  68  }


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