PHPackages                             phpsoftbox/validator-db - 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. phpsoftbox/validator-db

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

phpsoftbox/validator-db
=======================

Database validation contract for the PhpSoftBox framework

v1.2.1(2mo ago)0136↓83.3%MITPHPPHP ^8.4

Since Feb 3Pushed 2w agoCompare

[ Source](https://github.com/phpsoftbox/validator-db)[ Packagist](https://packagist.org/packages/phpsoftbox/validator-db)[ RSS](/packages/phpsoftbox-validator-db/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (4)Dependencies (6)Versions (6)Used By (0)

PhpSoftBox Validator DB
=======================

[](#phpsoftbox-validator-db)

Контракты, правила и executors для интеграции `phpsoftbox/validator` с базой данных.

Установка
---------

[](#установка)

```
composer require phpsoftbox/validator-db
```

Adapter
-------

[](#adapter)

Для одиночных проверок реализуйте `DatabaseValidationAdapterInterface`:

```
use PhpSoftBox\Validator\Db\Contracts\DatabaseValidationAdapterInterface;

final class DatabaseValidationAdapter implements DatabaseValidationAdapterInterface
{
    public function exists(string $table, array $criteria, ?string $connection = null): bool
    {
        // Проверка существования записи.
    }

    public function unique(
        string $table,
        array $criteria,
        ?string $connection = null,
        ?string $ignoreColumn = null,
        mixed $ignoreValue = null,
    ): bool {
        // Проверка уникальности записи.
    }
}
```

Для `ExistsValidation::all()` реализуйте `DatabaseBulkValidationAdapterInterface` и возвращайте `ExistingValuesQueryInterface`. Bulk-запрос получает `LookupSpec`, содержащий таблицу, lookup-column, список значений, дополнительные where-критерии и warmup key columns.

Регистрация executors
---------------------

[](#регистрация-executors)

```
use PhpSoftBox\Validator\Db\Rule\Executor\ExistsRuleExecutor;
use PhpSoftBox\Validator\Db\Rule\Executor\UniqueRuleExecutor;
use PhpSoftBox\Validator\Db\Rule\ExistsValidation;
use PhpSoftBox\Validator\Db\Rule\UniqueValidation;
use PhpSoftBox\Validator\Rule\Executor\RuleExecutorRegistry;

$registry = new RuleExecutorRegistry([
    [ExistsValidation::class, new ExistsRuleExecutor($adapter)],
    [UniqueValidation::class, new UniqueRuleExecutor($adapter)],
]);
```

Передайте registry в `PhpSoftBox\Validator\Validator`.

Exists
------

[](#exists)

```
ExistsValidation::make()
    ->table('users')
    ->column('email')
    ->where('active', true)
    ->connection('main');
```

Bulk-проверка всех значений:

```
use PhpSoftBox\DatabaseLookup\LookupSpec;

ExistsValidation::make()
    ->table('products')
    ->column('id')
    ->all(
        LookupSpec::forTable('products')
            ->lookupColumn('id')
            ->keyColumns('tenant_id', 'id'),
    )
    ->where('tenant_id', 10)
    ->warmup();
```

Unique
------

[](#unique)

```
UniqueValidation::make()
    ->table('users')
    ->column('email')
    ->where('tenant_id', 10)
    ->ignore($userId)
    ->connection('main');
```

Breaking change
---------------

[](#breaking-change)

DB rules и executors перенесены из Validator. Старые namespace не поддерживаются:

```
PhpSoftBox\Validator\Rule\ExistsValidation
    → PhpSoftBox\Validator\Db\Rule\ExistsValidation

PhpSoftBox\Validator\Rule\UniqueValidation
    → PhpSoftBox\Validator\Db\Rule\UniqueValidation

PhpSoftBox\Validator\Rule\Executor\Database\ExistsRuleExecutor
    → PhpSoftBox\Validator\Db\Rule\Executor\ExistsRuleExecutor

PhpSoftBox\Validator\Rule\Executor\Database\UniqueRuleExecutor
    → PhpSoftBox\Validator\Db\Rule\Executor\UniqueRuleExecutor

```

Подробные примеры находятся в `docs/exists-validation.md` и `docs/unique-validation.md`.

Лицензия
--------

[](#лицензия)

MIT

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance93

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

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 ~33 days

Total

5

Last Release

63d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0279d150240c97d210034878b0467462246dc14d29b5618157ff6a8be49a50e3?d=identicon)[inspector-who](/maintainers/inspector-who)

---

Top Contributors

[![inspector-who](https://avatars.githubusercontent.com/u/6973963?v=4)](https://github.com/inspector-who "inspector-who (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/phpsoftbox-validator-db/health.svg)

```
[![Health](https://phpackages.com/badges/phpsoftbox-validator-db/health.svg)](https://phpackages.com/packages/phpsoftbox-validator-db)
```

###  Alternatives

[toplan/laravel-sms

A mobile phone number validation solution based on laravel

83580.2k2](/packages/toplan-laravel-sms)[drupal/coder

Coder is a library to review Drupal code.

3046.8M629](/packages/drupal-coder)[ph-7/eu-vat-validator

A simple and clean PHP class that validates EU VAT numbers against the central ec.europa.eu database (using the official europa API).

97510.7k1](/packages/ph-7-eu-vat-validator)[hyperf/validation

hyperf validation

122.2M213](/packages/hyperf-validation)[udokmeci/yii2-phone-validator

Modern Yii2 Phone validator wrapper on top of PhoneNumberUtil library also used by Android devices

36227.5k1](/packages/udokmeci-yii2-phone-validator)[snowcap/vat-validation

EU VAT number validation

10112.3k](/packages/snowcap-vat-validation)

PHPackages © 2026

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