Add Validators\Html

This commit is contained in:
Visman 2021-03-04 12:55:02 +07:00
parent 6062ef8a95
commit 0ba9511177

View file

@ -0,0 +1,42 @@
<?php
/**
* This file is part of the ForkBB <https://github.com/forkbb>.
*
* @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
* @license The MIT License (MIT)
*/
declare(strict_types=1);
namespace ForkBB\Models\Validators;
use ForkBB\Core\RulesValidator;
use ForkBB\Core\Validator;
use function \ForkBB\__;
class Html extends RulesValidator
{
/**
* Обрабатывает html код в соответствии с заданными правилами
*
* @param Validator $v
* @param string $value
*
* @return mixed
*/
public function html(Validator $v, string $value)
{
$errors = [];
$result = $this->c->HTMLCleaner->setConfig()->parse($value, $errors);
if (empty($errors)) {
return $result;
} else {
foreach ($errors as $args) {
$v->addError(__(...$args));
}
return $value;
}
}
}