[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Validation / Validator / ConjunctionValidator.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Validation\Validator;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Validator to chain many validators in a conjunction (logical and).
19 *
20 * @api
21 */
22 class ConjunctionValidator extends AbstractCompositeValidator {
23
24 /**
25 * Checks if the given value is valid according to the validators of the conjunction.
26 * Every validator has to be valid, to make the whole conjunction valid.
27 *
28 * @param mixed $value The value that should be validated
29 * @return \TYPO3\CMS\Extbase\Error\Result
30 * @api
31 */
32 public function validate($value) {
33 $validators = $this->getValidators();
34 if ($validators->count() > 0) {
35 $result = NULL;
36 foreach ($validators as $validator) {
37 if ($result === NULL) {
38 $result = $validator->validate($value);
39 } else {
40 $result->merge($validator->validate($value));
41 }
42 }
43 } else {
44 $result = new \TYPO3\CMS\Extbase\Error\Result;
45 }
46
47 return $result;
48 }
49
50 /**
51 * Checks if the given value is valid according to the validators of the conjunction.
52 *
53 * If at least one error occurred, the result is FALSE.
54 *
55 * @param mixed $value The value that should be validated
56 * @return boolean
57 * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
58 */
59 public function isValid($value) {
60 $result = TRUE;
61 foreach ($this->validators as $validator) {
62 if ($validator->isValid($value) === FALSE) {
63 $this->errors = array_merge($this->errors, $validator->getErrors());
64 $result = FALSE;
65 }
66 }
67 return $result;
68 }
69 }