carno-php /
web
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * HTTP server routing |
||
| 4 | * User: moyo |
||
| 5 | * Date: 2018/5/29 |
||
| 6 | * Time: 12:03 PM |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace Carno\Web\Components; |
||
| 10 | |||
| 11 | use Carno\Console\Component; |
||
| 12 | use Carno\Console\Contracts\Application; |
||
| 13 | use Carno\Console\Contracts\Bootable; |
||
| 14 | use Carno\Container\DI; |
||
| 15 | use Carno\Web\Dispatcher; |
||
| 16 | use Carno\Web\Policy\Inspector; |
||
| 17 | use Carno\Web\Router\Initializer; |
||
| 18 | use Carno\Web\Router\Records; |
||
| 19 | |||
| 20 | class Routing extends Component implements Bootable |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @param Application $app |
||
| 24 | */ |
||
| 25 | public function starting(Application $app) : void |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var Records $rec |
||
| 29 | * @var Inspector $isp |
||
| 30 | * @var Dispatcher $dsp |
||
| 31 | */ |
||
| 32 | |||
| 33 | DI::set(Records::class, $rec = DI::object(Records::class)); |
||
| 34 | DI::set(Inspector::class, $isp = DI::object(Inspector::class)); |
||
| 35 | DI::set(Dispatcher::class, $dsp = DI::object(Dispatcher::class)); |
||
| 36 | |||
| 37 | // starting works |
||
| 38 | |||
| 39 | $app->starting()->add(static function () use ($rec, $isp, $dsp) { |
||
| 40 | // routes parsing |
||
| 41 | if (defined('CWD') && is_file($rf = CWD . '/routes.php')) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 42 | (new Initializer)->loads(...(array) include $rf); |
||
| 43 | } |
||
| 44 | |||
| 45 | // policing init |
||
| 46 | $dsp->policing($isp); |
||
| 47 | |||
| 48 | // dispatcher init |
||
| 49 | $dsp->dispatched($rec->dispatcher()); |
||
| 50 | }); |
||
| 51 | } |
||
| 52 | } |
||
| 53 |