Arbit - project tracking

PHPillow - PHP CouchDB connector

Browse source code

File: / src/ classes/ validator/ or.php

Type
text/plain text/plain
Last Author
hco
Version
177
Line Rev. Author Source
1 177 hco <?php
2 hco /**
3 hco * phpillow CouchDB backend
4 hco *
5 hco * This file is part of phpillow.
6 hco *
7 hco * phpillow is free software; you can redistribute it and/or modify it under
8 hco * the terms of the GNU Lesser General Public License as published by the Free
9 hco * Software Foundation; version 3 of the License.
10 hco *
11 hco * phpillow is distributed in the hope that it will be useful, but WITHOUT ANY
12 hco * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 hco * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 hco * more details.
15 hco *
16 hco * You should have received a copy of the GNU Lesser General Public License
17 hco * along with phpillow; if not, write to the Free Software Foundation, Inc., 51
18 hco * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 hco *
20 hco * @package Core
21 hco * @version $Revision: 177 $
22 hco * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL
23 hco */
24 hco
25 hco /**
26 hco * Validate object inputs
27 hco *
28 hco * @package Core
29 hco * @version $Revision: 177 $
30 hco * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL
31 hco */
32 hco class phpillowOrValidator extends phpillowValidator
33 hco {
34 hco /**
35 hco * Array of validators to be checked
36 hco *
37 hco * @var array
38 hco */
39 hco protected $validators;
40 hco
41 hco
42 hco /**
43 hco * Validator constructor
44 hco *
45 hco * Validator constructor to specify the validators that should be checked.
46 hco *
47 hco * @param array $validators
48 hco * @return void
49 hco */
50 hco public function __construct( array $validators )
51 hco {
52 hco $this->validators = $validators;
53 hco }
54 hco
55 hco /**
56 hco * Validate input as object
57 hco *
58 hco * @param stdclass $input
59 hco * @return StdClass
60 hco */
61 hco public function validate( $input )
62 hco {
63 hco $validatorClassNames = array();
64 hco
65 hco $validatorExceptions = array();
66 hco
67 hco foreach( $this->validators as $validator )
68 hco {
69 hco try {
70 hco return $validator->validate( $input );
71 hco } catch( phpillowValidationException $e ) {
72 hco $validatorClassName = get_class( $validator );
73 hco $validatorClassNames[] = $validatorClassName;
74 hco $validatorExceptions[$validatorClassName] = $e;
75 hco }
76 hco }
77 hco
78 hco $exception = new phpillowValidationException(
79 hco 'Could not validate, as none of the given validators (%validators) validated the input.',
80 hco array(
81 hco 'validators' => join( ',', $validatorClassNames )
82 hco )
83 hco );
84 hco
85 hco $exception->validatorExceptions = $validatorExceptions;
86 hco
87 hco throw $exception;
88 hco }
89 hco }