diff --git a/src/PhpGenerator/GlobalFunction.php b/src/PhpGenerator/GlobalFunction.php index 3a6a5a3b..f25689a2 100644 --- a/src/PhpGenerator/GlobalFunction.php +++ b/src/PhpGenerator/GlobalFunction.php @@ -9,6 +9,8 @@ namespace Nette\PhpGenerator; +use Nette; + /** * Global function. @@ -20,9 +22,9 @@ final class GlobalFunction use Traits\CommentAware; use Traits\AttributeAware; - public static function from(string $function, bool $withBody = false): self + public static function from(string|\Closure $function, bool $withBody = false): self { - return (new Factory)->fromFunctionReflection(new \ReflectionFunction($function), $withBody); + return (new Factory)->fromFunctionReflection(Nette\Utils\Callback::toReflection($function), $withBody); } diff --git a/src/PhpGenerator/Method.php b/src/PhpGenerator/Method.php index 5c10fec4..b414f966 100644 --- a/src/PhpGenerator/Method.php +++ b/src/PhpGenerator/Method.php @@ -28,7 +28,7 @@ final class Method private bool $abstract = false; - public static function from(string|array $method): static + public static function from(string|array|\Closure $method): static { return (new Factory)->fromMethodReflection(Nette\Utils\Callback::toReflection($method)); } diff --git a/tests/PhpGenerator/GlobalFunction.from.81.phpt b/tests/PhpGenerator/GlobalFunction.from.81.phpt new file mode 100644 index 00000000..10cab3ff --- /dev/null +++ b/tests/PhpGenerator/GlobalFunction.from.81.phpt @@ -0,0 +1,36 @@ +