File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,16 @@ public function fromFunctionReflection(\ReflectionFunction $from)
101101 }
102102
103103
104+ /** @return Method|GlobalFunction|Closure */
105+ public function fromCallable (callable $ from )
106+ {
107+ $ ref = Nette \Utils \Callback::toReflection ($ from );
108+ return $ ref instanceof \ReflectionMethod
109+ ? self ::fromMethodReflection ($ ref )
110+ : self ::fromFunctionReflection ($ ref );
111+ }
112+
113+
104114 public function fromParameterReflection (\ReflectionParameter $ from ): Parameter
105115 {
106116 $ param = new Parameter ($ from ->getName ());
Original file line number Diff line number Diff line change @@ -38,3 +38,13 @@ Assert::same('trim', $res->getName());
3838
3939$ res = $ factory ->fromFunctionReflection (new \ReflectionFunction (function () {}));
4040Assert::type (Nette \PhpGenerator \Closure::class, $ res );
41+
42+
43+ $ res = $ factory ->fromCallable ('trim ' );
44+ Assert::type (Nette \PhpGenerator \GlobalFunction::class, $ res );
45+ Assert::same ('trim ' , $ res ->getName ());
46+
47+
48+ $ res = $ factory ->fromCallable ([new ReflectionClass (stdClass::class), 'getName ' ]);
49+ Assert::type (Nette \PhpGenerator \Method::class, $ res );
50+ Assert::same ('getName ' , $ res ->getName ());
You can’t perform that action at this time.
0 commit comments