-
Notifications
You must be signed in to change notification settings - Fork 11
/
Utilities.php
77 lines (67 loc) · 2.63 KB
/
Utilities.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace MABI;
class ReflectionHelper {
public static function stripClassName($fullName) {
$components = explode('\\', $fullName);
return $components[count($components) - 1];
}
public static function getPrefixFromControllerClass($controllerClass) {
if (substr($controllerClass, -strlen('Controller')) === 'Controller') {
return substr($controllerClass, 0, strlen($controllerClass) - strlen('Controller'));
}
throw new \Exception('Cannot find model for model controller ' . $controllerClass);
}
public static function getDocDirective($docComments, $property) {
$matches = array();
preg_match_all('/\@' . $property . '\s(.*)\s/', $docComments, $matches);
return $matches[1];
}
public static function getDocText($docComments) {
// Doc comments include things like ' /** ' and ' * ' before the actual text. This function
// cleans all of that up.
$docComments = preg_replace('/^\s*\/\*\*.*\\n/m', '', $docComments); // Gets rid of ' /** '
$docComments = preg_replace('/^\s*\*\/\s*/m', '', $docComments); // gets rid of ' */'
$docComments = preg_replace('/^\s*\*\s*\n/m', "\n", $docComments); // gets rid of blank ' * '
$docComments = preg_replace('/^\s*\*\s/m', '', $docComments); // gets rid of the pre ' * '
// Gets rid of doc directives
$docComments = preg_replace('/^\@.*\\n/m', '', $docComments);
$docComments = preg_replace('/\@docs-jsondesc-start(.|\n|\r)*\@docs-jsondesc-end\n/m', '', $docComments);
return $docComments;
}
public static function createClassName($namespace, $className) {
return (empty($namespace) ? '' : $namespace) . "\\{$className}";
}
}
class DirectoryHelper {
/**
* todo: docs
*
* @param string $directory
* @param bool $recursive
* @param string $extension
*
* @return array
*/
public static function directoryToArray($directory, $recursive = FALSE, $extension = NULL) {
$array_items = array();
if ($handle = opendir($directory)) {
while (FALSE !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && (empty($extension) ||
(!empty($extension) && substr($file, -strlen($extension)) === $extension))
) {
if (is_dir($directory . "/" . $file)) {
if ($recursive) {
$array_items = array_merge($array_items, self::directoryToArray($directory . "/" . $file, $recursive));
}
}
else {
$file = $directory . "/" . $file;
$array_items[] = preg_replace("/\/\//si", "/", $file);
}
}
}
closedir($handle);
}
return $array_items;
}
}