1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette\PhpGenerator;
9:
10: use Nette;
11:
12:
13: /**
14: * Global function.
15: *
16: * @property string $body
17: */
18: class GlobalFunction
19: {
20: use Nette\SmartObject;
21: use Traits\FunctionLike;
22: use Traits\NameAware;
23: use Traits\CommentAware;
24:
25: /**
26: * @param string
27: * @return static
28: */
29: public static function from($function)
30: {
31: return (new Factory)->fromFunctionReflection(new \ReflectionFunction($function));
32: }
33:
34:
35: /**
36: * @return string PHP code
37: */
38: public function __toString()
39: {
40: return Helpers::formatDocComment($this->comment . "\n")
41: . 'function '
42: . ($this->returnReference ? '&' : '')
43: . $this->name
44: . $this->parametersToString()
45: . $this->returnTypeToString()
46: . "\n{\n" . Nette\Utils\Strings::indent(ltrim(rtrim($this->body) . "\n"), 1) . '}';
47: }
48: }
49: