mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-06 01:25:00 +02:00
Initial upload of the control panel
This commit is contained in:
parent
f21bd93fbc
commit
7eab26586c
791 changed files with 312718 additions and 0 deletions
37
cp/app/Lib/Validator.php
Normal file
37
cp/app/Lib/Validator.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue