| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\Framework\Foundation; |
| 4 |
|
| 5 |
class HookReference |
| 6 |
{ |
| 7 |
/** |
| 8 |
* $ref reference for any hook |
| 9 |
* @var null |
| 10 |
*/ |
| 11 |
private $ref = null; |
| 12 |
|
| 13 |
/** |
| 14 |
* construct the instance |
| 15 |
* @param Application $app |
| 16 |
* @param reference $ref |
| 17 |
* @param string $key |
| 18 |
*/ |
| 19 |
public function __construct(Application $app, $ref, $key = null) |
| 20 |
{ |
| 21 |
$this->app = $app; |
| 22 |
$this->ref = $ref; |
| 23 |
$this->key = $key; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Save the hook's handler reference |
| 28 |
* @param string $key |
| 29 |
* @return reference |
| 30 |
*/ |
| 31 |
public function saveReference($key = null) |
| 32 |
{ |
| 33 |
// TODO: Add exception |
| 34 |
$this->app->bindInstance($key ? $key : $this->key, $this->ref); |
| 35 |
|
| 36 |
return $this->ref; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Get the reference |
| 41 |
* @return reference |
| 42 |
*/ |
| 43 |
public function reference() |
| 44 |
{ |
| 45 |
return $this->ref; |
| 46 |
} |
| 47 |
} |