1
1
#!/usr/bin/env php
2
2
<?php
3
+ // bin/console
3
4
4
5
use App \Kernel ;
5
6
use Symfony \Bundle \FrameworkBundle \Console \Application ;
6
- use Symfony \Component \Console \Input \ArgvInput ;
7
- use Symfony \Component \Dotenv \Dotenv ;
8
- use Symfony \Component \ErrorHandler \Debug ;
9
7
10
- if (!in_array (PHP_SAPI , ['cli ' , 'phpdbg ' , 'embed ' ], true )) {
11
- echo 'Warning: The console should be invoked via the CLI version of PHP, not the ' .PHP_SAPI .' SAPI ' .PHP_EOL ;
12
- }
8
+ require_once dirname (__DIR__ ).'/vendor/autoload_runtime.php ' ;
13
9
14
- set_time_limit (0 );
10
+ return function (array $ context ): Application {
11
+ $ kernel = new Kernel ($ context ['APP_ENV ' ], (bool ) $ context ['APP_DEBUG ' ]);
15
12
16
- require dirname (__DIR__ ).'/vendor/autoload.php ' ;
17
-
18
- if (!class_exists (Application::class) || !class_exists (Dotenv::class)) {
19
- throw new LogicException ('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies. ' );
20
- }
21
-
22
- $ input = new ArgvInput ();
23
- if (null !== $ env = $ input ->getParameterOption (['--env ' , '-e ' ], null , true )) {
24
- putenv ('APP_ENV= ' .$ _SERVER ['APP_ENV ' ] = $ _ENV ['APP_ENV ' ] = $ env );
25
- }
26
-
27
- if ($ input ->hasParameterOption ('--no-debug ' , true )) {
28
- putenv ('APP_DEBUG= ' .$ _SERVER ['APP_DEBUG ' ] = $ _ENV ['APP_DEBUG ' ] = '0 ' );
29
- }
30
-
31
- if ( file_exists (dirname (__DIR__ ).'/.env ' ) ) {
32
- (new Dotenv ())->bootEnv (dirname (__DIR__ ).'/.env ' );
33
- } else {
34
- $ _SERVER ['APP_DEBUG ' ] = $ _SERVER ['APP_DEBUG ' ] ?? $ _ENV ['APP_DEBUG ' ] ?? 'prod ' !== $ _SERVER ['APP_ENV ' ];
35
- }
36
-
37
- if ($ _SERVER ['APP_DEBUG ' ]) {
38
- umask (0000 );
39
-
40
- if (class_exists (Debug::class)) {
41
- Debug::enable ();
42
- }
43
- }
44
-
45
- $ kernel = new Kernel ($ _SERVER ['APP_ENV ' ], (bool ) $ _SERVER ['APP_DEBUG ' ]);
46
- $ application = new Application ($ kernel );
47
- $ application ->run ($ input );
13
+ // returning an "Application" makes the Runtime run a Console
14
+ // application instead of the HTTP Kernel
15
+ return new Application ($ kernel );
16
+ };
0 commit comments