diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
commit | 4f5b44bd3bd490309eb2ba7b44df4769816ba729 (patch) | |
tree | 6cefe170dfe0a5a361cb1e2d1fc4d580a3316d02 /vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php | |
parent | 2b840e0cfb63a453bea67a98541f3df9c273c5f5 (diff) | |
download | wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.gz wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.zst wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.zip |
twig implementation
Diffstat (limited to 'vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php')
-rw-r--r-- | vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php b/vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php new file mode 100644 index 00000000..26382b0b --- /dev/null +++ b/vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php | |||
@@ -0,0 +1,108 @@ | |||
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 | class DumperPrefixCollection extends DumperCollection | ||
20 | { | ||
21 | /** | ||
22 | * @var string | ||
23 | */ | ||
24 | private $prefix = ''; | ||
25 | |||
26 | /** | ||
27 | * Returns the prefix. | ||
28 | * | ||
29 | * @return string The prefix | ||
30 | */ | ||
31 | public function getPrefix() | ||
32 | { | ||
33 | return $this->prefix; | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * Sets the prefix. | ||
38 | * | ||
39 | * @param string $prefix The prefix | ||
40 | */ | ||
41 | public function setPrefix($prefix) | ||
42 | { | ||
43 | $this->prefix = $prefix; | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Adds a route in the tree. | ||
48 | * | ||
49 | * @param DumperRoute $route The route | ||
50 | * | ||
51 | * @return DumperPrefixCollection The node the route was added to | ||
52 | * | ||
53 | * @throws \LogicException | ||
54 | */ | ||
55 | public function addPrefixRoute(DumperRoute $route) | ||
56 | { | ||
57 | $prefix = $route->getRoute()->compile()->getStaticPrefix(); | ||
58 | |||
59 | // Same prefix, add to current leave | ||
60 | if ($this->prefix === $prefix) { | ||
61 | $this->add($route); | ||
62 | |||
63 | return $this; | ||
64 | } | ||
65 | |||
66 | // Prefix starts with route's prefix | ||
67 | if ('' === $this->prefix || 0 === strpos($prefix, $this->prefix)) { | ||
68 | $collection = new DumperPrefixCollection(); | ||
69 | $collection->setPrefix(substr($prefix, 0, strlen($this->prefix)+1)); | ||
70 | $this->add($collection); | ||
71 | |||
72 | return $collection->addPrefixRoute($route); | ||
73 | } | ||
74 | |||
75 | // No match, fallback to parent (recursively) | ||
76 | |||
77 | if (null === $parent = $this->getParent()) { | ||
78 | throw new \LogicException("The collection root must not have a prefix"); | ||
79 | } | ||
80 | |||
81 | return $parent->addPrefixRoute($route); | ||
82 | } | ||
83 | |||
84 | /** | ||
85 | * Merges nodes whose prefix ends with a slash | ||
86 | * | ||
87 | * Children of a node whose prefix ends with a slash are moved to the parent node | ||
88 | */ | ||
89 | public function mergeSlashNodes() | ||
90 | { | ||
91 | $children = array(); | ||
92 | |||
93 | foreach ($this as $child) { | ||
94 | if ($child instanceof self) { | ||
95 | $child->mergeSlashNodes(); | ||
96 | if ('/' === substr($child->prefix, -1)) { | ||
97 | $children = array_merge($children, $child->all()); | ||
98 | } else { | ||
99 | $children[] = $child; | ||
100 | } | ||
101 | } else { | ||
102 | $children[] = $child; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | $this->setAll($children); | ||
107 | } | ||
108 | } | ||