截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GlobalFunction.php 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * This file is part of the Nette Framework (https://nette.org)
  4. * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
  5. */
  6. declare(strict_types=1);
  7. namespace Nette\PhpGenerator;
  8. use Nette;
  9. /**
  10. * Global function.
  11. *
  12. * @property string $body
  13. */
  14. final class GlobalFunction
  15. {
  16. use Nette\SmartObject;
  17. use Traits\FunctionLike;
  18. use Traits\NameAware;
  19. use Traits\CommentAware;
  20. use Traits\AttributeAware;
  21. public static function from(string $function): self
  22. {
  23. return (new Factory)->fromFunctionReflection(new \ReflectionFunction($function));
  24. }
  25. public static function withBodyFrom(string $function): self
  26. {
  27. return (new Factory)->fromFunctionReflection(new \ReflectionFunction($function), true);
  28. }
  29. public function __toString(): string
  30. {
  31. try {
  32. return (new Printer)->printFunction($this);
  33. } catch (\Throwable $e) {
  34. if (PHP_VERSION_ID >= 70400) {
  35. throw $e;
  36. }
  37. trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR);
  38. return '';
  39. }
  40. }
  41. }