-
Notifications
You must be signed in to change notification settings - Fork 23
/
leevel
56 lines (47 loc) · 1.57 KB
/
leevel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env php
<?php
declare(strict_types=1);
use App\Infra\Exceptions\Runtime;
use App\Infra\Kernel\Kernel;
use App\Infra\Kernel\KernelConsole;
use Leevel\Di\Container;
use Leevel\Di\IContainer;
use Leevel\Kernel\App;
use Leevel\Kernel\IApp;
use Leevel\Kernel\Exceptions\IRuntime;
use Leevel\Kernel\IKernel;
use Leevel\Kernel\IKernelConsole;
use Symfony\Component\Console\Input\ArgvInput;
// 加载 Composer
require __DIR__.'/vendor/autoload.php';
// 创建应用
// 注册应用基础服务
$container = Container::singletons();
$container->singleton(IContainer::class, $container);
// 应用路径
$path = str_starts_with(__DIR__, 'phar://')
? Phar::running()
: realpath(__DIR__);
$container->singleton('app', $app = new App($container, $path));
// PHAR 缓存路径不能是 phar 内部路径,因为 phar 内部路径是只读的
if (str_starts_with(__DIR__, 'phar://')) {
$app->setStoragePath(substr(dirname(Phar::running()), 7).\DIRECTORY_SEPARATOR.'storage');
}
$container->alias('app', [IApp::class, App::class]);
$container->singleton(IKernel::class, Kernel::class);
$container->singleton(IKernelConsole::class, KernelConsole::class);
$container->singleton(IRuntime::class, Runtime::class);
// 载入环境
$input = new ArgvInput();
if ($input->hasParameterOption('--env')) {
$env = $input->getParameterOption('--env');
} else {
$env = 'env';
}
putenv('RUNTIME_ENVIRONMENT='.$env);
// 执行应用
// 根据内核调度请求返回响应
$kernel = $container->make(IKernelConsole::class);
$status = $kernel->handle();
$kernel->terminate($status);
exit($status);