[CLEANUP] Adjust code to coding guidelines
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Validation / Validator / DisjunctionValidator.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Validation\Validator;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * This class is a backport of the corresponding class of TYPO3 Flow.
8 * All credits go to the TYPO3 Flow team.
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Validator to chain many validators in a disjunction (logical or). So only one
32 * validator has to be valid, to make the whole disjunction valid. Errors are
33 * only returned if all validators failed.
34 *
35 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
36 */
37 class DisjunctionValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator {
38
39 /**
40 * Checks if the given value is valid according to the validators of the
41 * disjunction.
42 *
43 * If all validators fail, the result is FALSE.
44 *
45 * @param mixed $value The value that should be validated
46 * @param boolean $resetInstancesCurrentlyUnderValidation Reserved for internal use!
47 * @return \TYPO3\CMS\Extbase\Error\Result
48 * @api
49 */
50 public function validate($value, $resetInstancesCurrentlyUnderValidation = TRUE) {
51 $result = new \TYPO3\CMS\Extbase\Error\Result();
52 $oneWithoutErrors = FALSE;
53 foreach ($this->validators as $validator) {
54 $validatorResult = $validator->validate($value);
55 if ($validatorResult->hasErrors()) {
56 $result->merge($validatorResult);
57 } else {
58 $oneWithoutErrors = TRUE;
59 }
60 }
61 if ($oneWithoutErrors === TRUE) {
62 $result = new \TYPO3\CMS\Extbase\Error\Result();
63 }
64 return $result;
65 }
66
67 /**
68 * Checks if the given value is valid according to the validators of the conjunction.
69 *
70 * If at least one error occurred, the result is FALSE.
71 *
72 * @param mixed $value The value that should be validated
73 * @return boolean TRUE if the value is valid, FALSE if an error occured
74 * @deprecated since Extbase 1.4.0, will be removed in Extbase 6.1
75 */
76 public function isValid($value) {
77 $result = FALSE;
78 foreach ($this->validators as $validator) {
79 if ($validator->isValid($value) === FALSE) {
80 $this->errors = array_merge($this->errors, $validator->getErrors());
81 } else {
82 $result = TRUE;
83 }
84 }
85 if ($result === TRUE) {
86 $this->errors = array();
87 }
88 return $result;
89 }
90 }
91
92 ?>