Add Validators\Html
This commit is contained in:
parent
6062ef8a95
commit
0ba9511177
1 changed files with 42 additions and 0 deletions
42
app/Models/Validators/Html.php
Normal file
42
app/Models/Validators/Html.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue