NormalizationBuilder.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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;
  20. public $remappings;
  21. /**
  22. * Constructor
  23. *
  24. * @param NodeDefinition $node The related node
  25. */
  26. public function __construct(NodeDefinition $node)
  27. {
  28. $this->node = $node;
  29. $this->keys = false;
  30. $this->remappings = array();
  31. $this->before = array();
  32. }
  33. /**
  34. * Registers a key to remap to its plural form.
  35. *
  36. * @param string $key The key to remap
  37. * @param string $plural The plural of the key in case of irregular plural
  38. *
  39. * @return NormalizationBuilder
  40. */
  41. public function remap($key, $plural = null)
  42. {
  43. $this->remappings[] = array($key, null === $plural ? $key.'s' : $plural);
  44. return $this;
  45. }
  46. /**
  47. * Registers a closure to run before the normalization or an expression builder to build it if null is provided.
  48. *
  49. * @param \Closure $closure
  50. *
  51. * @return ExprBuilder|NormalizationBuilder
  52. */
  53. public function before(\Closure $closure = null)
  54. {
  55. if (null !== $closure) {
  56. $this->before[] = $closure;
  57. return $this;
  58. }
  59. return $this->before[] = new ExprBuilder($this->node);
  60. }
  61. }