1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* 2018 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
|
|
|
const ERROR_CODE_CLASS_NOT_FOUND = 1487710245; |
22
|
|
|
const ERROR_CODE_CLASS_NOT_VALID = 1487710370; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $supportedOptions = [ |
28
|
|
|
'interface' => [ |
29
|
|
|
'', |
30
|
|
|
'Name of the interface that the class name should implement.', |
31
|
|
|
'string', |
32
|
|
|
true |
33
|
|
|
] |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Checks if the value is an existing class. |
38
|
|
|
* |
39
|
|
|
* @param mixed $value The value that should be validated. |
40
|
|
|
*/ |
41
|
|
|
public function isValid($value) |
42
|
|
|
{ |
43
|
|
|
if (false === Core::get()->classExists($value)) { |
44
|
|
|
$errorMessage = $this->translateErrorMessage( |
45
|
|
|
'validator.class_exists.not_valid', |
46
|
|
|
'configuration_object', |
47
|
|
|
[$value] |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$this->addError($errorMessage, self::ERROR_CODE_CLASS_NOT_FOUND); |
51
|
|
|
} elseif (false === in_array($this->options['interface'], class_implements($value))) { |
52
|
|
|
$errorMessage = $this->translateErrorMessage( |
53
|
|
|
'validator.class_implements_interface.not_valid', |
54
|
|
|
'configuration_object', |
55
|
|
|
[$value, $this->options['interface']] |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$this->addError($errorMessage, self::ERROR_CODE_CLASS_NOT_VALID); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|