[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/symfony/routing/Matcher/Dumper/ -> DumperPrefixCollection.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\Routing\Matcher\Dumper;
  13  
  14  /**
  15   * Prefix tree of routes preserving routes order.
  16   *
  17   * @author Arnaud Le Blanc <arnaud.lb@gmail.com>
  18   *
  19   * @internal
  20   */
  21  class DumperPrefixCollection extends DumperCollection
  22  {
  23      /**
  24       * @var string
  25       */
  26      private $prefix = '';
  27  
  28      /**
  29       * Returns the prefix.
  30       *
  31       * @return string The prefix
  32       */
  33      public function getPrefix()
  34      {
  35          return $this->prefix;
  36      }
  37  
  38      /**
  39       * Sets the prefix.
  40       *
  41       * @param string $prefix The prefix
  42       */
  43      public function setPrefix($prefix)
  44      {
  45          $this->prefix = $prefix;
  46      }
  47  
  48      /**
  49       * Adds a route in the tree.
  50       *
  51       * @return self
  52       *
  53       * @throws \LogicException
  54       */
  55      public function addPrefixRoute(DumperRoute $route)
  56      {
  57          $prefix = $route->getRoute()->compile()->getStaticPrefix();
  58  
  59          for ($collection = $this; null !== $collection; $collection = $collection->getParent()) {
  60              // Same prefix, add to current leave
  61              if ($collection->prefix === $prefix) {
  62                  $collection->add($route);
  63  
  64                  return $collection;
  65              }
  66  
  67              // Prefix starts with route's prefix
  68              if ('' === $collection->prefix || 0 === strpos($prefix, $collection->prefix)) {
  69                  $child = new self();
  70                  $child->setPrefix(substr($prefix, 0, \strlen($collection->prefix) + 1));
  71                  $collection->add($child);
  72  
  73                  return $child->addPrefixRoute($route);
  74              }
  75          }
  76  
  77          // Reached only if the root has a non empty prefix
  78          throw new \LogicException('The collection root must not have a prefix');
  79      }
  80  
  81      /**
  82       * Merges nodes whose prefix ends with a slash.
  83       *
  84       * Children of a node whose prefix ends with a slash are moved to the parent node
  85       */
  86      public function mergeSlashNodes()
  87      {
  88          $children = array();
  89  
  90          foreach ($this as $child) {
  91              if ($child instanceof self) {
  92                  $child->mergeSlashNodes();
  93                  if ('/' === substr($child->prefix, -1)) {
  94                      $children = array_merge($children, $child->all());
  95                  } else {
  96                      $children[] = $child;
  97                  }
  98              } else {
  99                  $children[] = $child;
 100              }
 101          }
 102  
 103          $this->setAll($children);
 104      }
 105  }


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