ExprBuilder.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Symfony\Component\DependencyInjection\Configuration\Builder;
  3. class ExprBuilder
  4. {
  5. public $parent;
  6. public $ifPart;
  7. public $thenPart;
  8. public function __construct($parent)
  9. {
  10. $this->parent = $parent;
  11. }
  12. public function ifTrue(\Closure $closure)
  13. {
  14. $this->ifPart = $closure;
  15. return $this;
  16. }
  17. public function ifString()
  18. {
  19. $this->ifPart = function($v) { return is_string($v); };
  20. return $this;
  21. }
  22. public function ifNull()
  23. {
  24. $this->ifPart = function($v) { return null === $v; };
  25. return $this;
  26. }
  27. public function ifArray()
  28. {
  29. $this->ifPart = function($v) { return is_array($v); };
  30. return $this;
  31. }
  32. public function then(\Closure $closure)
  33. {
  34. $this->thenPart = $closure;
  35. return $this;
  36. }
  37. public function end()
  38. {
  39. if (null === $this->ifPart) {
  40. throw new \RuntimeException('You must specify an if part.');
  41. }
  42. if (null === $this->thenPart) {
  43. throw new \RuntimeException('You must specify a then part.');
  44. }
  45. return $this->parent;
  46. }
  47. }