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:
parent
0f48382f69
commit
d2eddcbec6
|
@ -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
|
* It is called using the following signature: (Request $request, Form $form).
|
||||||
* form's method. 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'])) {
|
if (! is_callable($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)) {
|
|
||||||
throw new LogicException('The option `onSuccess\' is not callable');
|
throw new LogicException('The option `onSuccess\' is not callable');
|
||||||
}
|
}
|
||||||
|
$this->onSuccess = $onSuccess;
|
||||||
parent::__construct($options);
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue