Lines
57.14%
8 / 14
Methods
45.45%
5 / 11
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| env | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | ||
| getLucentVersion | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| registerRoutes | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| registerCommands | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| registerGlobalMiddlewares | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| handleHttpRequest | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| execute | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| container | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| make | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| call | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| exceptions | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| 20 | class App | |
| 21 | { | |
| 22 | public static function env(string $key, $default = null) | |
| 23 | { | |
| 24 | ||
| 25 | $env = Application::getInstance()->getEnv(); | |
| 26 | ||
| 27 | if (array_key_exists($key, $env)) { | |
| 28 | return trim($env[$key]); | |
| 29 | } else { | |
| 30 | return $default; | |
| 31 | } | |
| 32 | } | |
| 33 | ||
| 34 | public static function getLucentVersion(): string | |
| 35 | { | |
| 36 | return VERSION; | |
| 37 | } | |
| 38 | ||
| 39 | ||
| 40 | public static function registerRoutes(string $routeFile): void | |
| 41 | { | |
| 42 | Application::getInstance()->loadRoutes($routeFile); | |
| 43 | } | |
| 44 | ||
| 45 | public static function registerCommands(string $commandFile): void | |
| 46 | { | |
| 47 | Application::getInstance()->loadCommands($commandFile); | |
| 48 | } | |
| 49 | ||
| 50 | public static function registerGlobalMiddlewares(MiddlewareInterface|string $middleware): void | |
| 51 | { | |
| 52 | Application::getInstance()->registerGlobalMiddleware($middleware); | |
| 53 | } | |
| 54 | ||
| 55 | public static function handleHttpRequest(ServerRequestInterface $request): ResponseInterface | |
| 56 | { | |
| 57 | return Application::getInstance()->handleHttpRequest($request); | |
| 58 | } | |
| 59 | ||
| 60 | public static function execute(): string | |
| 61 | { | |
| 62 | return Application::getInstance()->executeHttpRequest(); | |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * Get the application's dependency injection container. | |
| 67 | * | |
| 68 | * The container is scoped to the {@see Application} singleton, so this | |
| 69 | * always returns the same instance for the lifetime of the application. | |
| 70 | * | |
| 71 | * ```php | |
| 72 | * $container = App::container(); | |
| 73 | * $container->singleton(MyService::class); | |
| 74 | * $service = $container->get(MyService::class); | |
| 75 | * ``` | |
| 76 | * | |
| 77 | * @return Container The PSR-11 service container | |
| 78 | */ | |
| 79 | public static function container(): Container | |
| 80 | { | |
| 81 | return Application::getInstance()->container(); | |
| 82 | } | |
| 83 | ||
| 84 | /** | |
| 85 | * Resolve a service from the container, autowiring its dependencies. | |
| 86 | * | |
| 87 | * ```php | |
| 88 | * $service = App::make(MyService::class); | |
| 89 | * ``` | |
| 90 | * | |
| 91 | * @param string $abstract Identifier (class name or alias) to resolve | |
| 92 | * @param array $parameters Explicit values keyed by constructor parameter name | |
| 93 | * @return mixed The resolved entry | |
| 94 | */ | |
| 95 | public static function make(string $abstract, array $parameters = []): mixed | |
| 96 | { | |
| 97 | return Application::getInstance()->make($abstract, $parameters); | |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * Invoke a callable, resolving its parameters from the container. | |
| 102 | * | |
| 103 | * ```php | |
| 104 | * $result = App::call([$controller, 'show'], ['id' => 5]); | |
| 105 | * ``` | |
| 106 | * | |
| 107 | * @param callable|string|array $callback The callable to invoke | |
| 108 | * @param array $parameters Explicit values keyed by parameter name | |
| 109 | * @param string|null $defaultMethod Method to invoke when $callback is an invokable class string | |
| 110 | * @return mixed The callable's return value | |
| 111 | */ | |
| 112 | public static function call(callable|string|array $callback, array $parameters = [], ?string $defaultMethod = null): mixed | |
| 113 | { | |
| 114 | return Application::getInstance()->call($callback, $parameters, $defaultMethod); | |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * Get the shared exception manager. | |
| 119 | * | |
| 120 | * ```php | |
| 121 | * App::exceptions()->render(function (HttpException $e) { | |
| 122 | * // Return a Response for any HttpException, or null to fall through. | |
| 123 | * return null; | |
| 124 | * }); | |
| 125 | * ``` | |
| 126 | * | |
| 127 | * @return \Lucent\Http\Exceptions\Exceptions The shared exception manager | |
| 128 | */ | |
| 129 | public static function exceptions(): \Lucent\Http\Exceptions\Exceptions | |
| 130 | { | |
| 131 | return Application::getInstance()->exceptions(); | |
| 132 | } | |
| 133 | } |