Commit | Line | Data |
---|---|---|
4bcd4c62 TO |
1 | <?php |
2 | namespace Civi\Setup; | |
3 | ||
4 | class BasicRunner { | |
5 | ||
6 | /** | |
7 | * Execute the controller and display the output. | |
8 | * | |
9 | * Note: This is really just an example which handles input and output using | |
10 | * stock PHP variables and functions. Depending on the environment, | |
11 | * it may be easier to work directly with `getCtrl()->run(...)` which | |
12 | * handles inputs/outputs in a more abstract fashion. | |
13 | * | |
30bef769 | 14 | * @param \Civi\Setup\UI\SetupController $ctrl |
4bcd4c62 TO |
15 | * A web controller. |
16 | */ | |
17 | public static function run($ctrl) { | |
18 | $method = $_SERVER['REQUEST_METHOD']; | |
30bef769 TO |
19 | |
20 | /** @var \Civi\Setup\UI\SetupResponse $response */ | |
21 | $response = $ctrl->run($method, ($method === 'GET' ? $_GET : $_POST)); | |
22 | ||
23 | self::send($ctrl, $response); | |
24 | } | |
25 | ||
26 | /** | |
27 | * @param \Civi\Setup\UI\SetupController $ctrl | |
28 | * @param \Civi\Setup\UI\SetupResponse $response | |
29 | */ | |
30 | public static function send($ctrl, $response) { | |
31 | http_response_code($response->code); | |
32 | foreach ($response->headers as $k => $v) { | |
4bcd4c62 TO |
33 | header("$k: $v"); |
34 | } | |
30bef769 TO |
35 | |
36 | /** @var \Civi\Setup\Model $model */ | |
37 | $model = \Civi\Setup::instance()->getModel(); | |
38 | ||
39 | if ($response->isComplete) { | |
40 | echo $response->body; | |
41 | } | |
42 | else { | |
43 | $pageVars = [ | |
44 | 'pageAssets' => $response->assets, | |
45 | 'pageTitle' => $response->title, | |
46 | 'pageBody' => $response->body, | |
47 | 'shortLangCode' => \CRM_Core_I18n_PseudoConstant::shortForLong($model->lang), | |
48 | 'textDirection' => (\CRM_Core_I18n::isLanguageRTL($model->lang) ? 'rtl' : 'ltr'), | |
49 | ]; | |
50 | ||
51 | echo $ctrl->render($ctrl->getResourcePath('page.tpl.php'), $pageVars); | |
52 | } | |
4bcd4c62 TO |
53 | } |
54 | ||
55 | } |