Arbit - project tracking

PHPillow - PHP CouchDB connector

Browse source code

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

Type
text/plain text/plain
Last Author
jakob
Version
174
Line Rev. Author Source
1 174 jakob <?php
2 jakob /**
3 jakob * phpillow CouchDB backend
4 jakob *
5 jakob * This file is part of phpillow.
6 jakob *
7 jakob * phpillow is free software; you can redistribute it and/or modify it under
8 jakob * the terms of the GNU Lesser General Public License as published by the Free
9 jakob * Software Foundation; version 3 of the License.
10 jakob *
11 jakob * phpillow is distributed in the hope that it will be useful, but WITHOUT ANY
12 jakob * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 jakob * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 jakob * more details.
15 jakob *
16 jakob * You should have received a copy of the GNU Lesser General Public License
17 jakob * along with phpillow; if not, write to the Free Software Foundation, Inc., 51
18 jakob * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 jakob *
20 jakob * @package Core
21 jakob * @version $Revision: 174 $
22 jakob * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL
23 jakob */
24 jakob
25 jakob /**
26 jakob * Validate uuid version 4 inputs
27 jakob *
28 jakob * @package Core
29 jakob * @version $Revision: 174 $
30 jakob * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL
31 jakob */
32 jakob class phpillowUuidValidator extends phpillowValidator
33 jakob {
34 jakob /**
35 jakob * Validate input as uuid version 4
36 jakob *
37 jakob * @param string $input
38 jakob *
39 jakob * @throws phpillowValidationException if the given input does not conform
40 jakob * to a uuid version 4
41 jakob *
42 jakob * @return string
43 jakob */
44 jakob public function validate( $input )
45 jakob {
46 jakob $uuidv4Pattern = '(^([0-9a-fA-F]{8})-?([0-9a-fA-F]{4})-?(4[0-9a-fA-F]{3})-?([89abAB][0-9a-fA-F]{3})-?([0-9a-fA-F]{12})$)';
47 jakob if ( preg_match( $uuidv4Pattern, $input, $matches ) !== 1 )
48 jakob {
49 jakob throw new phpillowValidationException(
50 jakob 'A uuid version 4 is required. Something else has been given.',
51 jakob array()
52 jakob );
53 jakob }
54 jakob
55 jakob return strtolower(
56 jakob $matches[1] . '-' . $matches[2] . '-' . $matches[3] . '-' . $matches[4] . '-' . $matches[5]
57 jakob );
58 jakob }
59 jakob }