| 1 | <?php |
||
| 7 | class ContextBag |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var ContextBag |
||
| 11 | */ |
||
| 12 | protected $parent; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | protected $stash = []; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param ContextBag|null $parent |
||
| 21 | */ |
||
| 22 | 123 | public function __construct(ContextBag $parent = null) |
|
| 26 | |||
| 27 | /** |
||
| 28 | * Searches for value of $key in this context and the parent context. |
||
| 29 | * Returns the value if found, throws an exception it's not found. |
||
| 30 | * |
||
| 31 | * @param string $key |
||
| 32 | * |
||
| 33 | * @throws OutOfBoundsException |
||
| 34 | * @return mixed |
||
| 35 | */ |
||
| 36 | 6 | public function get($key) |
|
| 45 | |||
| 46 | /** |
||
| 47 | * Searches for value of $key in this context and the parent context. |
||
| 48 | * Returns the value if found, null if not found. |
||
| 49 | * |
||
| 50 | * @param string $key |
||
| 51 | * |
||
| 52 | * @return mixed |
||
| 53 | */ |
||
| 54 | 7 | public function tryGet($key) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @param string $key |
||
| 69 | * @param mixed $value |
||
| 70 | */ |
||
| 71 | 5 | public function set($key, $value) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * @param string $key |
||
| 78 | */ |
||
| 79 | 1 | public function remove($key) |
|
| 85 | } |
||
| 86 |