Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
izica committed Apr 8, 2019
1 parent 4225ebc commit a92fa58
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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
)
)
```

17 changes: 16 additions & 1 deletion Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a92fa58

Please sign in to comment.