Initial upload of the control panel

This commit is contained in:
Pinga 2023-08-07 13:14:05 +03:00
parent f21bd93fbc
commit 7eab26586c
791 changed files with 312718 additions and 0 deletions

37
cp/app/Lib/Validator.php Normal file
View file

@ -0,0 +1,37 @@
<?php
namespace App\Lib;
use Respect\Validation\Validator as Respect;
use Respect\Validation\Exceptions\NestedValidationException;
/**
* Validator
*
* @author Hezekiah O. <support@hezecom.com>
*/
class Validator
{
protected $errors;
public function validate($request, array $rules)
{
$data = $request->getParsedBody();
foreach ($rules as $field => $rule) {
$fieldName = str_replace('_',' ',$field);
try {
$rule->setName(ucfirst($fieldName))->assert($data[$field]);
} catch (NestedValidationException $e) {
$this->errors[$field] = $e->getMessages();
}
}
$_SESSION['errors'] = $this->errors;
return $this;
}
public function failed()
{
return !empty($this->errors);
}
}