-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathApplication.php
More file actions
64 lines (55 loc) · 1.66 KB
/
Copy pathApplication.php
File metadata and controls
64 lines (55 loc) · 1.66 KB
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
57
58
59
60
61
62
63
64
<?php
namespace App\cli;
use App\utils;
use Minz\Request;
use Minz\Response;
/**
* This is the central class for the CLI. It is called from the cli file.
*
* @phpstan-import-type ResponseReturnable from Response
*
* @author Marien Fressinaud <dev@marienfressinaud.fr>
* @license http://www.gnu.org/licenses/agpl-3.0.en.html AGPL
*/
class Application
{
/**
* Setup the Engine.
*/
public function __construct()
{
$router = \App\Router::loadCli();
\Minz\Engine::init($router, [
'start_session' => false,
'not_found_template' => 'cli/not_found.txt',
'internal_server_error_template' => 'cli/internal_server_error.txt',
'controller_namespace' => '\\App\\cli',
]);
}
/**
* Execute a request.
*
* @return ResponseReturnable
*/
public function run(Request $request): mixed
{
$cli_locale = \App\Configuration::$application['cli_locale'];
if ($cli_locale) {
utils\Locale::setCurrentLocale($cli_locale);
}
$bin = $request->parameters->getString('bin', 'php cli');
$bin = $bin === 'cli' ? 'php cli' : $bin;
$command = $request->path();
$command = trim(str_replace('/', ' ', $command));
\Minz\Template\Twig::addGlobals([
'app' => [
'brand' => \App\Configuration::$application['brand'],
'version' => \App\Configuration::$application['version'],
'user_agent' => utils\UserAgent::get(),
'bin' => $bin,
'command' => $command,
],
]);
return \Minz\Engine::run($request);
}
}