From d2eddcbec6bff6ff640e5c76de302382ca689927 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 4 Nov 2014 16:15:06 +0100 Subject: [PATCH] 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. --- library/Icinga/Web/Form.php | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 82f4501a1..8eab0f6a5 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -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; } /**