This repository was archived by the owner on Mar 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldValidator.php
More file actions
65 lines (57 loc) · 1.38 KB
/
FieldValidator.php
File metadata and controls
65 lines (57 loc) · 1.38 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
*/
namespace Ulrack\Cli\Component\Element\Form;
use Ulrack\Cli\Common\Element\ElementInterface;
use Ulrack\Cli\Common\Element\Form\FieldValidatorInterface;
use GrizzIt\Validator\Common\ValidatorInterface;
class FieldValidator implements FieldValidatorInterface
{
/**
* Contains the error which should be displayed when validation fails.
*
* @var ElementInterface
*/
private $error;
/**
* Contains the validator which validates the field.
*
* @var ValidatorInterface
*/
private $validator;
/**
* Constructor.
*
* @param ValidatorInterface $validator
* @param ElementInterface $error
*/
public function __construct(
ValidatorInterface $validator,
ElementInterface $error
) {
$this->validator = $validator;
$this->error = $error;
}
/**
* Retrieves the error message for the field.-white
*
* @return ElementInterface
*/
public function getError(): ElementInterface
{
return $this->error;
}
/**
* Validate the data against the validator.
*
* @param string|object|array $data
*
* @return bool
*/
public function __invoke($data): bool
{
return $this->validator->__invoke($data);
}
}