Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

NodeBuilder.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 5.90 KiB


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