ValidationBuilder.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Config\Definition\Builder;
  11. /**
  12. * This class builds validation conditions.
  13. *
  14. * @author Christophe Coevoet <stof@notk.org>
  15. */
  16. class ValidationBuilder
  17. {
  18. protected $node;
  19. public $rules;
  20. /**
  21. * Constructor
  22. *
  23. * @param NodeDefinition $node The related node
  24. */
  25. public function __construct(NodeDefinition $node)
  26. {
  27. $this->node = $node;
  28. $this->rules = array();
  29. }
  30. /**
  31. * Registers a closure to run as normalization or an expression builder to build it if null is provided.
  32. *
  33. * @param \Closure $closure
  34. *
  35. * @return ExprBuilder|ValidationBuilder
  36. */
  37. public function rule(\Closure $closure = null)
  38. {
  39. if (null !== $closure) {
  40. $this->rules[] = $closure;
  41. return $this;
  42. }
  43. return $this->rules[] = new ExprBuilder($this->node);
  44. }
  45. }