Create a Special:Redirect page.
[lhc/web/wiklou.git] / includes / FormOptions.php
index d1a5fd3..530b094 100644 (file)
@@ -1,16 +1,35 @@
 <?php
 /**
  * Helper class to keep track of options when mixing links and form elements.
- * @todo This badly need some examples and tests :-)
- *
- * Copyright © 2008, Niklas Laxstiröm
  *
+ * Copyright © 2008, Niklas Laxström
  * Copyright © 2011, Antoine Musso
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  * @author Niklas Laxström
- * @author Antoine Musso 
+ * @author Antoine Musso
  */
 
+/**
+ * Helper class to keep track of options when mixing links and form elements.
+ *
+ * @todo This badly need some examples and tests :-)
+ */
 class FormOptions implements ArrayAccess {
        /** @name Type constants
         * Used internally to map an option value to a WebRequest accessor
@@ -64,6 +83,7 @@ class FormOptions implements ArrayAccess {
         * which will be assumed as INT if the data is an integer.
         *
         * @param $data Mixed: value to guess type for
+        * @throws MWException
         * @exception MWException Unsupported datatype
         * @return int Type constant
         */
@@ -84,8 +104,9 @@ class FormOptions implements ArrayAccess {
        /**
         * Verify the given option name exist.
         *
-        * @param $name String: option name
+        * @param string $name option name
         * @param $strict Boolean: throw an exception when the option does not exist (default false)
+        * @throws MWException
         * @return Boolean: true if option exist, false otherwise
         */
        public function validateName( $name, $strict = false ) {
@@ -102,7 +123,7 @@ class FormOptions implements ArrayAccess {
        /**
         * Use to set the value of an option.
         *
-        * @param $name String: option name
+        * @param string $name option name
         * @param $value Mixed: value for the option
         * @param $force Boolean: whether to set the value when it is equivalent to the default value for this option (default false).
         * @return null
@@ -122,7 +143,7 @@ class FormOptions implements ArrayAccess {
         * Get the value for the given option name.
         * Internally use getValueReal()
         *
-        * @param $name String: option name
+        * @param string $name option name
         * @return Mixed
         */
        public function getValue( $name ) {
@@ -133,7 +154,7 @@ class FormOptions implements ArrayAccess {
 
        /**
         * @todo Document
-        * @param $option Array: array structure describing the option
+        * @param array $option array structure describing the option
         * @return Mixed. Value or the default value if it is null
         */
        protected function getValueReal( $option ) {
@@ -147,7 +168,7 @@ class FormOptions implements ArrayAccess {
        /**
         * Delete the option value.
         * This will make future calls to getValue()  return the default value.
-        * @param $name String: option name
+        * @param string $name option name
         * @return null
         */
        public function reset( $name ) {
@@ -157,8 +178,9 @@ class FormOptions implements ArrayAccess {
 
        /**
         * @todo Document
-        * @param $name String: option name
-        * @return null
+        * @param string $name Option name
+        * @throws MWException If option does not exist.
+        * @return mixed Value or the default value if it is null.
         */
        public function consumeValue( $name ) {
                $this->validateName( $name, true );
@@ -169,7 +191,7 @@ class FormOptions implements ArrayAccess {
 
        /**
         * @todo Document
-        * @param $names Array: array of option names
+        * @param array $names array of option names
         * @return null
         */
        public function consumeValues( /*Array*/ $names ) {
@@ -186,11 +208,12 @@ class FormOptions implements ArrayAccess {
 
        /**
         * Validate and set an option integer value
-        * The value will be altered to fit in the range. 
+        * The value will be altered to fit in the range.
         *
-        * @param $name String: option name
-        * @param $min Int: minimum value
-        * @param $max Int: maximum value
+        * @param string $name option name
+        * @param int $min minimum value
+        * @param int $max maximum value
+        * @throws MWException
         * @exception MWException Option is not of type int
         * @return null
         */
@@ -267,15 +290,19 @@ class FormOptions implements ArrayAccess {
                        $default = $this->options[$name]['default'];
                        $type = $this->options[$name]['type'];
 
-                       switch( $type ) {
+                       switch ( $type ) {
                                case self::BOOL:
-                                       $value = $r->getBool( $name, $default ); break;
+                                       $value = $r->getBool( $name, $default );
+                                       break;
                                case self::INT:
-                                       $value = $r->getInt( $name, $default ); break;
+                                       $value = $r->getInt( $name, $default );
+                                       break;
                                case self::STRING:
-                                       $value = $r->getText( $name, $default ); break;
+                                       $value = $r->getText( $name, $default );
+                                       break;
                                case self::INTNULL:
-                                       $value = $r->getIntOrNull( $name ); break;
+                                       $value = $r->getIntOrNull( $name );
+                                       break;
                                default:
                                        throw new MWException( 'Unsupported datatype' );
                        }