Renamed Registry -> GenericRegistry to make it clear that this registry does
[core.git] / framework / main / classes / helper / html / forms / class_HtmlFormHelper.php
index 4e6fbc47eda7f2406279028dc0d263f85b4cb52b..7927b353a084340ca40f8a494c30f00e64c0c7a6 100644 (file)
@@ -1,14 +1,17 @@
 <?php
 // Own namespace
-namespace CoreFramework\Helper;
+namespace Org\Mxchange\CoreFramework\Helper;
 
 // Import framework stuff
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Generic\EmptyVariableException;
-use CoreFramework\Generic\NullPointerException;
-use CoreFramework\Registry\Registry;
-use CoreFramework\Template\CompileableTemplate;
-use CoreFramework\Wrapper\Database\User\UserDatabaseWrapper;
+use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseWrapper;
+use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\NullPointerException;
+use Org\Mxchange\CoreFramework\Helper\Template\HelpableTemplate;
+use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
+
+// Import SPL stuff
+use \InvalidArgumentException;
 
 /**
  * A helper for constructing web forms
@@ -34,10 +37,10 @@ use CoreFramework\Wrapper\Database\User\UserDatabaseWrapper;
  */
 class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
        /**
-        * Whether the form tag is opened (keep at FALSE or else your forms will
+        * Whether the form tag is opened (keep at false or else your forms will
         * never work!)
         */
-       private $formOpened = FALSE;
+       private $formOpened = false;
 
        /**
         * Name of the form
@@ -45,9 +48,9 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
        private $formName = '';
 
        /**
-        * Whether form tag is enabled (default: TRUE)
+        * Whether form tag is enabled (default: true)
         */
-       private $formEnabled = TRUE;
+       private $formEnabled = true;
 
        // Class Constants
        const EXCEPTION_FORM_NAME_INVALID       = 0x120;
@@ -74,7 +77,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         * @param       $withForm                       Whether include the form tag
         * @return      $helperInstance         A preparedf instance of this helper
         */
