1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Tester;
9:
10:
11: 12: 13: 14: 15:
16: class Helpers
17: {
18:
19: 20: 21: 22: 23:
24: public static function purge($dir)
25: {
26: if (!is_dir($dir)) {
27: mkdir($dir);
28: }
29: foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $entry) {
30: if ($entry->isDir()) {
31: rmdir($entry);
32: } else {
33: unlink($entry);
34: }
35: }
36: }
37:
38:
39: 40: 41: 42: 43:
44: public static function ($s)
45: {
46: $options = array();
47: if (!preg_match('#^/\*\*(.*?)\*/#ms', $s, $content)) {
48: return array();
49: }
50: if (preg_match('#^[ \t\*]*+([^\s@].*)#mi', $content[1], $matches)) {
51: $options[0] = trim($matches[1]);
52: }
53: preg_match_all('#^[ \t\*]*@(\w+)([^\w\r\n].*)?#mi', $content[1], $matches, PREG_SET_ORDER);
54: foreach ($matches as $match) {
55: $ref = & $options[strtolower($match[1])];
56: if (isset($ref)) {
57: $ref = (array) $ref;
58: $ref = & $ref[];
59: }
60: $ref = isset($match[2]) ? trim($match[2]) : '';
61: }
62: return $options;
63: }
64:
65:
66: 67: 68:
69: public static function errorTypeToString($type)
70: {
71: $consts = get_defined_constants(TRUE);
72: foreach ($consts['Core'] as $name => $val) {
73: if ($type === $val && substr($name, 0, 2) === 'E_') {
74: return $name;
75: }
76: }
77: }
78:
79:
80: 81: 82: 83:
84: public static function escapeArg($s)
85: {
86: return defined('PHP_WINDOWS_VERSION_BUILD')
87: ? '"' . str_replace('"', '""', $s) . '"'
88: : escapeshellarg($s);
89: }
90:
91: }
92: