Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
DumperPrefixCollection.php
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 class DumperPrefixCollection extends DumperCollection
020 {
021 /**
022 * @var string
023 */
024 private $prefix = '';
025
026 /**
027 * Returns the prefix.
028 *
029 * @return string The prefix
030 */
031 public function getPrefix()
032 {
033 return $this->prefix;
034 }
035
036 /**
037 * Sets the prefix.
038 *
039 * @param string $prefix The prefix
040 */
041 public function setPrefix($prefix)
042 {
043 $this->prefix = $prefix;
044 }
045
046 /**
047 * Adds a route in the tree.
048 *
049 * @param DumperRoute $route The route
050 *
051 * @return DumperPrefixCollection The node the route was added to
052 *
053 * @throws \LogicException
054 */
055 public function addPrefixRoute(DumperRoute $route)
056 {
057 $prefix = $route->getRoute()->compile()->getStaticPrefix();
058
059 for ($collection = $this; null !== $collection; $collection = $collection->getParent()) {
060 // Same prefix, add to current leave
061 if ($collection->prefix === $prefix) {
062 $collection->add($route);
063
064 return $collection;
065 }
066
067 // Prefix starts with route's prefix
068 if ('' === $collection->prefix || 0 === strpos($prefix, $collection->prefix)) {
069 $child = new DumperPrefixCollection();
070 $child->setPrefix(substr($prefix, 0, strlen($collection->prefix)+1));
071 $collection->add($child);
072
073 return $child->addPrefixRoute($route);
074 }
075 }
076
077 // Reached only if the root has a non empty prefix
078 throw new \LogicException("The collection root must not have a prefix");
079 }
080
081 /**
082 * Merges nodes whose prefix ends with a slash
083 *
084 * Children of a node whose prefix ends with a slash are moved to the parent node
085 */
086 public function mergeSlashNodes()
087 {
088 $children = array();
089
090 foreach ($this as $child) {
091 if ($child instanceof self) {
092 $child->mergeSlashNodes();
093 if ('/' === substr($child->prefix, -1)) {
094 $children = array_merge($children, $child->all());
095 } else {
096 $children[] = $child;
097 }
098 } else {
099 $children[] = $child;
100 }
101 }
102
103 $this->setAll($children);
104 }
105 }
106