12
12
namespace Symfony \Component \Routing \Matcher \Dumper ;
13
13
14
14
/**
15
- * Collection of routes with attributes
15
+ * Collection of routes with attributes.
16
16
*
17
17
* @author Arnaud Le Blanc <arnaud.lb@gmail.com>
18
18
*/
@@ -23,8 +23,10 @@ class DumperCollection implements \IteratorAggregate
23
23
private $ attributes ;
24
24
25
25
/**
26
- * @param array $routes Array of DumperCollection|DumperRoute
27
- * @param array $atributes Array of attributes
26
+ * Constructor.
27
+ *
28
+ * @param array $routes Array of DumperCollection|DumperRoute
29
+ * @param array $atributes Array of attributes
28
30
*/
29
31
public function __construct (array $ routes = array (), array $ attributes = array ())
30
32
{
@@ -33,7 +35,7 @@ public function __construct(array $routes = array(), array $attributes = array()
33
35
}
34
36
35
37
/**
36
- * Returns the parent collection
38
+ * Returns the parent collection.
37
39
*
38
40
* @return DumperCollection The parent collection
39
41
*/
@@ -43,7 +45,7 @@ public function getParent()
43
45
}
44
46
45
47
/**
46
- * Sets the parent collection
48
+ * Sets the parent collection.
47
49
*
48
50
* @param DumperCollection $parent The parent collection
49
51
*/
@@ -53,7 +55,7 @@ public function setParent(DumperCollection $parent)
53
55
}
54
56
55
57
/**
56
- * Returns the child routes
58
+ * Returns the child routes.
57
59
*
58
60
* @return array Array of DumperCollection|DumperRoute
59
61
*/
@@ -63,9 +65,10 @@ public function getRoutes()
63
65
}
64
66
65
67
/**
66
- * Gets a route by index
68
+ * Gets a route by index.
69
+ *
70
+ * @param int $index The index
67
71
*
68
- * @param int $index The index
69
72
* @return DumperCollection|DumperRoute The route at given index
70
73
*/
71
74
public function getRoute ($ index )
@@ -74,7 +77,7 @@ public function getRoute($index)
74
77
}
75
78
76
79
/**
77
- * Adds a route or route collection
80
+ * Adds a route or route collection.
78
81
*
79
82
* @param DumperCollection|DumperRoute The route or route collection
80
83
*/
@@ -87,9 +90,10 @@ public function addRoute($route)
87
90
}
88
91
89
92
/**
90
- * Returns true if the attribute is defined
93
+ * Returns true if the attribute is defined.
91
94
*
92
95
* @param string $name The attribute name
96
+ *
93
97
* @return Boolean true if the attribute is defined, false otherwise
94
98
*/
95
99
public function has ($ name )
@@ -98,23 +102,20 @@ public function has($name)
98
102
}
99
103
100
104
/**
101
- * Returns an attribute by name
105
+ * Returns an attribute by name.
106
+ *
107
+ * @param string $name The attribute name
108
+ * @param mixed $default Default value is the attribute doesn't exist
102
109
*
103
- * @param string $name The attribute name
104
- * @param mixed $default Default value is the attribute doesn't exist
105
110
* @return mixed The attribute value
106
111
*/
107
112
public function get ($ name , $ default = null )
108
113
{
109
- if ($ this ->has ($ name )) {
110
- return $ this ->attributes [$ name ];
111
- } else {
112
- return $ default ;
113
- }
114
+ return $ this ->has ($ name ) ? $ this ->attributes [$ name ] : $ default ;
114
115
}
115
116
116
117
/**
117
- * Sets an attribute by name
118
+ * Sets an attribute by name.
118
119
*
119
120
* @param string $name The attribute name
120
121
* @param mixed $value The attribute value
@@ -125,7 +126,7 @@ public function set($name, $value)
125
126
}
126
127
127
128
/**
128
- * Returns an iterator over the children
129
+ * Returns an iterator over the children.
129
130
*
130
131
* @return \Iterator The iterator
131
132
*/
@@ -135,11 +136,12 @@ public function getIterator()
135
136
}
136
137
137
138
/**
138
- * Clones the collection and its parents, up to the given parent
139
+ * Clones the collection and its parents, up to the given parent.
139
140
*
140
- * Children are reset
141
+ * Children are reset.
142
+ *
143
+ * @param DumperCollection $until If given, cloning will stop before this parent
141
144
*
142
- * @param DumperCollection $until If given, cloning will stop before this parent
143
145
* @return DumperCollection The cloned collection
144
146
*/
145
147
public function cloneHierarchyUntil (DumperCollection $ until = null )
@@ -160,35 +162,27 @@ public function cloneHierarchyUntil(DumperCollection $until = null)
160
162
}
161
163
162
164
/**
163
- * Returns the root of the collection
165
+ * Returns the root of the collection.
164
166
*
165
167
* @return DumperCollection|null The root collection
166
168
*/
167
169
public function getRoot ()
168
170
{
169
- if (null !== $ parent = $ this ->parent ) {
170
- return $ parent ->getRoot ();
171
- } else {
172
- return $ this ;
173
- }
171
+ return (null !== $ parent = $ this ->parent ) ? $ parent ->getRoot () : $ this ;
174
172
}
175
173
176
174
/**
177
- * Returns an array of parent collections, from the closer parent to the root
175
+ * Returns an array of parent collections, from the closer parent to the root.
178
176
*
179
177
* @return array Array of DumperCollection parents
180
178
*/
181
179
public function getParents ()
182
180
{
183
- if ($ parent = $ this ->parent ) {
184
- return array_merge (array ($ parent ), $ parent ->getParents ());
185
- } else {
186
- return array ();
187
- }
181
+ return $ this ->parent ? array_merge (array ($ this ->parent ), $ this ->parent ->getParents ()) : array ();
188
182
}
189
183
190
184
/**
191
- * Returns an array of this collection and its parents, from this collection to the root
185
+ * Returns an array of this collection and its parents, from this collection to the root.
192
186
*
193
187
* @return array Array of DumperCollection collections
194
188
*/
@@ -198,7 +192,7 @@ public function getParentsAndSelf()
198
192
}
199
193
200
194
/**
201
- * Returns a debug string representation of this collection
195
+ * Returns a debug string representation of this collection.
202
196
*
203
197
* @param Callable $toString Callback used to get the string representation of each individual child
204
198
* @param string $prefix String prepended to each line
@@ -216,4 +210,3 @@ public function toString($toString, $prefix)
216
210
return $ string ;
217
211
}
218
212
}
219
-
0 commit comments