[icinga-checkins] icinga.org: icingaweb2/feature/add-to-dashboard-4537: Introduce Form:: setOnSuccess() in favor of overriding the constructor

git at icinga.org git at icinga.org
Tue Nov 18 09:50:29 CET 2014


Module: icingaweb2
Branch: feature/add-to-dashboard-4537
Commit: 899e6dfb5ac10444d996d75f4896e798c7dbb169
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=899e6dfb5ac10444d996d75f4896e798c7dbb169

Author: Eric Lippmann <eric.lippmann at netways.de>
Date:   Tue Nov  4 16:15:06 2014 +0100

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 631b2eb..f3dcd9e 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;
     }
 
     /**



More information about the icinga-checkins mailing list