-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_validator.php
45 lines (38 loc) · 1003 Bytes
/
post_validator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
# Class non instanciable pour la validation
class AbstractValidator {
protected $data;
protected $validator;
public $errors=array();
public $err=0;
public function __construct(array $data)
{
# Données postées $_POST
$this->data = $data;
# Validateur de formulaire
$this->validator = new Validator($this->data);
}
public function validate(): bool
{
# Récupère les erreurs
$this->errors = ($this->validator->err > 0 )? $this->validator->errors:array();
$this->err = ($this->validator->err > 0 )? $this->validator->err:0;
if($this->errors == null AND $this->err == 0 ){
}
return $this->validator->validate();
}
public function errors(): array
{
return $this->validator->errors;
}
}
class PostValidator extends AbstractValidator {
public function __construct(array $data)
{
parent::__construct($data);
$this->validator
->rule('required', ['field-name']);
$this->validator
->rule('lengthBetween', ['field-name'], 2, 4);
}
}