| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\Framework\Foundation; |
| 4 |
|
| 5 |
use FluentSupport\Framework\Container\Contracts\BindingResolutionException; |
| 6 |
|
| 7 |
/** |
| 8 |
* @method static db(); |
| 9 |
* @method static view(); |
| 10 |
* @method static events(); |
| 11 |
* @method static config(); |
| 12 |
* @method static request(); |
| 13 |
* @method static response(); |
| 14 |
* @method static encrypter(); |
| 15 |
* @method static validator(); |
| 16 |
*/ |
| 17 |
|
| 18 |
class App |
| 19 |
{ |
| 20 |
/** |
| 21 |
* Application instance |
| 22 |
* |
| 23 |
* @var \FluentSupport\Framework\Foundation\Application |
| 24 |
*/ |
| 25 |
protected static $instance = null; |
| 26 |
|
| 27 |
/** |
| 28 |
* Set the application instance |
| 29 |
* |
| 30 |
* @param \FluentSupport\Framework\Foundation\Application $app |
| 31 |
*/ |
| 32 |
public static function setInstance($app) |
| 33 |
{ |
| 34 |
static::$instance = $app; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Get the application instance |
| 39 |
* |
| 40 |
* @param string $module The binding/key name for a component. |
| 41 |
* @param array $parameters constructor dependencies if any. |
| 42 |
* @return \FluentSupport\Framework\Foundation\Application|mixed |
| 43 |
*/ |
| 44 |
public static function getInstance($module = null, $parameters = []) |
| 45 |
{ |
| 46 |
if ($module) { |
| 47 |
return static::$instance->make($module, $parameters); |
| 48 |
} |
| 49 |
|
| 50 |
return static::$instance; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Retrive a component from the container |
| 55 |
* |
| 56 |
* @param string $module The binding/key name for a component. |
| 57 |
* @param array $parameters constructor dependencies if any. |
| 58 |
* @return \FluentSupport\Framework\Foundation\Application|mixed |
| 59 |
*/ |
| 60 |
public static function make($module = null, $parameters = []) |
| 61 |
{ |
| 62 |
return static::getInstance($module, $parameters); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Handle dynamic method calls |
| 67 |
* |
| 68 |
* @param string $method |
| 69 |
* @param array $params |
| 70 |
* @return mixed |
| 71 |
*/ |
| 72 |
public static function __callStatic($method, $params) |
| 73 |
{ |
| 74 |
if ($method === 'support') { |
| 75 |
$param = array_splice($params, 0, 1); |
| 76 |
return static::getInstance( |
| 77 |
'Support.' . implode('.', $param), ...$params |
| 78 |
); |
| 79 |
} |
| 80 |
|
| 81 |
if (method_exists(static::$instance, $method)) { |
| 82 |
return static::$instance->{$method}(...$params); |
| 83 |
} |
| 84 |
|
| 85 |
return static::getInstance($method, ...$params); |
| 86 |
} |
| 87 |
} |
| 88 |
|