vanilla /
garden-container
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * @author Todd Burry <[email protected]> |
||
| 4 | * @copyright 2009-2017 Vanilla Forums Inc. |
||
| 5 | * @license MIT |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace Garden\Container; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * A reference that uses a callback to resolve. |
||
| 12 | */ |
||
| 13 | class Callback implements ReferenceInterface { |
||
| 14 | /** |
||
| 15 | * @var callable $callback |
||
| 16 | */ |
||
| 17 | private $callback; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Construct a new instance of the {@link Callback} class. |
||
| 21 | * |
||
| 22 | * @param callable $callback The callback of the reference. |
||
| 23 | */ |
||
| 24 | 2 | public function __construct(callable $callback) { |
|
| 25 | 2 | $this->callback = $callback; |
|
| 26 | 2 | } |
|
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | 1 | public function resolve(Container $container, $instance = null) { |
|
| 32 | 1 | return call_user_func($this->callback, $container, $instance); |
|
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Get the callback. |
||
| 37 | * |
||
| 38 | * @return callable Returns the callback. |
||
| 39 | */ |
||
| 40 | 1 | public function getCallback() { |
|
| 41 | 1 | return $this->callback; |
|
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Set the callback. |
||
| 46 | * |
||
| 47 | * @param callable $callback The new callback to set. |
||
| 48 | * @return Callback Returns `$this` for fluent calls. |
||
| 49 | */ |
||
| 50 | 1 | public function setCallback($callback) { |
|
| 51 | 1 | $this->callback = $callback; |
|
| 52 | 1 | return $this; |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 53 | } |
||
| 54 | } |
||
| 55 |