PropelConditionalProxy.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. /**
  10. * Proxy for conditional statements in a fluid interface.
  11. * This class replaces another class for wrong statements,
  12. * and silently catches all calls to non-conditional method calls
  13. *
  14. * @example
  15. * <code>
  16. * $c->_if(true) // returns $c
  17. * ->doStuff() // executed
  18. * ->_else() // returns a PropelConditionalProxy instance
  19. * ->doOtherStuff() // not executed
  20. * ->_endif(); // returns $c
  21. * $c->_if(false) // returns a PropelConditionalProxy instance
  22. * ->doStuff() // not executed
  23. * ->_else() // returns $c
  24. * ->doOtherStuff() // executed
  25. * ->_endif(); // returns $c
  26. * @see Criteria
  27. *
  28. * @author Francois Zaninotto
  29. * @version $Revision: 1612 $
  30. * @package propel.runtime.util
  31. */
  32. class PropelConditionalProxy
  33. {
  34. protected $mainObject;
  35. public function __construct($mainObject)
  36. {
  37. $this->mainObject = $mainObject;
  38. }
  39. public function _if()
  40. {
  41. throw new PropelException('_if() statements cannot be nested');
  42. }
  43. public function _elseif($cond)
  44. {
  45. if($cond) {
  46. return $this->mainObject;
  47. } else {
  48. return $this;
  49. }
  50. }
  51. public function _else()
  52. {
  53. return $this->mainObject;
  54. }
  55. public function _endif()
  56. {
  57. return $this->mainObject;
  58. }
  59. public function __call($name, $arguments)
  60. {
  61. return $this;
  62. }
  63. }