1. Go to this page and download the library: Download phpsoftbox/validator-db library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpsoftbox / validator-db example snippets
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 {
// Проверка уникальности записи.
}
}
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)],
]);