comparison vendor/symfony/routing/Matcher/Dumper/DumperCollection.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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 * Collection of routes.
16 *
17 * @author Arnaud Le Blanc <arnaud.lb@gmail.com>
18 *
19 * @internal
20 */
21 class DumperCollection implements \IteratorAggregate
22 {
23 /**
24 * @var DumperCollection|null
25 */
26 private $parent;
27
28 /**
29 * @var DumperCollection[]|DumperRoute[]
30 */
31 private $children = array();
32
33 /**
34 * @var array
35 */
36 private $attributes = array();
37
38 /**
39 * Returns the children routes and collections.
40 *
41 * @return self[]|DumperRoute[]
42 */
43 public function all()
44 {
45 return $this->children;
46 }
47
48 /**
49 * Adds a route or collection.
50 *
51 * @param DumperRoute|DumperCollection The route or collection
52 */
53 public function add($child)
54 {
55 if ($child instanceof self) {
56 $child->setParent($this);
57 }
58 $this->children[] = $child;
59 }
60
61 /**
62 * Sets children.
63 *
64 * @param array $children The children
65 */
66 public function setAll(array $children)
67 {
68 foreach ($children as $child) {
69 if ($child instanceof self) {
70 $child->setParent($this);
71 }
72 }
73 $this->children = $children;
74 }
75
76 /**
77 * Returns an iterator over the children.
78 *
79 * @return \Iterator|DumperCollection[]|DumperRoute[] The iterator
80 */
81 public function getIterator()
82 {
83 return new \ArrayIterator($this->children);
84 }
85
86 /**
87 * Returns the root of the collection.
88 *
89 * @return self The root collection
90 */
91 public function getRoot()
92 {
93 return (null !== $this->parent) ? $this->parent->getRoot() : $this;
94 }
95
96 /**
97 * Returns the parent collection.
98 *
99 * @return self|null The parent collection or null if the collection has no parent
100 */
101 protected function getParent()
102 {
103 return $this->parent;
104 }
105
106 /**
107 * Sets the parent collection.
108 *
109 * @param DumperCollection $parent The parent collection
110 */
111 protected function setParent(DumperCollection $parent)
112 {
113 $this->parent = $parent;
114 }
115
116 /**
117 * Returns true if the attribute is defined.
118 *
119 * @param string $name The attribute name
120 *
121 * @return bool true if the attribute is defined, false otherwise
122 */
123 public function hasAttribute($name)
124 {
125 return array_key_exists($name, $this->attributes);
126 }
127
128 /**
129 * Returns an attribute by name.
130 *
131 * @param string $name The attribute name
132 * @param mixed $default Default value is the attribute doesn't exist
133 *
134 * @return mixed The attribute value
135 */
136 public function getAttribute($name, $default = null)
137 {
138 return $this->hasAttribute($name) ? $this->attributes[$name] : $default;
139 }
140
141 /**
142 * Sets an attribute by name.
143 *
144 * @param string $name The attribute name
145 * @param mixed $value The attribute value
146 */
147 public function setAttribute($name, $value)
148 {
149 $this->attributes[$name] = $value;
150 }
151
152 /**
153 * Sets multiple attributes.
154 *
155 * @param array $attributes The attributes
156 */
157 public function setAttributes($attributes)
158 {
159 $this->attributes = $attributes;
160 }
161 }