PHPackages                             davidecesarano/embryo-validation - 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. davidecesarano/embryo-validation

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

davidecesarano/embryo-validation
================================

PHP validation for PSR-7 request.

191.7k4PHP

Since Jan 28Pushed 6y ago4 watchersCompare

[ Source](https://github.com/davidecesarano/Embryo-Validation)[ Packagist](https://packagist.org/packages/davidecesarano/embryo-validation)[ RSS](/packages/davidecesarano-embryo-validation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Embryo Validation
=================

[](#embryo-validation)

PHP validation for PSR-7 request.

Features
--------

[](#features)

- PSR compatible.
- Used for `$request->getParsedBody` and `$request->getUploadedFiles`.
- Sanitize values.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.1
- A [PSR-7](https://www.php-fig.org/psr/psr-7/) http message implementation and [PSR-17](https://www.php-fig.org/psr/psr-17/) http factory implementation (ex. [Embryo-Http](https://github.com/davidecesarano/Embryo-Http))

Installation
------------

[](#installation)

Using Composer:

```
$ composer require davidecesarano/embryo-validation

```

Example
-------

[](#example)

You may quickly test this using the built-in PHP server going to .

```
$ cd example
$ php -S localhost:8000

```

Usage
-----

[](#usage)

### Writing simple validation logic

[](#writing-simple-validation-logic)

Let's assume we have `POST` request. With PSR we have the `$_POST` parameters in `$request->getParsedBody()` and the `$_FILES` files in `$request->getUploadedFiles()`. Use Embryo Validation for to validate parameters values.

```
$request = (new Embryo\Http\Factory\ServerRequestFactory)->createServerRequestFromServer();
$validation = new Embryo\Validation\Validation($request);

$validation->name('title')->type('text')->required();
$validation->name('body')->type('any')->required();
if ($validation->isSuccess()) {
    // ...
} else {
    print_r($validation->getErrors());
}
```

If the validation rules pass, your code will keep executing normally; however, if validation fails, you can display errors.

### Methods

[](#methods)

#### `name(string $name)`

[](#namestring-name)

Set field name. If name not exists in `$request->getParsedBody()` or in `$request->getUploadedFiles()` return null.

#### `type(string $type)`

[](#typestring-type)

Set field type. If value not match at type return an error. The types are:

- **text**. Value may be anything, it will be sanitized with `FILTER_SANITIZE_STRING`.
- **email**. Value must be an email.
- **file**. Value must be an array of `UploadedFileInterface` objects or an `UploadedFileInterface` object.
- **array**. Value must be an array.
- **datetime**. Value must be a `DateTime` format.
- **number**. Value must be a generic number.
- **int**. Value must be an integer.
- **float**. Value must be a float.
- **url**. Value must be a url.
- **slug**. Value must be a slug.
- **boolean**. Value must be a boolean.
- **any**. Value may be anything, without sanitization (this is useful for html code).

#### `required()`

[](#required)

Set field require. The value must not be empty.

#### `pattern(string $type)`

[](#patternstring-type)

Set field pattern. The value must match regular expression.

#### `equal($value)`

[](#equalvalue)

Set field value. The value must be the same.

#### `match(... $value)`

[](#match-value)

Set field matches. The value must match at one of the values.

#### `length(int $min, int $max)`

[](#lengthint-min-int-max)

Set field length. The value may not be less than `$min` and greater than `$max`.

#### `maxSize(int $size)`

[](#maxsizeint-size)

Set field file max size. The size of the file must not be greater than `$size` in bytes.

#### `accept(... $ext)`

[](#accept-ext)

Set allowed extensions for file field. The extension must match at one of the values.

#### `result(): array`

[](#result-array)

Return validation result. This method return an array like so:

```
    return [
        'status' => 200,
        'data' => [
            'title' => 'Hello World!',
            'body' => 'This is a post...',
            'name' => ''
        ],
        'errors' => [
            'name' => [
                'The name field is required.'
            ]
        ],
        'errorList' => [
            'The name field is required.'
        ]
    ];
```

If validation fails, status is `400`, otherwise is `200`.

#### `isSuccess(): bool`

[](#issuccess-bool)

Return `true` if validation pass, otherwise return `false`.

#### `getErrors(): array`

[](#geterrors-array)

Return errors multidimensional array where key is field name and value is an errors array.

#### `getErrorList(): array`

[](#geterrorlist-array)

Return errors array.

#### `getData([string $key])`

[](#getdatastring-key)

Return sanitized data array. If the value is an instance of `UploadedFileInterface`, you must use, for example, `$file->getClientFilename()` for returning file name. You may returning single item:

```
    echo $validation->getData('title'); // Hello World!
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16277144?v=4)[Davide Cesarano](/maintainers/davidecesarano)[@davidecesarano](https://github.com/davidecesarano)

---

Top Contributors

[![davidecesarano](https://avatars.githubusercontent.com/u/16277144?v=4)](https://github.com/davidecesarano "davidecesarano (23 commits)")

---

Tags

phpphp7psr-7validation

### Embed Badge

![Health badge](/badges/davidecesarano-embryo-validation/health.svg)

```
[![Health](https://phpackages.com/badges/davidecesarano-embryo-validation/health.svg)](https://phpackages.com/packages/davidecesarano-embryo-validation)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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