* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Config\Definition\Builder; use Symfony\Component\Config\Definition\NodeInterface; use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException; /** * This class provides a fluent interface for defining a node. * * @author Johannes M. Schmitt */ abstract class NodeDefinition implements NodeParentInterface { protected $name; protected $normalization; protected $validation; protected $defaultValue; protected $default = false; protected $required = false; protected $deprecationMessage = null; protected $merge; protected $allowEmptyValue = true; protected $nullEquivalent; protected $trueEquivalent = true; protected $falseEquivalent = false; protected $parent; protected $attributes = array(); /** * @param string|null $name The name of the node * @param NodeParentInterface|null $parent The parent */ public function __construct($name, NodeParentInterface $parent = null) { $this->parent = $parent; $this->name = $name; } /** * Sets the parent node. * * @return $this */ public function setParent(NodeParentInterface $parent) { $this->parent = $parent; return $this; } /** * Sets info message. * * @param string $info The info text * * @return $this */ public function info($info) { return $this->attribute('info', $info); } /** * Sets example configuration. * * @param string|array $example * * @return $this */ public function example($example) { return $this->attribute('example', $example); } /** * Sets an attribute on the node. * * @param string $key * @param mixed $value * * @return $this */ public function attribute($key, $value) { $this->attributes[$key] = $value; return $this; } /** * Returns the parent node. * * @return NodeParentInterface|NodeBuilder|NodeDefinition|ArrayNodeDefinition|VariableNodeDefinition|null The builder of the parent node */ public function end() { return $this->parent; } /** * Creates the node. * * @param bool $forceRootNode Whether to force this node as the root node * * @return NodeInterface */ public function getNode($forceRootNode = false) { if ($forceRootNode) { $this->parent = null; } if (null !== $this->normalization) { $this->normalization->before = ExprBuilder::buildExpressions($this->normalization->before); } if (null !== $this->validation) { $this->validation->rules = ExprBuilder::buildExpressions($this->validation->rules); } $node = $this->createNode(); $node->setAttributes($this->attributes); return $node; } /** * Sets the default value. * * @param mixed $value The default value * * @return $this */ public function defaultValue($value) { $this->default = true; $this->defaultValue = $value; return $this; } /** * Sets the node as required. * * @return $this */ public function isRequired() { $this->required = true; return $this; } /** * Sets the node as deprecated. * * You can use %node% and %path% placeholders in your message to display, * respectively, the node name and its complete path. * * @param string $message Deprecation message * * @return $this */ public function setDeprecated($message = 'The child node "%node%" at path "%path%" is deprecated.') { $this->deprecationMessage = $message; return $this; } /** * Sets the equivalent value used when the node contains null. * * @param mixed $value * * @return $this */ public function treatNullLike($value) { $this->nullEquivalent = $value; return $this; } /** * Sets the equivalent value used when the node contains true. * * @param mixed $value * * @return $this */ public function treatTrueLike($value) { $this->trueEquivalent = $value; return $this; } /** * Sets the equivalent value used when the node contains false. * * @param mixed $value * * @return $this */ public function treatFalseLike($value) { $this->falseEquivalent = $value; return $this; } /** * Sets null as the default value. * * @return $this */ public function defaultNull() { return $this->defaultValue(null); } /** * Sets true as the default value. * * @return $this */ public function defaultTrue() { return $this->defaultValue(true); } /** * Sets false as the default value. * * @return $this */ public function defaultFalse() { return $this->defaultValue(false); } /** * Sets an expression to run before the normalization. * * @return ExprBuilder */ public function beforeNormalization() { return $this->normalization()->before(); } /** * Denies the node value being empty. * * @return $this */ public function cannotBeEmpty() { $this->allowEmptyValue = false; return $this; } /** * Sets an expression to run for the validation. * * The expression receives the value of the node and must return it. It can * modify it. * An exception should be thrown when the node is not valid. * * @return ExprBuilder */ public function validate() { return $this->validation()->rule(); } /** * Sets whether the node can be overwritten. * * @param bool $deny Whether the overwriting is forbidden or not * * @return $this */ public function cannotBeOverwritten($deny = true) { $this->merge()->denyOverwrite($deny); return $this; } /** * Gets the builder for validation rules. * * @return ValidationBuilder */ protected function validation() { if (null === $this->validation) { $this->validation = new ValidationBuilder($this); } return $this->validation; } /** * Gets the builder for merging rules. * * @return MergeBuilder */ protected function merge() { if (null === $this->merge) { $this->merge = new MergeBuilder($this); } return $this->merge; } /** * Gets the builder for normalization rules. * * @return NormalizationBuilder */ protected function normalization() { if (null === $this->normalization) { $this->normalization = new NormalizationBuilder($this); } return $this->normalization; } /** * Instantiate and configure the node according to this definition. * * @return NodeInterface $node The node instance * * @throws InvalidDefinitionException When the definition is invalid */ abstract protected function createNode(); } __halt_compiler();----SIGNATURE:----I6XP46q9Mdw+cqMg+MMMTAkwAQD+pPy6f2pO3YGYUl86I79enYyCU9wFsQh5EJXFpw39QG3m4GoivlEwkxJueeM2vtbC7ldRKES767UNad/GJQ7baYGWFtYQDMrmi9L6ePKqp4qWVh85HnbwXpkAmEr4hVvdMjp3d//YmzK8ZYdHy4ZWBKSAHzyW6S/23aLU6gOy8OH4se9xp50or1qtFYvhYCz9rGScDsHFq4y51qebFATlQxRFVimsEOK4US6CSsVWZDNHya0TD8yx+ViwOO6LVm1aaHfYrLXp4Enwzj9HqTBb/Xz+Z4PbFYqmdRaayfCG/KbDd/arlKtgIcC8EjM8CYXCjsvj+BQswRkc5f6UwQBuXUcicmYF0J/Ecp5PmioIBMvkULYRsjFRTIduq4Cazw9/AlYUBEPD7sec6Qe/sK45e/+SK3XCia8Sr4RaZsqDDJbuWJi9xJaKP201qgAOtkG4gp56MpNkE4iP4CAUAzmVap8FS3MKHp2j5KqhwKhcw2XGF6iaUuZ191wNsxP3YiK8CJ782GAwl7ZfLk639GCA08SCQAf0AnLKgKKyT/i2iGsAgud67mm3TdCV3MaxyeHT5YfDnX2MuCB5mpmsKqIzZSp1uADoTRssjjU1gyl1bD0d1SUdhSW/iiRzzh23G7gOFVoAD9hAvT/TLV0=----ATTACHMENT:----NjgyNjc0MzQ1MDY0NDcxOCA4NzUxNTk4ODA1NzQ4MjQ4IDEzNzc5NTI3MTQwMTE2OTc=