PluginProbe
Packeta / 1.6.1
Packeta v1.6.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / deps / nette / php-generator / src / PhpGenerator / Closure.php

Closure.php in Packeta 1.6.1, at deps/nette/php-generator/src/PhpGenerator/Closure.php

59 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 declare (strict_types=1);
8 namespace Packetery\Nette\PhpGenerator;
9
10 use Packetery\Nette;
11 /**
12 * Closure.
13 *
14 * @property string $body
15 */
16 final class Closure
17 {
18 use \Packetery\Nette\SmartObject;
19 use Traits\FunctionLike;
20 use Traits\AttributeAware;
21 /** @var Parameter[] */
22 private $uses = [];
23 public static function from(\Closure $closure) : self
24 {
25 return (new Factory())->fromFunctionReflection(new \ReflectionFunction($closure));
26 }
27 public function __toString() : string
28 {
29 try {
30 return (new Printer())->printClosure($this);
31 } catch (\Throwable $e) {
32 if (\PHP_VERSION_ID >= 70400) {
33 throw $e;
34 }
35 \trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", \E_USER_ERROR);
36 return '';
37 }
38 }
39 /**
40 * @param Parameter[] $uses
41 * @return static
42 */
43 public function setUses(array $uses) : self
44 {
45 (function (Parameter ...$uses) {
46 })(...$uses);
47 $this->uses = $uses;
48 return $this;
49 }
50 public function getUses() : array
51 {
52 return $this->uses;
53 }
54 public function addUse(string $name) : Parameter
55 {
56 return $this->uses[] = new Parameter($name);
57 }
58 }
59