1 | <?php |
||
10 | abstract class BaseValidator extends SchemaValidator |
||
11 | { |
||
12 | public function __construct($descriptor, $basePath = null) |
||
17 | |||
18 | /** |
||
19 | * validate a descriptor. |
||
20 | * |
||
21 | * @param object $descriptor |
||
22 | * @param string $basePath |
||
23 | * |
||
24 | * @return \frictionlessdata\tableschema\SchemaValidationError[] |
||
25 | */ |
||
26 | public static function validate($descriptor, $basePath = null) |
||
32 | |||
33 | protected $basePath; |
||
34 | |||
35 | /** |
||
36 | * should be implemented properly by extending classes |
||
37 | * should return the profile used for validation |
||
38 | * if using the default getValidationSchemaUrl function - this value should correspond to a file in schemas/ directory. |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | protected function getValidationProfile() |
||
46 | |||
47 | protected function convertValidationSchemaFilenameToUrl($filename) |
||
56 | |||
57 | protected function getJsonSchemaFileFromRegistry($profile) |
||
61 | |||
62 | /** |
||
63 | * get the url which the schema for validation can be fetched from. |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | protected function getValidationSchemaUrl() |
||
84 | |||
85 | /** |
||
86 | * Allows to specify different error classes for different validators. |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | protected function getSchemaValidationErrorClass() |
||
94 | |||
95 | /** |
||
96 | * allows extending classes to modify the descriptor before passing to the validator. |
||
97 | * |
||
98 | * @return object |
||
99 | */ |
||
100 | protected function getDescriptorForValidation() |
||
104 | |||
105 | /** |
||
106 | * conver the validation error message received from JsonSchema to human readable string. |
||
107 | * |
||
108 | * @param array $error |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | protected function getValidationErrorMessage($error) |
||
116 | |||
117 | /** |
||
118 | * does the validation, adds errors to the validator object using _addError method. |
||
119 | */ |
||
120 | protected function validateSchema() |
||
124 | |||
125 | protected function validateSchemaUrl($url) |
||
139 | |||
140 | /** |
||
141 | * Add an error to the validator object - errors are aggregated and returned by validate function. |
||
142 | * |
||
143 | * @param int $code |
||
144 | * @param null|mixed $extraDetails |
||
145 | */ |
||
146 | protected function addError($code, $extraDetails = null) |
||
152 | |||
153 | protected function validateKeys() |
||
160 | } |
||
161 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: