1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This software package is licensed under `AGPL, Commercial` license[s]. |
5
|
|
|
* |
6
|
|
|
* @package maslosoft/zamm |
7
|
|
|
* @license AGPL, Commercial |
8
|
|
|
* |
9
|
|
|
* @copyright Copyright (c) Peter Maselkowski <[email protected]> |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Maslosoft\Zamm; |
14
|
|
|
|
15
|
|
|
use DirectoryIterator; |
16
|
|
|
use ReflectionClass; |
17
|
|
|
use ReflectionProperty; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Iterator |
21
|
|
|
* |
22
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
23
|
|
|
*/ |
24
|
|
|
class Iterator |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Iterate over classes in same folder. |
29
|
|
|
* @param string $class |
30
|
|
|
* @return string[] |
31
|
|
|
*/ |
32
|
|
|
public static function ns($class) |
33
|
|
|
{ |
34
|
|
|
$info = new ReflectionClass($class); |
35
|
|
|
$path = dirname($info->getFileName()); |
36
|
|
|
$ns = $info->getNamespaceName(); |
37
|
|
|
$classNames = []; |
38
|
|
|
foreach (new DirectoryIterator($path) as $fileInfo) |
39
|
|
|
{ |
40
|
|
|
$name = $fileInfo->getFilename(); |
41
|
|
|
|
42
|
|
|
// Only files |
43
|
|
|
if (!$fileInfo->isFile()) |
44
|
|
|
{ |
45
|
|
|
continue; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// Only php |
49
|
|
|
if (!preg_match('~\.php$~', $name)) |
50
|
|
|
{ |
51
|
|
|
continue; |
52
|
|
|
} |
53
|
|
|
$classNames[] = sprintf('%s\%s', $ns, basename($name, '.php')); |
54
|
|
|
} |
55
|
|
|
sort($classNames); |
56
|
|
|
return $classNames; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Iterate over *public* class methods |
61
|
|
|
* @param string $class |
62
|
|
|
* @return string[] |
63
|
|
|
*/ |
64
|
|
|
public static function methods($class) |
65
|
|
|
{ |
66
|
|
|
$info = new ReflectionClass($class); |
67
|
|
|
|
68
|
|
|
$methods = []; |
69
|
|
|
foreach ($info->getMethods(ReflectionProperty::IS_PUBLIC) as $method) |
70
|
|
|
{ |
71
|
|
|
$methods[] = $method->name; |
72
|
|
|
} |
73
|
|
|
sort($methods); |
74
|
|
|
return $methods; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Iterate over *public* class properties |
79
|
|
|
* @param string $class |
80
|
|
|
* @return string[] |
81
|
|
|
*/ |
82
|
|
|
public static function properties($class) |
83
|
|
|
{ |
84
|
|
|
$info = new ReflectionClass($class); |
85
|
|
|
|
86
|
|
|
$properties = []; |
87
|
|
|
foreach ($info->getProperties(ReflectionProperty::IS_PUBLIC) as $property) |
88
|
|
|
{ |
89
|
|
|
$properties[] = $property->name; |
90
|
|
|
} |
91
|
|
|
sort($properties); |
92
|
|
|
return $properties; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|