-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·47 lines (36 loc) · 1.59 KB
/
index.php
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
#!/usr/bin/env php
<?php
// include()/include_once()/require()/require_once()
include __DIR__ . '/vendor/autoload.php'; // composer
/*spl_autoload_register(function () {
echo 'spl_autoload_register' . PHP_EOL;
});*/
$app = new \App\Illuminate\Foundation\Application(__DIR__); // container
// bind console kernel service, interface::class format
$app->singleton(
\Illuminate\Contracts\Console\Kernel::class,
\App\Cli\Commands\Kernel::class
);
// bind exceptions handler service, interface::class format
$app->singleton(\Illuminate\Contracts\Debug\ExceptionHandler::class,
\App\Illuminate\Foundation\Exceptions\Handler::class
);
/** @var $kernel \App\Illuminate\Foundation\Console\Kernel */
$kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class); // dependency injection
// register \Illuminate\Console\Events\ArtisanStarting::class event listener
$app['events']->listen(\Illuminate\Console\Events\ArtisanStarting::class, function (\Illuminate\Console\Events\ArtisanStarting $event) {
echo 'Application name is ' . $event->artisan->getName() . ', and the version is ' . $event->artisan->getVersion() . PHP_EOL;
});
// demo for 'cli:build_laravel' command dependency injection
// $app->events->listen()
$app['events']->listen('cli:build_laravel', function (\App\Illuminate\Foundation\Application $app) {
$app->terminating(function () use ($app) {
echo $app->version() . PHP_EOL;
});
});
$status = $kernel->handle(
$input = new \Symfony\Component\Console\Input\ArgvInput(),
new \Symfony\Component\Console\Output\ConsoleOutput()
);
$kernel->terminate($input, $status);
exit($status);