浏览代码

added V result types: minOccurs, maxOccurs

Piotr Labudda 8 年之前
父节点
当前提交
65e1ab9aa2
共有 1 个文件被更改,包括 18 次插入16 次删除
  1. 18 16
      SE/se-lib/V.php

+ 18 - 16
SE/se-lib/V.php

@@ -72,7 +72,7 @@ class V {
 					$ret = $from;
 					settype($ret, $type);
 				}
-				break;
+				return $ret;
 			case 'word':
 				if (is_scalar($from)) {
 					$ret = $from;
@@ -82,7 +82,7 @@ class V {
 						$ret = substr($ret, 0, $pos);
 					}
 				}
-				break;
+				return $ret;
 			case 'login':// [a-zA-Z.-_]
 				if (is_scalar($from)) {
 					$ret = $from;
@@ -92,7 +92,7 @@ class V {
 						$ret = null;
 					}
 				}
-				break;
+				return $ret;
 			case 'url':// [a-zA-Z0-9_-]
 				if (is_scalar($from)) {
 					$ret = $from;
@@ -103,35 +103,35 @@ class V {
 					$ret = str_replace($pl_letters, $en_letters, $ret);
 					$ret = preg_replace('/[^a-zA-Z0-9_-]+/', '_', $ret);
 				}
-				break;
+				return $ret;
 			case 'int':
 			case 'integer':
 				if (is_scalar($from)) {
 					$ret = $from;
 					settype($ret, $type);
 				}
-				break;
+				return $ret;
 			case 'float':
 			case 'double':
 				if (is_scalar($from)) {
 					$ret = str_replace(',', '.', $from);
 					settype($ret, $type);
 				}
-				break;
+				return $ret;
 			case 'price':// 0.00 - decimal(n, 2)
 				if (is_scalar($from)) {
 					$ret = str_replace(',', '.', $from);
 					settype($ret, 'float');
 					$ret = round($ret, 2);
 				}
-				break;
+				return $ret;
 			case 'object':
 			case 'array':
 				if (is_scalar($from) || is_array($from) || is_object($from)) {
 					$ret = $from;
 					settype($ret, $type);
 				}
-				break;
+				return $ret;
 			case 'int_array':
 				if (is_scalar($from) || is_array($from) || is_object($from)) {
 					$ret = array();
@@ -142,7 +142,7 @@ class V {
 						$ret[] = $v;
 					}
 				}
-				break;
+				return $ret;
 			case 'uint_array':// unsigned int array
 				if (is_scalar($from) || is_array($from) || is_object($from)) {
 					$ret = array();
@@ -154,7 +154,7 @@ class V {
 						$ret[] = $v;
 					}
 				}
-				break;
+				return $ret;
 			case 'float_array':// uncigned int array
 				if (is_scalar($from) || is_array($from) || is_object($from)) {
 					$ret = array();
@@ -165,17 +165,19 @@ class V {
 						$ret[] = $v;
 					}
 				}
-				break;
+				return $ret;
 			case 'bool':
 			case 'boolean': return (bool)$from;
+			case 'minOccurs':
+			case 'maxOccurs': // The default values for minOccurs and maxOccurs are 1 - @return int or 'unbounded', default is 1
+				if (!is_scalar($from)) return null;
+				if (!strlen($from)) return 1;
+				if ("unbounded" === $from) return "unbounded";
+				return (int)$from;
 			default:
 				$fun = 'func_type_convert_'.$type;
-				if (function_exists($fun)) {
-					$ret = $fun($from);
-				}
-				break;
+				return (function_exists($fun)) ? $fun($from) : null;
 		}
-		return $ret;
 	}
 
 	/**