|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Validator.php - Jaxon input data validator |
|
5
|
|
|
* |
|
6
|
|
|
* Validate requests data before the are passed into the library. |
|
7
|
|
|
* |
|
8
|
|
|
* @package jaxon-core |
|
9
|
|
|
* @author Thierry Feuzeu <[email protected]> |
|
10
|
|
|
* @copyright 2016 Thierry Feuzeu <[email protected]> |
|
11
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
|
12
|
|
|
* @link https://github.com/jaxon-php/jaxon-core |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Jaxon\Utils\Validation; |
|
16
|
|
|
|
|
17
|
|
|
/* |
|
18
|
|
|
* See the following links to get explanations about the regexp. |
|
19
|
|
|
* http://php.net/manual/en/language.oop5.basic.php |
|
20
|
|
|
* http://stackoverflow.com/questions/3195614/validate-class-method-names-with-regex |
|
21
|
|
|
* http://www.w3schools.com/charsets/ref_html_utf8.asp |
|
22
|
|
|
* http://www.w3schools.com/charsets/ref_utf_latin1_supplement.asp |
|
23
|
|
|
*/ |
|
24
|
|
|
class Validator |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Validate a function name |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $sName The function name |
|
30
|
|
|
* |
|
31
|
|
|
* @return bool True if the function name is valid, and false if not |
|
32
|
|
|
*/ |
|
33
|
|
|
public function validateFunction($sName) |
|
34
|
|
|
{ |
|
35
|
|
|
return preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $sName); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Validate an event name |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $sName The event name |
|
42
|
|
|
* |
|
43
|
|
|
* @return bool True if the event name is valid, and false if not |
|
44
|
|
|
*/ |
|
45
|
|
|
public function validateEvent($sName) |
|
46
|
|
|
{ |
|
47
|
|
|
return preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $sName); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Validate a class name |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $sName The class name |
|
54
|
|
|
* |
|
55
|
|
|
* @return bool True if the class name is valid, and false if not |
|
56
|
|
|
*/ |
|
57
|
|
|
public function validateClass($sName) |
|
58
|
|
|
{ |
|
59
|
|
|
return preg_match('/^([a-zA-Z][a-zA-Z0-9_]*)(\.[a-zA-Z][a-zA-Z0-9_]*)*$/', $sName); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Validate a method name |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $sName The function name |
|
66
|
|
|
* |
|
67
|
|
|
* @return bool True if the method name is valid, and false if not |
|
68
|
|
|
*/ |
|
69
|
|
|
public function validateMethod($sName) |
|
70
|
|
|
{ |
|
71
|
|
|
// return preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $sName); |
|
72
|
|
|
return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sName); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Validate an uploaded file |
|
77
|
|
|
* |
|
78
|
|
|
* @param array $aUploadedFile The file data received in the $_FILES array |
|
79
|
|
|
* |
|
80
|
|
|
* @return bool True if the file data are valid, and false if not |
|
81
|
|
|
*/ |
|
82
|
|
|
public function validateUploadedFile(array $aUploadedFile) |
|
|
|
|
|
|
83
|
|
|
{ |
|
84
|
|
|
return true; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.