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

NodeDefinition.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 7.34 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  use Symfony\Component\Config\Definition\NodeInterface;
 015  use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
 016   
 017  /**
 018   * This class provides a fluent interface for defining a node.
 019   *
 020   * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 021   */
 022  abstract class NodeDefinition implements NodeParentInterface
 023  {
 024      protected $name;
 025      protected $normalization;
 026      protected $validation;
 027      protected $defaultValue;
 028      protected $default = false;
 029      protected $required = false;
 030      protected $merge;
 031      protected $allowEmptyValue = true;
 032      protected $nullEquivalent;
 033      protected $trueEquivalent = true;
 034      protected $falseEquivalent = false;
 035   
 036      /**
 037       * @var NodeParentInterface|null
 038       */
 039      protected $parent;
 040      protected $attributes = array();
 041   
 042      /**
 043       * Constructor.
 044       *
 045       * @param string                   $name   The name of the node
 046       * @param NodeParentInterface|null $parent The parent
 047       */
 048      public function __construct($name, NodeParentInterface $parent = null)
 049      {
 050          $this->parent = $parent;
 051          $this->name = $name;
 052      }
 053   
 054      /**
 055       * Sets the parent node.
 056       *
 057       * @param NodeParentInterface $parent The parent
 058       *
 059       * @return NodeDefinition|$this
 060       */
 061      public function setParent(NodeParentInterface $parent)
 062      {
 063          $this->parent = $parent;
 064   
 065          return $this;
 066      }
 067   
 068      /**
 069       * Sets info message.
 070       *
 071       * @param string $info The info text
 072       *
 073       * @return NodeDefinition|$this
 074       */
 075      public function info($info)
 076      {
 077          return $this->attribute('info', $info);
 078      }
 079   
 080      /**
 081       * Sets example configuration.
 082       *
 083       * @param string|array $example
 084       *
 085       * @return NodeDefinition|$this
 086       */
 087      public function example($example)
 088      {
 089          return $this->attribute('example', $example);
 090      }
 091   
 092      /**
 093       * Sets an attribute on the node.
 094       *
 095       * @param string $key
 096       * @param mixed  $value
 097       *
 098       * @return NodeDefinition|$this
 099       */
 100      public function attribute($key, $value)
 101      {
 102          $this->attributes[$key] = $value;
 103   
 104          return $this;
 105      }
 106   
 107      /**
 108       * Returns the parent node.
 109       *
 110       * @return NodeParentInterface|NodeBuilder|NodeDefinition|null The builder of the parent node
 111       */
 112      public function end()
 113      {
 114          return $this->parent;
 115      }
 116   
 117      /**
 118       * Creates the node.
 119       *
 120       * @param bool $forceRootNode Whether to force this node as the root node
 121       *
 122       * @return NodeInterface
 123       */
 124      public function getNode($forceRootNode = false)
 125      {
 126          if ($forceRootNode) {
 127              $this->parent = null;
 128          }
 129   
 130          if (null !== $this->normalization) {
 131              $this->normalization->before = ExprBuilder::buildExpressions($this->normalization->before);
 132          }
 133   
 134          if (null !== $this->validation) {
 135              $this->validation->rules = ExprBuilder::buildExpressions($this->validation->rules);
 136          }
 137   
 138          $node = $this->createNode();
 139          $node->setAttributes($this->attributes);
 140   
 141          return $node;
 142      }
 143   
 144      /**
 145       * Sets the default value.
 146       *
 147       * @param mixed $value The default value
 148       *
 149       * @return NodeDefinition|$this
 150       */
 151      public function defaultValue($value)
 152      {
 153          $this->default = true;
 154          $this->defaultValue = $value;
 155   
 156          return $this;
 157      }
 158   
 159      /**
 160       * Sets the node as required.
 161       *
 162       * @return NodeDefinition|$this
 163       */
 164      public function isRequired()
 165      {
 166          $this->required = true;
 167   
 168          return $this;
 169      }
 170   
 171      /**
 172       * Sets the equivalent value used when the node contains null.
 173       *
 174       * @param mixed $value
 175       *
 176       * @return NodeDefinition|$this
 177       */
 178      public function treatNullLike($value)
 179      {
 180          $this->nullEquivalent = $value;
 181   
 182          return $this;
 183      }
 184   
 185      /**
 186       * Sets the equivalent value used when the node contains true.
 187       *
 188       * @param mixed $value
 189       *
 190       * @return NodeDefinition|$this
 191       */
 192      public function treatTrueLike($value)
 193      {
 194          $this->trueEquivalent = $value;
 195   
 196          return $this;
 197      }
 198   
 199      /**
 200       * Sets the equivalent value used when the node contains false.
 201       *
 202       * @param mixed $value
 203       *
 204       * @return NodeDefinition|$this
 205       */
 206      public function treatFalseLike($value)
 207      {
 208          $this->falseEquivalent = $value;
 209   
 210          return $this;
 211      }
 212   
 213      /**
 214       * Sets null as the default value.
 215       *
 216       * @return NodeDefinition|$this
 217       */
 218      public function defaultNull()
 219      {
 220          return $this->defaultValue(null);
 221      }
 222   
 223      /**
 224       * Sets true as the default value.
 225       *
 226       * @return NodeDefinition|$this
 227       */
 228      public function defaultTrue()
 229      {
 230          return $this->defaultValue(true);
 231      }
 232   
 233      /**
 234       * Sets false as the default value.
 235       *
 236       * @return NodeDefinition|$this
 237       */
 238      public function defaultFalse()
 239      {
 240          return $this->defaultValue(false);
 241      }
 242   
 243      /**
 244       * Sets an expression to run before the normalization.
 245       *
 246       * @return ExprBuilder
 247       */
 248      public function beforeNormalization()
 249      {
 250          return $this->normalization()->before();
 251      }
 252   
 253      /**
 254       * Denies the node value being empty.
 255       *
 256       * @return NodeDefinition|$this
 257       */
 258      public function cannotBeEmpty()
 259      {
 260          $this->allowEmptyValue = false;
 261   
 262          return $this;
 263      }
 264   
 265      /**
 266       * Sets an expression to run for the validation.
 267       *
 268       * The expression receives the value of the node and must return it. It can
 269       * modify it.
 270       * An exception should be thrown when the node is not valid.
 271       *
 272       * @return ExprBuilder
 273       */
 274      public function validate()
 275      {
 276          return $this->validation()->rule();
 277      }
 278   
 279      /**
 280       * Sets whether the node can be overwritten.
 281       *
 282       * @param bool $deny Whether the overwriting is forbidden or not
 283       *
 284       * @return NodeDefinition|$this
 285       */
 286      public function cannotBeOverwritten($deny = true)
 287      {
 288          $this->merge()->denyOverwrite($deny);
 289   
 290          return $this;
 291      }
 292   
 293      /**
 294       * Gets the builder for validation rules.
 295       *
 296       * @return ValidationBuilder
 297       */
 298      protected function validation()
 299      {
 300          if (null === $this->validation) {
 301              $this->validation = new ValidationBuilder($this);
 302          }
 303   
 304          return $this->validation;
 305      }
 306   
 307      /**
 308       * Gets the builder for merging rules.
 309       *
 310       * @return MergeBuilder
 311       */
 312      protected function merge()
 313      {
 314          if (null === $this->merge) {
 315              $this->merge = new MergeBuilder($this);
 316          }
 317   
 318          return $this->merge;
 319      }
 320   
 321      /**
 322       * Gets the builder for normalization rules.
 323       *
 324       * @return NormalizationBuilder
 325       */
 326      protected function normalization()
 327      {
 328          if (null === $this->normalization) {
 329              $this->normalization = new NormalizationBuilder($this);
 330          }
 331   
 332          return $this->normalization;
 333      }
 334   
 335      /**
 336       * Instantiate and configure the node according to this definition.
 337       *
 338       * @return NodeInterface $node The node instance
 339       *
 340       * @throws InvalidDefinitionException When the definition is invalid
 341       */
 342      abstract protected function createNode();
 343  }
 344