Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

DumperPrefixCollection.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 2.67 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Symfony\Component\Routing\Matcher\Dumper;
 013   
 014  /**
 015   * Prefix tree of routes preserving routes order.
 016   *
 017   * @author Arnaud Le Blanc <arnaud.lb@gmail.com>
 018   *
 019   * @internal
 020   */
 021  class DumperPrefixCollection extends DumperCollection
 022  {
 023      /**
 024       * @var string
 025       */
 026      private $prefix = '';
 027   
 028      /**
 029       * Returns the prefix.
 030       *
 031       * @return string The prefix
 032       */
 033      public function getPrefix()
 034      {
 035          return $this->prefix;
 036      }
 037   
 038      /**
 039       * Sets the prefix.
 040       *
 041       * @param string $prefix The prefix
 042       */
 043      public function setPrefix($prefix)
 044      {
 045          $this->prefix = $prefix;
 046      }
 047   
 048      /**
 049       * Adds a route in the tree.
 050       *
 051       * @param DumperRoute $route The route
 052       *
 053       * @return DumperPrefixCollection The node the route was added to
 054       *
 055       * @throws \LogicException
 056       */
 057      public function addPrefixRoute(DumperRoute $route)
 058      {
 059          $prefix = $route->getRoute()->compile()->getStaticPrefix();
 060   
 061          for ($collection = $this; null !== $collection; $collection = $collection->getParent()) {
 062              // Same prefix, add to current leave
 063              if ($collection->prefix === $prefix) {
 064                  $collection->add($route);
 065   
 066                  return $collection;
 067              }
 068   
 069              // Prefix starts with route's prefix
 070              if ('' === $collection->prefix || 0 === strpos($prefix, $collection->prefix)) {
 071                  $child = new self();
 072                  $child->setPrefix(substr($prefix, 0, strlen($collection->prefix) + 1));
 073                  $collection->add($child);
 074   
 075                  return $child->addPrefixRoute($route);
 076              }
 077          }
 078   
 079          // Reached only if the root has a non empty prefix
 080          throw new \LogicException('The collection root must not have a prefix');
 081      }
 082   
 083      /**
 084       * Merges nodes whose prefix ends with a slash.
 085       *
 086       * Children of a node whose prefix ends with a slash are moved to the parent node
 087       */
 088      public function mergeSlashNodes()
 089      {
 090          $children = array();
 091   
 092          foreach ($this as $child) {
 093              if ($child instanceof self) {
 094                  $child->mergeSlashNodes();
 095                  if ('/' === substr($child->prefix, -1)) {
 096                      $children = array_merge($children, $child->all());
 097                  } else {
 098                      $children[] = $child;
 099                  }
 100              } else {
 101                  $children[] = $child;
 102              }
 103          }
 104   
 105          $this->setAll($children);
 106      }
 107  }
 108