-
-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathClosure.php
More file actions
61 lines (44 loc) · 993 Bytes
/
Closure.php
File metadata and controls
61 lines (44 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\PhpGenerator;
use Nette;
/**
* Closure.
*/
final class Closure extends FunctionLike
{
use Nette\SmartObject;
use Traits\AttributeAware;
/** @var Parameter[] */
private array $uses = [];
public static function from(\Closure $closure): self
{
return (new Factory)->fromFunctionReflection(new \ReflectionFunction($closure));
}
public function __toString(): string
{
return (new Printer)->printClosure($this);
}
/**
* @param Parameter[] $uses
*/
public function setUses(array $uses): static
{
(function (Parameter ...$uses) {})(...$uses);
$this->uses = $uses;
return $this;
}
/** @return Parameter[] */
public function getUses(): array
{
return $this->uses;
}
public function addUse(string $name): Parameter
{
return $this->uses[] = new Parameter($name);
}
}