1. Go to this page and download the library: Download mb4it/validation 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/ */
use MB\Validation\Concerns\ValidatesProperties;
final class ProductDto
{
use ValidatesProperties;
protected string $validatorLang = 'ru'; // optional
public function __construct(
public string $title,
protected array $items,
private array $profile,
) {}
protected function rules(): array
{
return [
'title' => '
use MB\Validation\Factory;
use MB\Validation\Validator;
public function validator(): Validator
{
return Factory::create(lang: $this->validatorLang)->make(
$this->validationData(),
$this->rules()
);
}
use MB\Validation\Factory;
use MB\Validation\PresenceVerifierInterface;
final class MyPresenceVerifier implements PresenceVerifierInterface
{
public function getCount($collection, $column, $value, $excludeId = null, $idColumn = null, array $extra = [])
{
return 0;
}
public function getMultiCount($collection, $column, array $values, array $extra = [])
{
return 0;
}
}
$factory = Factory::create();
$factory->setPresenceVerifier(new MyPresenceVerifier());