Author: Tobias Schlitt
Date: 2007-04-07 12:08:13 +0200 (Sat, 07 Apr 2007)
New Revision: 4821

Log:
- Added conversion option to menu dialog validator.

Modified:
   trunk/ConsoleTools/src/dialog/validators/menu_dialog_default.php

Modified: trunk/ConsoleTools/src/dialog/validators/menu_dialog_default.php
===================================================================
--- trunk/ConsoleTools/src/dialog/validators/menu_dialog_default.php    
2007-04-07 10:04:44 UTC (rev 4820)
+++ trunk/ConsoleTools/src/dialog/validators/menu_dialog_default.php    
2007-04-07 10:08:13 UTC (rev 4821)
@@ -28,8 +28,9 @@
      * @var array
      */
     protected $properties = array(
-        "elements"  => array(),
-        "default"   => null,
+        "elements"      => array(),
+        "default"       => null,
+        "conversion"    => self::CONVERT_NONE,
     );
 
     /**
@@ -39,10 +40,11 @@
      * @param mixed $default  The default value.
      * @return void
      */
-    public function __construct( array $elements = array(), $default = null )
+    public function __construct( array $elements = array(), $default = null, 
$conversion = self::CONVERT_NONE )
     {
-        $this->elements = $elements;
-        $this->default  = $default;
+        $this->elements     = $elements;
+        $this->default      = $default;
+        $this->conversion   = $conversion;
     }
 
     /**
@@ -69,7 +71,21 @@
      */
     public function fixup( $result )
     {
-        return ( $result === "" && $this->default !== null ) ? $this->default 
: $result;
+        if ( $result === "" && $this->default !== null )
+        {
+            return $this->default;
+
+        }
+        switch ( $this->conversion )
+        {
+            case self::CONVERT_LOWER:
+                return strtolower( $result );
+            case self::CONVERT_UPPER:
+                return strtoupper( $result );
+            case self::CONVERT_NONE:
+            default:
+                return $result;
+        }
     }
 
     /**
@@ -141,6 +157,12 @@
                     throw new ezcBaseValueException( $propertyName, 
$propertyValue, "scalar" );
                 }
                 break;
+            case "conversion":
+                if ( $propertyValue !== self::CONVERT_NONE && $propertyValue 
!== self::CONVERT_UPPER && $propertyValue !== self::CONVERT_LOWER )
+                {
+                    throw new ezcBaseValueException( "conversion", 
$conversion, "ezcConsoleMenuDialogDefaultValidator::CONVERT_*" );
+                }
+                break;
             default:
                 throw new ezcBasePropertyNotFoundException( $propertyName );
         }

-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to