Introduce Form::setOnSuccess() in favor of overriding the constructor

Zend_Form uses setters for options if a respective setter method exists.
It is not necessary to override the constructor for introducing new options.
This commit is contained in:
Eric Lippmann 2014-11-04 16:15:06 +01:00
parent 0f48382f69
commit d2eddcbec6
1 changed files with 10 additions and 17 deletions

View File

@ -108,30 +108,23 @@ class Form extends Zend_Form
);
/**
* Create a new form
* Set a callback that is called instead of this form's onSuccess method
*
* Accepts an additional option `onSuccess' which is a callback that is called instead of this
* form's method. It is called using the following signature: (Request $request, Form $form).
* It is called using the following signature: (Request $request, Form $form).
*
* @see Zend_Form::__construct()
* @param callable $onSuccess Callback
*
* @throws LogicException In case `onSuccess' is not callable
* @return $this
*
* @throws LogicException If the callback is not callable
*/
public function __construct($options = null)
public function setOnSuccess($onSuccess)
{
if (is_array($options) && isset($options['onSuccess'])) {
$this->onSuccess = $options['onSuccess'];
unset($options['onSuccess']);
} elseif (isset($options->onSuccess)) {
$this->onSuccess = $options->onSuccess;
unset($options->onSuccess);
}
if ($this->onSuccess !== null && false === is_callable($this->onSuccess)) {
if (! is_callable($onSuccess)) {
throw new LogicException('The option `onSuccess\' is not callable');
}
parent::__construct($options);
$this->onSuccess = $onSuccess;
return $this;
}
/**