1. sfFormSymfony.class.php
  2. /** * Extends the form component with symfony-specific functionality. * * @package symfony * @subpackage form * @author Kris Wallsmith * @version SVN: $Id: sfFormSymfony.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */
  3. class sfFormSymfony extends sfForm
  4. {
  5. static protected
  6. $dispatcher = null;
  7. /**
  8. * Constructor.
  9. *
  10. * Notifies the 'form.post_configure' event.
  11. *
  12. * @see sfForm
  13. */
  14. public function __construct($defaults = array(), $options = array(), $CSRFSecret = null)
  15. {
  16. parent::__construct($defaults, $options, $CSRFSecret);
  17. if (self::$dispatcher)
  18. {
  19. self::$dispatcher->notify(new sfEvent($this, 'form.post_configure'));
  20. }
  21. }
  22. /**
  23. * Sets the event dispatcher to be used by all forms.
  24. *
  25. * @param sfEventDispatcher $dispatcher
  26. */
  27. static public function setEventDispatcher(sfEventDispatcher $dispatcher = null)
  28. {
  29. self::$dispatcher = $dispatcher;
  30. }
  31. /**
  32. * Returns the event dispatcher.
  33. *
  34. * @return sfEventDispatcher
  35. */
  36. static public function getEventDispatcher()
  37. {
  38. return self::$dispatcher;
  39. }
  40. /**
  41. * Notifies the 'form.filter_values' and 'form.validation_error' events.
  42. *
  43. * @see sfForm
  44. */
  45. protected function doBind(array $values)
  46. {
  47. if (self::$dispatcher)
  48. {
  49. $values = self::$dispatcher->filter(new sfEvent($this, 'form.filter_values'), $values)->getReturnValue();
  50. }
  51. try
  52. {
  53. parent::doBind($values);
  54. }
  55. catch (sfValidatorError $error)
  56. {
  57. if (self::$dispatcher)
  58. {
  59. self::$dispatcher->notify(new sfEvent($this, 'form.validation_error', array('error' => $error)));
  60. }
  61. throw $error;
  62. }
  63. }
  64. /**
  65. * Calls methods defined via sfEventDispatcher.
  66. *
  67. * @param string $method The method name
  68. * @param array $arguments The method arguments
  69. *
  70. * @return mixed The returned value of the called method
  71. */
  72. public function __call($method, $arguments)
  73. {
  74. if (self::$dispatcher)
  75. {
  76. $event = self::$dispatcher->notifyUntil(new sfEvent($this, 'form.method_not_found', array('method' => $method, 'arguments' => $arguments)));
  77. if ($event->isProcessed())
  78. {
  79. return $event->getReturnValue();
  80. }
  81. }
  82. throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
  83. }
  84. }

Debug toolbar