Download the PHP package sweetcode/cake without Composer
On this page you can find all versions of the php package sweetcode/cake. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sweetcode/cake
More information about sweetcode/cake
Files in sweetcode/cake
Package cake
Short Description PHP Data Validator
License
Homepage https://github.com/sweetcode/Cake
Informations about the package cake
Cake - the simple way to validate values
Cake is the latest validation project. Cake is based on "Validatio" and at all Validatio is a nice script, but the main reason to change to Cake is that Cake is 10 times faster than Validation and this is a massive increase in performance.
Installation
Just use Composer
Bugs
- When you use aliases with the match rule it's doesn't work in the right way. #00001
How can I use Cake?
It's really simple to use.
1 - First of all create a new instance that you can use to validate your fields
2 - You need a array to validate. The array should follow the following pattern:
3 - Now we validate the given fields.
4 - The Cake#validate() method returns a CakeErrorHandler instance. You can use this instance to echo out the errors.
How can I add my own rules?
- Method Name:
rule__<your-rule-name>
| Replace the<your-rule-name>
with your rule name - Method Arguments:
rule__<your-rule-name>($field, $value, $arguments)
| Your rule method needs three arguments.
2.1) The names of the arguments doesn't matter
- The rule method must be "public"
- Done! - Now you can use your rule to validate fields.
List of all rules
Name | Arguments | Example | Description |
---|---|---|---|
alphanumeric | none |
['username' => ['Yonas', 'alphanumeric'] | Check for alphanumeric character(s). |
collection | list of values (string) |
['service' => ['Google', 'collection(Google, Facebook, Twitter)']] | Checks if a value exists in the given collection. |
date | date format (string) |
['birthdate' => ['1.1.1990', 'date(d-m-Y)']] | Checks if the value is a valid date - based on the given date format. The method accepts every format that the DateTime#createFromFormat method accepts too. |
none |
['emailadress' => ['[email protected]', 'email']] | Checks if the value is a valid email address. | |
hexcolor | none |
['favouriteColor' => ['#FFFFFF', 'date(d-m-Y)']] | Checks if the value is a valid hex color. |
match | list of fields (string) |
['password' => ['test', 'match(repeatPassword)'], 'repeatPassword' => ['test', '']] | Checks if the value matches to the other given fields. |
ip | none |
['yourServer' => ['127.0.0.1', 'ip']] | Checks if the value is a valid ip address. |
maxlength | maximum length (integer) |
['username' => ['Yonas', 'maxlength(12)']] | Checks the maximum length of the value. |
minlength | minimum length (integer) |
['username' => ['Yonas', 'minlength(4)']] | Checks the minimum length of the value |
required | none |
['username' => ['Yonas', 'required']] | Checks if a value is given. |
url | none |
['homepage' => ['http://example.com', 'url']] | Checks if the value is a valid url. |
nocaptcha | secret (string), sendIp (boolean) |
['captcha' => [$_POST['g-recaptcha-response'], 'nocaptcha(mysecrettoke, false)']] | Checks if the captcha is answered in the right way |