PHPackages                             sweetcode/cake - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. sweetcode/cake

AbandonedArchivedLibrary[Validation &amp; Sanitization](/categories/validation)

sweetcode/cake
==============

PHP Data Validator

1.0.0-beta(10y ago)17PHPPHP &gt;=5.3.0

Since Jul 22Pushed 10y ago1 watchersCompare

[ Source](https://github.com/sweetcode/cake)[ Packagist](https://packagist.org/packages/sweetcode/cake)[ Docs](https://github.com/sweetcode/Cake)[ RSS](/packages/sweetcode-cake/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Cake - the simple way to validate values
========================================

[](#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

```
composer require sweetcode/cake

```

Bugs
====

[](#bugs)

1. When you use aliases with the match rule it's doesn't work in the right way. #00001

How can I use Cake?
===================

[](#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

```
$cake = new Cake;

```

2 - You need a array to validate. The array should follow the following pattern:

```
   key: (|)
   value: array(
            key:
            value: (||(arguments)...)
        )

```

```
$fields = [
    'username'  => ['Yonas' => 'required|minlength(3)|maxlength(12)|alphanumeric'],
    'password'  => ['test' => 'required|match(repeatPassword)|minlength(4)'],
    'passwordRepeat' => ['testit' => 'required'],
    'email'     => ['test@test.com' => 'required|email']
];

```

3 - Now we validate the given fields.

```
$errorHandler = $cake->validate($fields);

```

4 - The Cake#validate() method returns a CakeErrorHandler instance. You can use this instance to echo out the errors.

```
if($errorHandler->valid()) {
    echo "No errors found.";
} else {
    var_dump($errorHandler->getErrors());
}

```

---

How can I add my own rules?
===========================

[](#how-can-i-add-my-own-rules)

1. Method Name: `rule__` | Replace the `` with your rule name
2. Method Arguments: `rule__($field, $value, $arguments)` | Your rule method needs three arguments.

```
$field       => the field name
$value       => the given value from the field
$arguments   => the given arguments that are passed into the method

```

2.1) The names of the arguments doesn't matter 3. The rule method must be "public" 4. Done! - Now you can use your rule to validate fields.

---

---

List of all rules
=================

[](#list-of-all-rules)

NameArgumentsExampleDescriptionalphanumeric`none`\['username' =&gt; \['Yonas', 'alphanumeric'\]Check for alphanumeric character(s).collection`list of values` (string)\['service' =&gt; \['Google', 'collection(Google, Facebook, Twitter)'\]\]Checks if a value exists in the given collection.date`date format` (string)\['birthdate' =&gt; \['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.email`none`\['emailadress' =&gt; \['', 'email'\]\]Checks if the value is a valid email address.hexcolor`none`\['favouriteColor' =&gt; \['#FFFFFF', 'date(d-m-Y)'\]\]Checks if the value is a valid hex color.match`list of fields` (string)\['password' =&gt; \['test', 'match(repeatPassword)'\], 'repeatPassword' =&gt; \['test', ''\]\]Checks if the value matches to the other given fields.ip`none`\['yourServer' =&gt; \['127.0.0.1', 'ip'\]\]Checks if the value is a valid ip address.maxlength`maximum length` (integer)\['username' =&gt; \['Yonas', 'maxlength(12)'\]\]Checks the maximum length of the value.minlength`minimum length` (integer)\['username' =&gt; \['Yonas', 'minlength(4)'\]\]Checks the minimum length of the valuerequired`none`\['username' =&gt; \['Yonas', 'required'\]\]Checks if a value is given.url`none`\['homepage' =&gt; \['', 'url'\]\]Checks if the value is a valid url.nocaptcha`secret` (string), `sendIp` (boolean)\['captcha' =&gt; \[$\_POST\['g-recaptcha-response'\], 'nocaptcha(mysecrettoke, false)'\]\]Checks if the captcha is answered in the right way

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3953d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e403125d485594f067db372a59b604b192de02fe14d42ad77d405324e83da33e?d=identicon)[sweetcode](/maintainers/sweetcode)

---

Top Contributors

[![jan-krueger](https://avatars.githubusercontent.com/u/3315137?v=4)](https://github.com/jan-krueger "jan-krueger (17 commits)")

---

Tags

validatordata

### Embed Badge

![Health badge](/badges/sweetcode-cake/health.svg)

```
[![Health](https://phpackages.com/badges/sweetcode-cake/health.svg)](https://phpackages.com/packages/sweetcode-cake)
```

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[seld/jsonlint

JSON Linter

1.3k217.8M205](/packages/seld-jsonlint)[composer/spdx-licenses

SPDX licenses list and validation library.

1.4k184.2M25](/packages/composer-spdx-licenses)[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[laminas/laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria

15644.9M188](/packages/laminas-laminas-validator)[form-manager/form-manager

PHP-HTML form manager

16041.0k7](/packages/form-manager-form-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
