Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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