[ Index ]

PHP Cross Reference of phpBB-3.3.2-deutsch

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2020 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  
  10  use InvalidArgumentException;
  11  use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
  12  
  13  class ChoiceFilter extends RegexpFilter
  14  {
  15      /**
  16      * Constructor
  17      *
  18      * @param  array $values        List of allowed values
  19      * @param  bool  $caseSensitive Whether the choice is case-sensitive
  20      */
  21  	public function __construct(array $values = null, $caseSensitive = false)
  22      {
  23          parent::__construct();
  24  
  25          if (isset($values))
  26          {
  27              $this->setValues($values, $caseSensitive);
  28          }
  29      }
  30  
  31      /**
  32      * Set the list of allowed values
  33      *
  34      * @param  array $values        List of allowed values
  35      * @param  bool  $caseSensitive Whether the choice is case-sensitive
  36      * @return void
  37      */
  38  	public function setValues(array $values, $caseSensitive = false)
  39      {
  40          if (!is_bool($caseSensitive))
  41          {
  42              throw new InvalidArgumentException('Argument 2 passed to ' . __METHOD__ . ' must be a boolean');
  43          }
  44  
  45          // Create a regexp based on the list of allowed values
  46          $regexp = RegexpBuilder::fromList($values, ['delimiter' => '/']);
  47          $regexp = '/^' . $regexp . '$/D';
  48  
  49          // Add the case-insensitive flag if applicable
  50          if (!$caseSensitive)
  51          {
  52              $regexp .= 'i';
  53          }
  54  
  55          // Add the Unicode flag if the regexp isn't purely ASCII
  56          if (!preg_match('#^[[:ascii:]]*$#D', $regexp))
  57          {
  58              $regexp .= 'u';
  59          }
  60  
  61          // Set the regexp associated with this list of values
  62          $this->setRegexp($regexp);
  63      }
  64  }


Generated: Wed Nov 11 20:28:18 2020 Cross-referenced by PHPXref 0.7.1