PHPackages                             celiovmjr/smartvalidator - 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. celiovmjr/smartvalidator

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

celiovmjr/smartvalidator
========================

Validate. Sanitize. Secure Your Data.

2.0.5(2y ago)0123MITPHPPHP &gt;=8.1

Since Jun 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/celiovmjr/SmartValidator)[ Packagist](https://packagist.org/packages/celiovmjr/smartvalidator)[ RSS](/packages/celiovmjr-smartvalidator/feed)WikiDiscussions main Synced yesterday

READMEChangelog (8)Dependencies (1)Versions (10)Used By (0)

SmartValidator
==============

[](#smartvalidator)

The **SmartValidator** is a PHP class designed to validate and filter input data based on configurable rules. It supports a variety of simple and complex validations, ensuring that data meets specified criteria before being considered valid.

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

[](#installation)

To use the SmartValidator, include the `SmartValidator.php` class file in your PHP project and instantiate the class as needed.

```
require_once 'SmartValidator.php';

// Basic usage example
$data = [
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'age' => 30,
];

$rules = [
    'name' => 'string|required',
    'email' => 'email|required',
    'age' => 'int|required|min:18',
];

$validator = new Validator\Application\SmartValidator($data, $rules);
$validatedData = $validator->getValidated();

// $validatedData will contain the validated data according to the specified rules
```

Features
--------

[](#features)

### Constructor

[](#constructor)

```
public function __construct(array|object $data, array $rules)
```

- **$data**: Associative array containing the data to be validated.
- **$rules**: Associative array where keys represent property names to validate, and values are strings containing validation rules separated by pipe (`|`).

### Supported Validation Methods

[](#supported-validation-methods)

The SmartValidator supports the following types of validation:

- **Simple Types**:

    - `string`: Validates if the value is a string and applies sanitization.
    - `bool`: Validates and converts the value to boolean.
    - `int`: Validates and converts the value to integer.
    - `float`: Validates and converts the value to float.
    - `email`: Validates if the value is a valid email address.
    - `url`: Validates if the value is a valid URL.
    - `ip`: Validates if the value is a valid IP address.
    - `required`: Validates if the value is not null or empty.
    - `uuid`: Validates if the value is a valid UUID.
- **Complex Validations**:

    - `min:x`: Validates if the numeric value is greater than or equal to `x`, or if the string has at least `x` characters.
    - `max:x`: Validates if the numeric value is less than or equal to `x`, or if the string has at most `x` characters.
    - `range:min,max`: Validates if the value is within the specified range.
    - `format:format`: Validates if the value matches the specified date format.
    - `before:date,format`: Validates if the value is a date before the specified date.
    - `after:date,format`: Validates if the value is a date after the specified date.
    - `in:val1,val2,...`: Validates if the value is among the allowed values.
    - `size:size`: Validates if the size of the value is equal to `size`.
    - `mime:type1,type2,...`: Validates if the MIME type of the value is among the allowed types.

### Exceptions

[](#exceptions)

The SmartValidator throws `InvalidArgumentException` when a validation fails, with detailed error messages explaining the reason for the validation failure.

### Return

[](#return)

- **getValidated()**: Returns an associative array containing successfully validated data according to the specified rules.

```
public function getValidated(): array
```

Final Notes
-----------

[](#final-notes)

The SmartValidator offers a flexible solution for data validation in PHP, providing a robust mechanism to ensure input data meets defined requirements before processing or storing. It facilitates the implementation of complex validations in a clear and structured manner, promoting data security and integrity in PHP applications.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

Every ~1 days

Total

9

Last Release

733d ago

Major Versions

1.0.2 → 2.0.02024-06-26

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/58183571?v=4)[Célio Junior](/maintainers/celiovmjr)[@celiovmjr](https://github.com/celiovmjr)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/celiovmjr-smartvalidator/health.svg)

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

###  Alternatives

[marcosh/php-validation-dsl

A DSL for validating data in a functional fashion

483.9k](/packages/marcosh-php-validation-dsl)

PHPackages © 2026

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