| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBoards\Framework\Foundation; |
| 4 |
|
| 5 |
|
| 6 |
class App |
| 7 |
{ |
| 8 |
/** |
| 9 |
* Application instance |
| 10 |
* |
| 11 |
* @var FluentBoards\Framework\Foundation\Application |
| 12 |
*/ |
| 13 |
protected static $instance = null; |
| 14 |
|
| 15 |
/** |
| 16 |
* Set the application instance |
| 17 |
* |
| 18 |
* @param FluentBoards\Framework\Foundation\Application $app |
| 19 |
*/ |
| 20 |
public static function setInstance($app) |
| 21 |
{ |
| 22 |
static::$instance = $app; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Get the application instance |
| 27 |
* |
| 28 |
* @param string $module The binding/key name for a component. |
| 29 |
* @param array $parameters constructor dependencies if any. |
| 30 |
* @return FluentBoards\Framework\Foundation\Application|mixed |
| 31 |
*/ |
| 32 |
public static function getInstance($module = null, $parameters = []) |
| 33 |
{ |
| 34 |
if ($module) { |
| 35 |
return static::$instance->make($module, $parameters); |
| 36 |
} |
| 37 |
|
| 38 |
return static::$instance; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Retrive a component from the container |
| 43 |
* |
| 44 |
* @param string $module The binding/key name for a component. |
| 45 |
* @param array $parameters constructor dependencies if any. |
| 46 |
* @return FluentBoards\Framework\Foundation\Application|mixed |
| 47 |
*/ |
| 48 |
public static function make($module = null, $parameters = []) |
| 49 |
{ |
| 50 |
return static::getInstance($module, $parameters); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Handle dynamic method calls |
| 55 |
* |
| 56 |
* @param string $method |
| 57 |
* @param array $params |
| 58 |
* @return mixed |
| 59 |
*/ |
| 60 |
public static function __callStatic($method, $params) |
| 61 |
{ |
| 62 |
if (method_exists(static::$instance, $method)) { |
| 63 |
return static::$instance->{$method}(...$params); |
| 64 |
} |
| 65 |
|
| 66 |
return static::getInstance($method, ...$params); |
| 67 |
} |
| 68 |
} |
| 69 |
|