1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* 2017 Romain CANON <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the TYPO3 Configuration Object project. |
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
7
|
|
|
* under the terms of the GNU General Public License, either |
8
|
|
|
* version 3 of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, see: |
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Romm\ConfigurationObject\Validation\Validator; |
15
|
|
|
|
16
|
|
|
use Romm\ConfigurationObject\Core\Core; |
17
|
|
|
use TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator; |
18
|
|
|
|
19
|
|
|
class ClassImplementsValidator extends AbstractValidator |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
protected $supportedOptions = [ |
26
|
|
|
'interface' => [ |
27
|
|
|
'', |
28
|
|
|
'Name of the interface that the class name should implement.', |
29
|
|
|
'string', |
30
|
|
|
true |
31
|
|
|
] |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Checks if the value is an existing class. |
36
|
|
|
* |
37
|
|
|
* @param mixed $value The value that should be validated. |
38
|
|
|
*/ |
39
|
|
|
public function isValid($value) |
40
|
|
|
{ |
41
|
|
|
if (false === Core::get()->classExists($value)) { |
42
|
|
|
$errorMessage = $this->translateErrorMessage( |
43
|
|
|
'validator.class_exists.not_valid', |
44
|
|
|
'configuration_object', |
45
|
|
|
[$value] |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->addError($errorMessage, 1487710245); |
49
|
|
|
} elseif (false === in_array($this->options['interface'], class_implements($value))) { |
50
|
|
|
$errorMessage = $this->translateErrorMessage( |
51
|
|
|
'validator.class_implements_interface.not_valid', |
52
|
|
|
'configuration_object', |
53
|
|
|
[$value, $this->options['interface']] |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$this->addError($errorMessage, 1487710370); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|