| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfFormSymfony extends sfForm |
|---|
| 20 |
{ |
|---|
| 21 |
static protected |
|---|
| 22 |
$dispatcher = null; |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
* Constructor. |
|---|
| 26 |
* |
|---|
| 27 |
* Notifies the 'form.post_configure' event. |
|---|
| 28 |
* |
|---|
| 29 |
* @see sfForm |
|---|
| 30 |
*/ |
|---|
| 31 |
public function __construct($defaults = array(), $options = array(), $CSRFSecret = null) |
|---|
| 32 |
{ |
|---|
| 33 |
parent::__construct($defaults, $options, $CSRFSecret); |
|---|
| 34 |
|
|---|
| 35 |
if (self::$dispatcher) |
|---|
| 36 |
{ |
|---|
| 37 |
self::$dispatcher->notify(new sfEvent($this, 'form.post_configure')); |
|---|
| 38 |
} |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
* Sets the event dispatcher to be used by all forms. |
|---|
| 43 |
* |
|---|
| 44 |
* @param sfEventDispatcher $dispatcher |
|---|
| 45 |
*/ |
|---|
| 46 |
static public function setEventDispatcher(sfEventDispatcher $dispatcher = null) |
|---|
| 47 |
{ |
|---|
| 48 |
self::$dispatcher = $dispatcher; |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
* Returns the event dispatcher. |
|---|
| 53 |
* |
|---|
| 54 |
* @return sfEventDispatcher |
|---|
| 55 |
*/ |
|---|
| 56 |
static public function getEventDispatcher() |
|---|
| 57 |
{ |
|---|
| 58 |
return self::$dispatcher; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
* Notifies the 'form.filter_values' and 'form.validation_error' events. |
|---|
| 63 |
* |
|---|
| 64 |
* @see sfForm |
|---|
| 65 |
*/ |
|---|
| 66 |
protected function doBind(array $values) |
|---|
| 67 |
{ |
|---|
| 68 |
if (self::$dispatcher) |
|---|
| 69 |
{ |
|---|
| 70 |
$values = self::$dispatcher->filter(new sfEvent($this, 'form.filter_values'), $values)->getReturnValue(); |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
try |
|---|
| 74 |
{ |
|---|
| 75 |
parent::doBind($values); |
|---|
| 76 |
} |
|---|
| 77 |
catch (sfValidatorError $error) |
|---|
| 78 |
{ |
|---|
| 79 |
if (self::$dispatcher) |
|---|
| 80 |
{ |
|---|
| 81 |
self::$dispatcher->notify(new sfEvent($this, 'form.validation_error', array('error' => $error))); |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
throw $error; |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
* Calls methods defined via sfEventDispatcher. |
|---|
| 90 |
* |
|---|
| 91 |
* @param string $method The method name |
|---|
| 92 |
* @param array $arguments The method arguments |
|---|
| 93 |
* |
|---|
| 94 |
* @return mixed The returned value of the called method |
|---|
| 95 |
*/ |
|---|
| 96 |
public function __call($method, $arguments) |
|---|
| 97 |
{ |
|---|
| 98 |
if (self::$dispatcher) |
|---|
| 99 |
{ |
|---|
| 100 |
$event = self::$dispatcher->notifyUntil(new sfEvent($this, 'form.method_not_found', array('method' => $method, 'arguments' => $arguments))); |
|---|
| 101 |
if ($event->isProcessed()) |
|---|
| 102 |
{ |
|---|
| 103 |
return $event->getReturnValue(); |
|---|
| 104 |
} |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method)); |
|---|
| 108 |
} |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|