1 | <?php |
||
9 | trait DynamicObjectTrait |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $methods = []; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $properties = []; |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $flags = []; |
||
25 | |||
26 | /** |
||
27 | * Add a method identified by the given name. |
||
28 | * |
||
29 | * @param string $name |
||
30 | * @param callable $method the body of the method |
||
31 | * @return $this |
||
32 | */ |
||
33 | public function addMethod($name, callable $method) |
||
39 | |||
40 | /** |
||
41 | * Adds a lazy property identified by the given name. The property |
||
42 | * is lazy because it is not evaluated until asked for via __get(). |
||
43 | * |
||
44 | * @param string $name |
||
45 | * @param callable $factory |
||
46 | * @param bool $memoize |
||
47 | * @return $this |
||
48 | */ |
||
49 | public function addProperty($name, callable $factory, $memoize = false) |
||
55 | |||
56 | /** |
||
57 | * A simple mechanism for storing arbitrary flags. Flags are useful |
||
58 | * for tweaking behavior based on their presence. |
||
59 | * |
||
60 | * @return $this|mixed |
||
61 | */ |
||
62 | public function flag() |
||
77 | |||
78 | /** |
||
79 | * Reset flags. Flags are generally cleared after an Assertion is made. |
||
80 | * |
||
81 | * @return $this |
||
82 | */ |
||
83 | public function clearFlags() |
||
89 | } |
||
90 |