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