NormalizationBuilder.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 normalization conditions.
  13. *
  14. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  15. */
  16. class NormalizationBuilder
  17. {
  18. protected $node;
  19. public $before = array();
  20. public $remappings = array();
  21. public function __construct(NodeDefinition $node)
  22. {
  23. $this->node = $node;
  24. }
  25. /**
  26. * Registers a key to remap to its plural form.
  27. *
  28. * @param string $key The key to remap
  29. * @param string $plural The plural of the key in case of irregular plural
  30. *
  31. * @return $this
  32. */
  33. public function remap($key, $plural = null)
  34. {
  35. $this->remappings[] = array($key, null === $plural ? $key.'s' : $plural);
  36. return $this;
  37. }
  38. /**
  39. * Registers a closure to run before the normalization or an expression builder to build it if null is provided.
  40. *
  41. * @return ExprBuilder|$this
  42. */
  43. public function before(\Closure $closure = null)
  44. {
  45. if (null !== $closure) {
  46. $this->before[] = $closure;
  47. return $this;
  48. }
  49. return $this->before[] = new ExprBuilder($this->node);
  50. }
  51. }