File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 9
9
10
10
namespace Toolkit \Stdlib \Helper ;
11
11
12
+ use Closure ;
13
+ use Generator ;
14
+ use ReflectionClass ;
15
+ use ReflectionException ;
12
16
use RuntimeException ;
13
17
use Toolkit \Stdlib \Obj \ObjectHelper ;
14
18
use function array_sum ;
38
42
*/
39
43
class PhpHelper
40
44
{
45
+ /**
46
+ * @var ReflectionClass[]
47
+ */
48
+ private static $ reflects = [];
49
+
50
+ /**
51
+ * @param string $class
52
+ *
53
+ * @return ReflectionClass
54
+ * @throws ReflectionException
55
+ */
56
+ public static function reflectClass (string $ class ): ReflectionClass
57
+ {
58
+ if (!isset (self ::$ reflects [$ class ])) {
59
+ self ::$ reflects [$ class ] = new ReflectionClass ($ class );
60
+ }
61
+
62
+ return self ::$ reflects [$ class ];
63
+ }
64
+
65
+ /**
66
+ * @param ReflectionClass $reflectClass
67
+ * @param int $flags eg: \ReflectionMethod::IS_PUBLIC
68
+ * @param Closure|null $nameFilter
69
+ *
70
+ * @return Generator
71
+ */
72
+ public static function reflectMethods (ReflectionClass $ reflectClass , int $ flags = 0 , Closure $ nameFilter = null ): ?Generator
73
+ {
74
+ foreach ($ reflectClass ->getMethods ($ flags ) as $ m ) {
75
+ $ mName = $ m ->getName ();
76
+
77
+ if ($ nameFilter && false === $ nameFilter ($ mName )) {
78
+ continue ;
79
+ }
80
+
81
+ yield $ mName => $ m ;
82
+ }
83
+ }
84
+
41
85
/**
42
86
* @param $value
43
87
*
You can’t perform that action at this time.
0 commit comments