HexMakina /
kadro
| 1 | <?php |
||
| 2 | |||
| 3 | namespace HexMakina\kadro; |
||
| 4 | |||
| 5 | use HexMakina\Debugger\Debugger; |
||
| 6 | use HexMakina\LeMarchand\LeMarchand; |
||
| 7 | use HexMakina\Lezer\Lezer; |
||
| 8 | |||
| 9 | class kadro |
||
| 10 | { |
||
| 11 | private static $box; // PSR-11 Service Locator, ugly until DI is ready |
||
| 12 | |||
| 13 | |||
| 14 | public static function init($settings) |
||
| 15 | { |
||
| 16 | new Debugger(); |
||
| 17 | |||
| 18 | self::$box = LeMarchand::box($settings); |
||
| 19 | |||
| 20 | //-- error & logs & messages |
||
| 21 | error_reporting(E_ALL); |
||
| 22 | ini_set('display_errors', PRODUCTION ? 0 : 1); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 23 | |||
| 24 | $log_laddy = self::$box->get('Psr\Log\LoggerInterface'); |
||
| 25 | |||
| 26 | |||
| 27 | //-- router |
||
| 28 | $router = self::$box->get('HexMakina\BlackBox\RouterInterface'); |
||
| 29 | $router->addRoutes(require(__DIR__.'/routes.php')); |
||
| 30 | |||
| 31 | //-- session |
||
| 32 | $StateAgent = self::$box->get('HexMakina\BlackBox\StateAgentInterface'); |
||
| 33 | $StateAgent->addRuntimeFilters((array)self::$box->get('settings.filter')); |
||
| 34 | $StateAgent->addRuntimeFilters((array)($_SESSION['filter'] ?? [])); |
||
| 35 | $StateAgent->addRuntimeFilters((array)($_REQUEST['filter'] ?? [])); |
||
| 36 | |||
| 37 | |||
| 38 | self::internationalisation(); |
||
| 39 | |||
| 40 | // ---- ŝablonoj |
||
| 41 | self::templating(); |
||
| 42 | |||
| 43 | // ---- lingva |
||
| 44 | $json_path = self::$box->get('settings.locale.json_path'); |
||
| 45 | $cache_path = self::$box->get('settings.locale.cache_path'); |
||
| 46 | $fallback_lang = self::$box->get('settings.locale.fallback_lang'); |
||
| 47 | $lezer = new Lezer($json_path, $cache_path, $fallback_lang); |
||
| 48 | $language = $lezer->availableLanguage(); |
||
| 49 | $lezer->init(); |
||
| 50 | |||
| 51 | self::$box->get('\Smarty')->assign('lezer', $lezer); |
||
| 52 | self::$box->get('\Smarty')->assign('language', $language); |
||
| 53 | |||
| 54 | setcookie('lang', $language, time() + (365 * 24 * 60 * 60), "/", ""); |
||
| 55 | |||
| 56 | return self::$box; |
||
| 57 | } |
||
| 58 | |||
| 59 | private static function internationalisation() |
||
| 60 | { |
||
| 61 | // ---- parametroj:signo |
||
| 62 | $setting = 'settings.default.charset'; |
||
| 63 | if (is_string(self::$box->get($setting))) { |
||
| 64 | ini_set('default_charset', self::$box->get($setting)); |
||
| 65 | header('Content-type: text/html; charset=' . strtolower(self::$box->get($setting))); |
||
| 66 | } else { |
||
| 67 | throw new \UnexpectedValueException($setting); |
||
| 68 | } |
||
| 69 | |||
| 70 | // ---- parametroj:linguo |
||
| 71 | $setting = 'settings.default.language'; |
||
| 72 | if (is_string(self::$box->get($setting))) { |
||
| 73 | putenv('LANG=' . self::$box->get($setting)); |
||
| 74 | setlocale(LC_ALL, self::$box->get($setting)); |
||
| 75 | } else { |
||
| 76 | throw new \UnexpectedValueException($setting); |
||
| 77 | } |
||
| 78 | |||
| 79 | // ---- parametroj:datoj |
||
| 80 | $setting = 'settings.default.timezone'; |
||
| 81 | if (is_string(self::$box->get($setting))) { |
||
| 82 | date_default_timezone_set(self::$box->get($setting)); |
||
| 83 | } else { |
||
| 84 | throw new \UnexpectedValueException($setting); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | private static function templating() |
||
| 89 | { |
||
| 90 | $smarty = self::$box->get('\Smarty'); |
||
| 91 | // Load smarty template parser |
||
| 92 | $smarty->setTemplateDir(self::$box->get('settings.smarty.template_app_directory')); |
||
| 93 | |||
| 94 | foreach (self::$box->get('settings.smarty.template_extra_directories') as $i => $template_dir) { |
||
| 95 | $smarty->addTemplateDir($template_dir); |
||
| 96 | } |
||
| 97 | $smarty->addTemplateDir(__DIR__ . '/Views/'); //kadro templates |
||
| 98 | |||
| 99 | $setting = 'settings.smarty.compiled_path'; |
||
| 100 | if (is_string(self::$box->get($setting))) { |
||
| 101 | $smarty->setCompileDir(self::$box->get($setting)); |
||
| 102 | } else { |
||
| 103 | throw new \UnexpectedValueException($setting); |
||
| 104 | } |
||
| 105 | |||
| 106 | $setting = 'settings.smarty.debug'; |
||
| 107 | if (is_bool(self::$box->get($setting))) { |
||
| 108 | $smarty->setDebugging(self::$box->get($setting)); |
||
| 109 | } else { |
||
| 110 | throw new \UnexpectedValueException($setting); |
||
| 111 | } |
||
| 112 | |||
| 113 | $smarty->registerClass('Lezer', '\HexMakina\Lezer\Lezer'); |
||
| 114 | $smarty->registerClass('Marker', '\HexMakina\Marker\Marker'); |
||
| 115 | $smarty->registerClass('Form', '\HexMakina\Marker\Form'); |
||
| 116 | $smarty->registerClass('TableToForm', '\HexMakina\kadro\TableToForm'); |
||
| 117 | $smarty->registerClass('Dato', '\HexMakina\Tempus\Dato'); |
||
| 118 | |||
| 119 | $smarty->assign('APP_NAME', self::$box->get('settings.app.name')); |
||
| 120 | |||
| 121 | return $smarty; |
||
| 122 | } |
||
| 123 | } |
||
| 124 |