Browse Source

Update Exceptions

朱金辉 2 năm trước cách đây
mục cha
commit
2555848047

+ 0 - 1
_cli.php

@@ -312,4 +312,3 @@ class cmd
 
 array_shift($argv);
 new cmd($argv);
-?>

+ 23 - 3
src/Base/Rules.php

@@ -138,14 +138,34 @@ class Rules
         }
         if(!$method) throw new Exception(__METHOD__ . ' undefined.', 1);
     }
+
+    /**
+     * 批量添加验证规则
+     *
+     * @param array $rules [$field, $key, $valid, $message]
+     * @return void
+     */
+    public function batchRules(array $rules)
+    {
+        foreach ($rules as $rule)
+        {
+            list($field, $key, $valid, $message) = $rule;
+            $this->addRules($field, $key, $valid, $message);
+        }
+    }
     /**
      * 添加规则
+     * @param string $field 验证字段
+     * @param string $key 验证规则
+     * @param mixed $valid 验证参数,如 key=length valid=10
+     * @param string $message 验证失败返回的消息
+     * @return void
      */
-    public function addRules($field, $key, $isValid, $message)
+    public function addRules($field, $key, $valid, $message)
     {
-        if(!$field || !$key || $isValid === null || $isValid === '') return;
+        if(!$field || !$key || $valid === null || $valid === '') return;
         if(!$this->isAllow($key)) return;
-        $this->rules[$field][$key] = $isValid;
+        $this->rules[$field][$key] = $valid;
         $this->message[$field][$key] = $message;
     }
     /**

+ 3 - 0
src/Exceptions/AccessDenied.php

@@ -1,6 +1,9 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\AccessDenied', false)) {
+    return;
+}
 class AccessDenied extends Errors
 {
 	const VERSION = '1.2';

+ 3 - 0
src/Exceptions/Cache.php

@@ -1,6 +1,9 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\Cache', false)) {
+    return;
+}
 class Cache extends Errors
 {
 	const VERSION = '1.2';

+ 3 - 0
src/Exceptions/CallUndefinedClass.php

@@ -1,6 +1,9 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\CallUndefinedClass', false)) {
+    return;
+}
 class CallUndefinedClass extends Errors
 {
 	const VERSION = '1.2';

+ 3 - 0
src/Exceptions/ClassInstanceof.php

@@ -1,6 +1,9 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\ClassInstanceof', false)) {
+    return;
+}
 class ClassInstanceof extends Errors
 {
 	const VERSION = '1.2';

+ 4 - 0
src/Exceptions/ClassNotFound.php

@@ -1,6 +1,10 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\ClassNotFound', false)) {
+    return;
+}
+
 class ClassNotFound extends Errors
 {
 	const VERSION = '1.2';

+ 3 - 1
src/Exceptions/Error.php

@@ -1,7 +1,9 @@
 <?php
-
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\Error', false)) {
+    return;
+}
 /**
  *
  * Class Qii_Exceptions_Error

+ 3 - 0
src/Exceptions/Errors.php

@@ -2,6 +2,9 @@
 
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\Errors', false)) {
+    return;
+}
 class Errors extends \Exception
 {
     const VERSION = '1.2';

+ 3 - 0
src/Exceptions/FileNotFound.php

@@ -1,6 +1,9 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\FileNotFound', false)) {
+    return;
+}
 class FileNotFound extends Errors
 {
 	const VERSION = '1.2';

+ 3 - 0
src/Exceptions/FolderDoesNotExist.php

@@ -1,6 +1,9 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\FolderDoesNotExist', false)) {
+    return;
+}
 class FolderDoesNotExist extends Errors
 {
     const VERSION = '1.2';

+ 4 - 0
src/Exceptions/InvalidFormat.php

@@ -1,6 +1,10 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\InvalidFormat', false)) {
+    return;
+}
+
 class InvalidFormat extends Errors
 {
 	const VERSION = '1.2';

+ 3 - 0
src/Exceptions/InvalidParams.php

@@ -1,6 +1,9 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\InvalidParams', false)) {
+    return;
+}
 class InvalidParams extends Errors
 {
     const VERSION = '1.2';

+ 4 - 0
src/Exceptions/MethodNotFound.php

@@ -1,6 +1,10 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\InvalidParams', false)) {
+    return;
+}
+
 class MethodNotFound extends Errors
 {
 	const VERSION = '1.2';

+ 4 - 0
src/Exceptions/NotAllowed.php

@@ -1,6 +1,10 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\NotAllowed', false)) {
+    return;
+}
+
 class NotAllowed extends Errors
 {
 	const VERSION = '1.2';

+ 4 - 0
src/Exceptions/Overwrite.php

@@ -1,6 +1,10 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\Overwrite', false)) {
+    return;
+}
+
 class Overwrite extends Errors
 {
 	const VERSION = '1.2';

+ 4 - 0
src/Exceptions/Response.php

@@ -1,6 +1,10 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\Response', false)) {
+    return;
+}
+
 class Response extends Errors
 {
 	const VERSION = '1.2';

+ 4 - 0
src/Exceptions/TableException.php

@@ -1,6 +1,10 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\TableException', false)) {
+    return;
+}
+
 class TableException extends Errors
 {
 	const VERSION = '1.2';

+ 4 - 0
src/Exceptions/Unsupported.php

@@ -1,6 +1,10 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\Unsupported', false)) {
+    return;
+}
+
 class Unsupported extends Errors
 {
 	const VERSION = '1.2';

+ 4 - 0
src/Exceptions/Variable.php

@@ -1,6 +1,10 @@
 <?php
 namespace Qii\Exceptions;
 
+if (class_exists('\Qii\Exceptions\Variable', false)) {
+    return;
+}
+
 class Variable extends Errors
 {
 	const VERSION = '1.2';