-       public static final function createHtmlFormHelper (CompileableTemplate $templateInstance, $formName, $formId = FALSE, $withForm = TRUE) {
+       public static final function createHtmlFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false, $withForm = true) {
                // Get new instance
                $helperInstance = new HtmlFormHelper();
 
@@ -82,7 +85,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
                $helperInstance->setTemplateInstance($templateInstance);
 
                // Is the form id not set?
-               if ($formId === FALSE) {
+               if ($formId === false) {
                        // Use form id from form name
                        $formId = $formName;
                } // END - if
@@ -90,13 +93,13 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
                // Set form name
                $helperInstance->setFormName($formName);
 
-               // A form-less field may say 'FALSE' here...
-               if ($withForm === TRUE) {
+               // A form-less field may say 'false' here...
+               if ($withForm === true) {
                        // Create the form
                        $helperInstance->addFormTag($formName, $formId);
                } else {
                        // Disable form
-                       $helperInstance->enableForm(FALSE);
+                       $helperInstance->enableForm(false);
                }
 
                // Return the prepared instance
@@ -106,15 +109,15 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
        /**
         * Add the form tag or close it an already opened form tag
         *
-        * @param       $formName       Name of the form (default: FALSE)
-        * @param       $formId         Id of the form (attribute 'id'; default: FALSE)
+        * @param       $formName       Name of the form (default: false)
+        * @param       $formId         Id of the form (attribute 'id'; default: false)
         * @return      void
-        * @throws      InvalidFormNameException        If the form name is invalid ( = FALSE)
+        * @throws      InvalidFormNameException        If the form name is invalid ( = false)
         * @todo        Add some unique PIN here to bypass problems with some browser and/or extensions
         */
-       public function addFormTag ($formName = FALSE, $formId = FALSE) {
+       public function addFormTag ($formName = false, $formId = false) {
                // When the form is not yet opened at least form name must be valid
-               if (($this->formOpened === FALSE) && ($formName === FALSE)) {
+               if (($this->formOpened === false) && ($formName === false)) {
                        // Thrown an exception
                        throw new InvalidFormNameException ($this, self::EXCEPTION_FORM_NAME_INVALID);
                } // END - if
@@ -123,7 +126,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
                $formContent = '</form>';
 
                // Check whether we shall open or close the form
-               if (($this->formOpened === FALSE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Add HTML code
                        $formContent = sprintf("<form name=\"%s\" class=\"forms\" action=\"%s/%s\" method=\"%s\" target=\"%s\"",
                                $formName,
@@ -142,7 +145,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
                        $formContent .= '>';
 
                        // Open the form and remeber the form name
-                       $this->formOpened = TRUE;
+                       $this->formOpened = true;
 
                        // Add it to the content
                        $this->addHeaderContent($formContent);
@@ -157,7 +160,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
                        } // END - if
 
                        // Simply close it
-                       $this->formOpened = FALSE;
+                       $this->formOpened = false;
 
                        // Add it to the content
                        $this->addFooterContent($formContent);
@@ -175,7 +178,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         */
        public function addInputTextField ($fieldName, $fieldValue = '') {
                // Is the form opened?
-               if (($this->formOpened === FALSE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw an exception
                        throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
                } // END - if
@@ -217,7 +220,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         */
        public function addInputPasswordField ($fieldName, $fieldValue = '') {
                // Is the form opened?
-               if (($this->formOpened === FALSE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw an exception
                        throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
                } // END - if
@@ -244,7 +247,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         */
        public function addInputHiddenField ($fieldName, $fieldValue = '') {
                // Is the form opened?
-               if (($this->formOpened === FALSE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw an exception
                        throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
                } // END - if
@@ -299,16 +302,16 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         * @return      void
         * @throws      FormClosedException             If the form is not yet opened
         */
-       public function addInputCheckboxField ($fieldName, $fieldChecked = TRUE) {
+       public function addInputCheckboxField ($fieldName, $fieldChecked = true) {
                // Is the form opened?
-               if (($this->formOpened === FALSE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw an exception
                        throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
                } // END - if
 
                // Set whether the check box is checked...
                $checked = " checked=\"checked\"";
-               if ($fieldChecked === FALSE) $checked = ' ';
+               if ($fieldChecked === false) $checked = ' ';
 
                // Generate the content
                $inputContent = sprintf("<input type=\"checkbox\" name=\"%s\" class=\"checkbox %s_field\" value=\"1\"%s/>",
@@ -331,7 +334,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         */
        public function addInputResetButton ($buttonText) {
                // Is the form opened?
-               if (($this->formOpened === FALSE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw an exception
                        throw new FormClosedException (array($this, 'reset'), self::EXCEPTION_CLOSED_FORM);
                } // END - if
@@ -356,7 +359,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         */
        public function addInputSubmitButton ($buttonText) {
                // Is the form opened?
-               if (($this->formOpened === FALSE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw an exception
                        throw new FormClosedException (array($this, 'submit'), self::EXCEPTION_CLOSED_FORM);
                } // END - if
@@ -379,35 +382,32 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         * @param       $groupText      Text including HTML to show above this group
         * @return      void
         * @throws      FormClosedException             If no form has been opened before
-        * @throws      EmptyVariableException  If $groupId is not set
+        * @throws      InvalidArgumentException        If $groupId is not set
         */
        public function addFormGroup ($groupId = '', $groupText = '') {
                // Is a form opened?
-               if (($this->formOpened === FALSE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw exception here
                        throw new FormClosedException(array($this, $groupId), self::EXCEPTION_CLOSED_FORM);
-               } // END - if
-
-               // At least the group name should be set
-               if ((empty($groupId)) && ($this->ifGroupOpenedPreviously() === FALSE)) {
+               } elseif ((empty($groupId)) && ($this->ifGroupOpenedPreviously() === false)) {
                        // Throw exception here
-                       throw new EmptyVariableException(array($this, 'groupId'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+                       throw new InvalidArgumentException('Parameter "groupId" is empty but group is not closed');
                } elseif (empty($groupId)) {
                        // Close the last opened
                        $groupId = $this->getPreviousGroupId();
                }
 
                // Same group to open?
-               if (($this->ifGroupOpenedPreviously() === FALSE) && ($groupId === $this->getPreviousGroupId())) {
+               if (($this->ifGroupOpenedPreviously() === false) && ($groupId === $this->getPreviousGroupId())) {
                        // Abort here silently
-                       return FALSE;
+                       return false;
                } // END - if
 
                // Initialize content with closing div by default
                $content = "    </div>\n</div><!-- Group - CLOSE //-->";
 
                // Is this group opened?
-               if ($this->ifGroupOpenedPreviously() === FALSE) {
+               if ($this->ifGroupOpenedPreviously() === false) {
                        // Begin the div/span blocks
                        $content = sprintf("<!-- Group %s - OPEN //-->
 <div class=\"group_box\" id=\"%s_group_box\">
@@ -454,35 +454,32 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         * @param       $subGroupText   Text including HTML to show above this group
         * @return      void
         * @throws      FormFormClosedException         If no group has been opened before
-        * @throws      EmptyVariableException          If $subGroupId is not set
+        * @throws      InvalidArgumentException                If $subGroupId is not set
         */
        public function addFormSubGroup ($subGroupId = '', $subGroupText = '') {
                // Is a group opened?
-               if ($this->ifGroupOpenedPreviously() === FALSE) {
+               if ($this->ifGroupOpenedPreviously() === false) {
                        // Throw exception here
                        throw new FormFormClosedException(array($this, $subGroupId), self::EXCEPTION_UNEXPECTED_CLOSED_GROUP);
-               } // END - if
-
-               // At least the sub group name should be set
-               if ((empty($subGroupId)) && ($this->ifSubGroupOpenedPreviously() === FALSE)) {
+               } elseif ((empty($subGroupId)) && ($this->ifSubGroupOpenedPreviously() === false)) {
                        // Throw exception here
-                       throw new EmptyVariableException(array($this, 'subGroupId'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+                       throw new InvalidArgumentException('Parameter "subGroupId" is empty but sub-group is not closed');
                } elseif (empty($subGroupId)) {
                        // Close the last opened
                        $subGroupId = $this->getPreviousSubGroupId();
                }
 
                // Same sub group to open?
-               if (($this->ifSubGroupOpenedPreviously() === FALSE) && ($subGroupId == $this->getPreviousSubGroupId())) {
+               if (($this->ifSubGroupOpenedPreviously() === false) && ($subGroupId == $this->getPreviousSubGroupId())) {
                        // Abort here silently
-                       return FALSE;
+                       return false;
                } // END - if
 
                // Initialize content with closing div by default
                $content = "    </div>\n</div><!-- Sub group- CLOSE //-->";
 
                // Is this group opened?
-               if ($this->ifSubGroupOpenedPreviously() === FALSE) {
+               if ($this->ifSubGroupOpenedPreviously() === false) {
                        // Begin the span block
                        $content = sprintf("<!-- Sub group %s - OPEN //-->
 <div class=\"subgroup_box\" id=\"%s_subgroup_box\">
@@ -524,7 +521,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         */
        public function addFieldText ($fieldName, $fieldText) {
                // Is the form opened?
-               if (($this->formOpened === FALSE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw an exception
                        throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
                } // END - if
@@ -558,7 +555,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         */
        public function addFormNote ($noteId, $formNotes) {
                // Is the form opened?
-               if (($this->formOpened === FALSE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw an exception
                        throw new FormClosedException (array($this, 'form_notes'), self::EXCEPTION_CLOSED_FORM);
                } // END - if
@@ -586,13 +583,13 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         */
        public function addInputSelectField ($selectId, $firstEntry) {
                // Is the form group opened?
-               if (($this->formOpened === FALSE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === false) && ($this->formEnabled === true)) {
                        // Throw an exception
                        throw new FormClosedException (array($this, 'form_notes'), self::EXCEPTION_CLOSED_FORM);
                } // END - if
 
                // Shall we close or open the sub group?
-               if (($this->ifSubGroupOpenedPreviously() === FALSE) && ($this->getPreviousSubGroupId() !== $selectId)) {
+               if (($this->ifSubGroupOpenedPreviously() === false) && ($this->getPreviousSubGroupId() !== $selectId)) {
                        // Initialize first entry (which might be non-selectable if content is provided
                        if (!empty($firstEntry)) {
                                // Add selection around it
@@ -633,7 +630,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         */
        public function addSelectSubOption ($subName, $subValue) {
                // Is there a sub group (shall be a selection box!)
-               if ($this->ifSubGroupOpenedPreviously() === FALSE) {
+               if ($this->ifSubGroupOpenedPreviously() === false) {
                        // Then throw an exception here
                        throw new HelperNoPreviousOpenedSubGroupException(array($this, $content), self::EXCEPTION_NO_PREVIOUS_SUB_GROUP_OPENED);
                } // END - if
@@ -661,7 +658,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         */
        public function addSelectOption ($optionName, $optionValue) {
                // Is there a sub group (shall be a selection box!)
-               if ($this->ifSubGroupOpenedPreviously() === FALSE) {
+               if ($this->ifSubGroupOpenedPreviously() === false) {
                        // Then throw an exception here
                        throw new HelperNoPreviousOpenedSubGroupException(array($this, $content), self::EXCEPTION_NO_PREVIOUS_SUB_GROUP_OPENED);
                } // END - if
@@ -688,7 +685,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
 
                try {
                        // Get last executed pre filter
-                       $extraInstance = Registry::getRegistry()->getInstance('extra');
+                       $extraInstance = GenericRegistry::getRegistry()->getInstance('extra');
                } catch (NullPointerException $e) {
                        // Instance in registry is not set (NULL)
                        // @TODO We need to log this later
@@ -713,7 +710,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         * @param       $formEnabled    Whether form is enabled or disabled
         * @return      void
         */
-       public final function enableForm ($formEnabled = TRUE) {
+       public final function enableForm ($formEnabled = true) {
                $this->formEnabled = (bool) $formEnabled;
        }
 
@@ -863,7 +860,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         * @todo        Implement check if rules have been changed
         */
        public function ifRulesHaveChanged () {
-               return FALSE;
+               return false;
        }
 
        /**
@@ -926,10 +923,10 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
         */
        public function flushContent () {
                // Is the form still open?
-               if (($this->formOpened === TRUE) && ($this->formEnabled === TRUE)) {
+               if (($this->formOpened === true) && ($this->formEnabled === true)) {
                        // Close the form automatically
                        $this->addFormTag();
-               } elseif ($this->formEnabled === FALSE) {
+               } elseif ($this->formEnabled === false) {
                        if ($this->ifSubGroupOpenedPreviously()) {
                                // Close sub group
                                $this->addFormSubGroup();