diff --git a/README.md b/README.md index 265966d..be133a5 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ Izica\Validation ### Notice [https://docs.phalconphp.com/3.4/en/api/phalcon_validation_validator_numericality] -$arOptions which passed in static functions, for example static numeric($arOptions), -used as params for new Numericality($arOptions); +`$arOptions` which passed in static functions, for example `static numeric($arOptions)`, +used as params for `new Numericality($arOptions)`; You can use it like this ``` @@ -67,25 +67,28 @@ Array ( [0] => Array ( - [type] => Email - [message] => email is not valid [field] => email + [type] => email + [message] => email is not valid ) [1] => Array ( - [type] => PresenceOf - [message] => num is required [field] => num + [type] => required + [message] => num is required ) [2] => Array ( - [type] => Numericality - [message] => num is not numeric [field] => num + [type] => numeric + [message] => num is not numeric ) + ) + + ``` diff --git a/Validation.php b/Validation.php index 0d22c38..37635ec 100644 --- a/Validation.php +++ b/Validation.php @@ -31,6 +31,20 @@ class Validation { 'regex' => Regex::class, ]; + public static $arTypes = [ + 'PresenceOf' => 'required', + 'Numericality' => 'numeric', + 'Email' => 'email', + 'UniquenessValidator' => 'unique', + 'Callback' => 'callback', + 'StringLength' => 'length', + 'Between' => 'between', + 'File' => 'file', + 'Url' => 'url', + 'Date' => 'date', + 'Regex' => 'regex', + ]; + function __construct($arOptions) { $this->arOptions = $arOptions; } @@ -58,10 +72,11 @@ public function validate($arData) { foreach ($obMessages as $obMessage) { $arMessages[] = [ 'field' => $obMessage->getField(), - 'type' => $obMessage->getType(), + 'type' => self::$arTypes[$obMessage->getType()], 'message' => $obMessage->getMessage(), ]; } + return $arMessages; } public static function required(