dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
dbxValidator_rules_audit_test.php
Go to the documentation of this file.
1<?php
2
10
11$root = dirname(__DIR__, 2);
12require_once $root . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'dbxValidator.class.php';
13
15$rules = array();
16$errors = array();
17
18$iterator = new RecursiveIteratorIterator(
19 new RecursiveDirectoryIterator(
20 $root . DIRECTORY_SEPARATOR . 'modules',
21 FilesystemIterator::SKIP_DOTS
22 )
23);
24
25$patterns = array(
26 '/\$field\s*\‍[\s*([\'"])rules\1\s*\‍]\s*=\s*([\'"])(.*?)\2\s*;/s',
27 '/\brules\s*:\s*([\'"])(.*?)\1/s',
28);
29
30foreach ($iterator as $file) {
31 if (!$file->isFile() || strtolower($file->getExtension()) !== 'php') {
32 continue;
33 }
34
35 $path = str_replace('\\', '/', $file->getPathname());
36 $relativePath = '/' . ltrim(str_replace(
37 '\\',
38 '/',
39 substr($file->getPathname(), strlen($root . DIRECTORY_SEPARATOR . 'modules'))
40 ), '/');
41 if (strpos($relativePath, '/vendor/') !== false
42 || strpos($relativePath, '/add_ons/') !== false
43 || strpos($relativePath, '/work/') !== false) {
44 continue;
45 }
46
47 $source = (string)file_get_contents($file->getPathname());
48 foreach ($patterns as $patternNo => $pattern) {
49 if (!preg_match_all($pattern, $source, $matches, PREG_SET_ORDER)) {
50 continue;
51 }
52
53 foreach ($matches as $match) {
54 $valueIndex = $patternNo === 0 ? 3 : 2;
55 $rule = stripcslashes((string)($match[$valueIndex] ?? ''));
56 if ($rule === '' || strpbrk($rule, '${}') !== false) {
57 continue;
58 }
59 $rules[$rule] = true;
60
61 $result = $validator->validateResult('', $rule, 'audit');
62 if (($result['code'] ?? '') === 'invalid_rule') {
63 $errors[] = $path . ': ' . $rule;
64 }
65 }
66 }
67}
68
69if (!$rules) {
70 fwrite(STDERR, "FAIL: Keine literal definierten Validator-Regeln gefunden.\n");
71 exit(1);
72}
73
74if ($errors) {
75 fwrite(STDERR, "FAIL: Unbekannte oder widerspruechliche Validator-Regeln:\n - "
76 . implode("\n - ", array_unique($errors)) . "\n");
77 exit(1);
78}
79
80echo 'OK: ' . count($rules) . " literal definierte Validator-Regeln sind kompatibel.\n";
Zentrale, strikt pruefende Eingabevalidierung.
exit
Definition index.php:146