[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/s9e/regexp-builder/src/Passes/ -> Recurse.php (source)

   1  <?php declare(strict_types=1);
   2  
   3  /**
   4  * @package   s9e\RegexpBuilder
   5  * @copyright Copyright (c) 2016-2022 The s9e authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\RegexpBuilder\Passes;
   9  
  10  use function array_map, is_array;
  11  use s9e\RegexpBuilder\Runner;
  12  
  13  /**
  14  * Enables passes to be run recursively into alternations to replace a(?:x0|x1|y0|y1) with a[xy][01]
  15  */
  16  class Recurse extends AbstractPass
  17  {
  18      /**
  19      * @var Runner
  20      */
  21      protected $runner;
  22  
  23      /**
  24      * @param Runner $runner
  25      */
  26  	public function __construct(Runner $runner)
  27      {
  28          $this->runner = $runner;
  29      }
  30  
  31      /**
  32      * {@inheritdoc}
  33      */
  34  	protected function runPass(array $strings): array
  35      {
  36          return array_map([$this, 'recurseString'], $strings);
  37      }
  38  
  39      /**
  40      * Recurse into given string and run all passes on each element
  41      *
  42      * @param  array $string
  43      * @return array
  44      */
  45  	protected function recurseString(array $string): array
  46      {
  47          $isOptional = $this->isOptional;
  48          foreach ($string as $k => $element)
  49          {
  50              if (is_array($element))
  51              {
  52                  $string[$k] = $this->runner->run($element);
  53              }
  54          }
  55          $this->isOptional = $isOptional;
  56  
  57          return $string;
  58      }
  59  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1