Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ValidationRuleRegistry | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| getExtension | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getConfigId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getValidators | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2016 (original work) Open Assessment Technologies SA |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\tao\helpers\form; |
| 24 | |
| 25 | use oat\oatbox\AbstractRegistry; |
| 26 | use oat\generis\model\OntologyAwareTrait; |
| 27 | |
| 28 | /** |
| 29 | * The ValidationRuleRegistry allows you to register specific validation rules |
| 30 | * |
| 31 | * @package tao |
| 32 | */ |
| 33 | class ValidationRuleRegistry extends AbstractRegistry |
| 34 | { |
| 35 | use OntologyAwareTrait; |
| 36 | |
| 37 | public const REGISTRY_ID = 'validationRules'; |
| 38 | |
| 39 | public const PROPERTY_VALIDATION_RULE = 'http://www.tao.lu/Ontologies/generis.rdf#validationRule'; |
| 40 | |
| 41 | /** |
| 42 | * (non-PHPdoc) |
| 43 | * @see \oat\oatbox\AbstractRegistry::getExtension() |
| 44 | */ |
| 45 | protected function getExtension() |
| 46 | { |
| 47 | return \common_ext_ExtensionsManager::singleton()->getExtensionById('tao'); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * (non-PHPdoc) |
| 52 | * @see \oat\oatbox\AbstractRegistry::getConfigId() |
| 53 | */ |
| 54 | protected function getConfigId() |
| 55 | { |
| 56 | return self::REGISTRY_ID; |
| 57 | } |
| 58 | |
| 59 | public function getValidators(\core_kernel_classes_Property $property) |
| 60 | { |
| 61 | $validationProp = $this->getProperty(self::PROPERTY_VALIDATION_RULE); |
| 62 | $rules = []; |
| 63 | foreach ($property->getPropertyValues($validationProp) as $ruleId) { |
| 64 | $rule = $this->get($ruleId); |
| 65 | if ($rule == '') { |
| 66 | throw new \common_exception_NotFound('No validation rule found with id "' . $ruleId . '"'); |
| 67 | } |
| 68 | $rules[] = $rule; |
| 69 | } |
| 70 | return $rules; |
| 71 | } |
| 72 | } |