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 |
NodeBuilder.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\Config\Definition\Builder;
013
014 /**
015 * This class provides a fluent interface for building a node.
016 *
017 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
018 */
019 class NodeBuilder implements NodeParentInterface
020 {
021 protected $parent;
022 protected $nodeMapping;
023
024 /**
025 * Constructor
026 *
027 */
028 public function __construct()
029 {
030 $this->nodeMapping = array(
031 'variable' => __NAMESPACE__.'\\VariableNodeDefinition',
032 'scalar' => __NAMESPACE__.'\\ScalarNodeDefinition',
033 'boolean' => __NAMESPACE__.'\\BooleanNodeDefinition',
034 'integer' => __NAMESPACE__.'\\IntegerNodeDefinition',
035 'float' => __NAMESPACE__.'\\FloatNodeDefinition',
036 'array' => __NAMESPACE__.'\\ArrayNodeDefinition',
037 'enum' => __NAMESPACE__.'\\EnumNodeDefinition',
038 );
039 }
040
041 /**
042 * Set the parent node.
043 *
044 * @param ParentNodeDefinitionInterface $parent The parent node
045 *
046 * @return NodeBuilder This node builder
047 */
048 public function setParent(ParentNodeDefinitionInterface $parent = null)
049 {
050 $this->parent = $parent;
051
052 return $this;
053 }
054
055 /**
056 * Creates a child array node.
057 *
058 * @param string $name The name of the node
059 *
060 * @return ArrayNodeDefinition The child node
061 */
062 public function arrayNode($name)
063 {
064 return $this->node($name, 'array');
065 }
066
067 /**
068 * Creates a child scalar node.
069 *
070 * @param string $name the name of the node
071 *
072 * @return ScalarNodeDefinition The child node
073 */
074 public function scalarNode($name)
075 {
076 return $this->node($name, 'scalar');
077 }
078
079 /**
080 * Creates a child Boolean node.
081 *
082 * @param string $name The name of the node
083 *
084 * @return BooleanNodeDefinition The child node
085 */
086 public function booleanNode($name)
087 {
088 return $this->node($name, 'boolean');
089 }
090
091 /**
092 * Creates a child integer node.
093 *
094 * @param string $name the name of the node
095 *
096 * @return IntegerNodeDefinition The child node
097 */
098 public function integerNode($name)
099 {
100 return $this->node($name, 'integer');
101 }
102
103 /**
104 * Creates a child float node.
105 *
106 * @param string $name the name of the node
107 *
108 * @return FloatNodeDefinition The child node
109 */
110 public function floatNode($name)
111 {
112 return $this->node($name, 'float');
113 }
114
115 /**
116 * Creates a child EnumNode.
117 *
118 * @param string $name
119 *
120 * @return EnumNodeDefinition
121 */
122 public function enumNode($name)
123 {
124 return $this->node($name, 'enum');
125 }
126
127 /**
128 * Creates a child variable node.
129 *
130 * @param string $name The name of the node
131 *
132 * @return VariableNodeDefinition The builder of the child node
133 */
134 public function variableNode($name)
135 {
136 return $this->node($name, 'variable');
137 }
138
139 /**
140 * Returns the parent node.
141 *
142 * @return ParentNodeDefinitionInterface The parent node
143 */
144 public function end()
145 {
146 return $this->parent;
147 }
148
149 /**
150 * Creates a child node.
151 *
152 * @param string $name The name of the node
153 * @param string $type The type of the node
154 *
155 * @return NodeDefinition The child node
156 *
157 * @throws \RuntimeException When the node type is not registered
158 * @throws \RuntimeException When the node class is not found
159 */
160 public function node($name, $type)
161 {
162 $class = $this->getNodeClass($type);
163
164 $node = new $class($name);
165
166 $this->append($node);
167
168 return $node;
169 }
170
171 /**
172 * Appends a node definition.
173 *
174 * Usage:
175 *
176 * $node = new ArrayNodeDefinition('name')
177 * ->children()
178 * ->scalarNode('foo')->end()
179 * ->scalarNode('baz')->end()
180 * ->append($this->getBarNodeDefinition())
181 * ->end()
182 * ;
183 *
184 * @param NodeDefinition $node
185 *
186 * @return NodeBuilder This node builder
187 */
188 public function append(NodeDefinition $node)
189 {
190 if ($node instanceof ParentNodeDefinitionInterface) {
191 $builder = clone $this;
192 $builder->setParent(null);
193 $node->setBuilder($builder);
194 }
195
196 if (null !== $this->parent) {
197 $this->parent->append($node);
198 // Make this builder the node parent to allow for a fluid interface
199 $node->setParent($this);
200 }
201
202 return $this;
203 }
204
205 /**
206 * Adds or overrides a node Type.
207 *
208 * @param string $type The name of the type
209 * @param string $class The fully qualified name the node definition class
210 *
211 * @return NodeBuilder This node builder
212 */
213 public function setNodeClass($type, $class)
214 {
215 $this->nodeMapping[strtolower($type)] = $class;
216
217 return $this;
218 }
219
220 /**
221 * Returns the class name of the node definition.
222 *
223 * @param string $type The node type
224 *
225 * @return string The node definition class name
226 *
227 * @throws \RuntimeException When the node type is not registered
228 * @throws \RuntimeException When the node class is not found
229 */
230 protected function getNodeClass($type)
231 {
232 $type = strtolower($type);
233
234 if (!isset($this->nodeMapping[$type])) {
235 throw new \RuntimeException(sprintf('The node type "%s" is not registered.', $type));
236 }
237
238 $class = $this->nodeMapping[$type];
239
240 if (!class_exists($class)) {
241 throw new \RuntimeException(sprintf('The node class "%s" does not exist.', $class));
242 }
243
244 return $class;
245 }
246 }
247