HexMakina /
kadro
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace HexMakina\kadro; |
||||||
| 4 | |||||||
| 5 | use HexMakina\Debugger\Debugger; |
||||||
| 6 | use HexMakina\Hopper\hopper; |
||||||
| 7 | use HexMakina\LeMarchand\LeMarchand; |
||||||
| 8 | use HexMakina\Lezer\Lezer; |
||||||
| 9 | use HexMakina\LogLaddy\LogLaddy; |
||||||
| 10 | use HexMakina\Smith\Smith; |
||||||
| 11 | |||||||
| 12 | class kadro |
||||||
| 13 | { |
||||||
| 14 | private static $box; // PSR-11 Service Locator, ugly until DI is ready |
||||||
| 15 | |||||||
| 16 | |||||||
| 17 | public static function init($settings) |
||||||
| 18 | { |
||||||
| 19 | new Debugger(); |
||||||
| 20 | |||||||
| 21 | self::$box = LeMarchand::box($settings); |
||||||
| 22 | |||||||
| 23 | //-- logger |
||||||
| 24 | self::$box->put('LoggerInterface', self::reporting()); |
||||||
| 25 | |||||||
| 26 | //-- router |
||||||
| 27 | self::$box->put('RouterInterface', self::routing()); |
||||||
| 28 | |||||||
| 29 | //-- sessions, ans soon cookies |
||||||
| 30 | self::$box->put('StateAgent', self::state()); |
||||||
| 31 | |||||||
| 32 | |||||||
| 33 | self::internationalisation(); |
||||||
| 34 | |||||||
| 35 | // ---- ŝablonoj |
||||||
| 36 | self::$box->put('template_engine', self::templating()); |
||||||
| 37 | |||||||
| 38 | // ---- lingva |
||||||
| 39 | $json_path = self::$box->get('settings.locale.json_path'); |
||||||
| 40 | $cache_path = self::$box->get('settings.locale.cache_path'); |
||||||
| 41 | $fallback_lang = self::$box->get('settings.locale.fallback_lang'); |
||||||
| 42 | $lezer = new Lezer($json_path, $cache_path, $fallback_lang); |
||||||
| 43 | $language = $lezer->availableLanguage(); |
||||||
| 44 | $lezer->init(); |
||||||
| 45 | |||||||
| 46 | self::$box->get('template_engine')->assign('lezer', $lezer); |
||||||
| 47 | self::$box->get('template_engine')->assign('language', $language); |
||||||
| 48 | |||||||
| 49 | setcookie('lang', $language, time() + (365 * 24 * 60 * 60), "/", ""); |
||||||
| 50 | |||||||
| 51 | return self::$box; |
||||||
| 52 | } |
||||||
| 53 | |||||||
| 54 | |||||||
| 55 | private static function reporting(): \HexMakina\LogLaddy\LoggerInterface |
||||||
| 56 | { |
||||||
| 57 | //-- logger |
||||||
| 58 | error_reporting(E_ALL); |
||||||
| 59 | define('PRODUCTION', $_SERVER['HTTP_HOST'] === self::$box->get('settings.app.production_host')); |
||||||
| 60 | ini_set('display_errors', PRODUCTION ? 0 : 1); |
||||||
| 61 | |||||||
| 62 | $log_laddy = new \HexMakina\LogLaddy\LogLaddy(); |
||||||
| 63 | $log_laddy->setHandlers(); |
||||||
| 64 | return $log_laddy; |
||||||
| 65 | } |
||||||
| 66 | |||||||
| 67 | private static function routing() |
||||||
| 68 | { |
||||||
| 69 | $Hup = new \HexMakina\Hopper\hopper(require(__DIR__.'/routes.php')); |
||||||
| 70 | $Hup->setBasePath(self::$box->get('settings.hopper.web_base')); |
||||||
| 71 | $Hup->setFilePath(self::$box->get('settings.hopper.file_root')); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 72 | $Hup->mapHomeRoute(self::$box->get('settings.hopper.route_home')); |
||||||
|
0 ignored issues
–
show
The method
mapHomeRoute() does not exist on HexMakina\Hopper\hopper.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 73 | return $Hup; |
||||||
| 74 | } |
||||||
| 75 | |||||||
| 76 | private static function state() |
||||||
| 77 | { |
||||||
| 78 | //-- kuketoj |
||||||
| 79 | // setcookie('cookie_test', 'test_value', time()+(365 * 24 * 60 * 60), "/", ""); |
||||||
| 80 | // $cookies_enabled=isset($_COOKIE['cookie_test']); // houston, do we have cookies ? |
||||||
| 81 | |||||||
| 82 | // if($cookies_enabled === false) |
||||||
| 83 | // { |
||||||
| 84 | // ini_set('session.use_cookies', 0); |
||||||
| 85 | // ini_set('session.use_only_cookies', 0); |
||||||
| 86 | // ini_set('session.use_trans_sid', 1); |
||||||
| 87 | // ini_set('session.cache_limiter', 'nocache'); |
||||||
| 88 | // } |
||||||
| 89 | |||||||
| 90 | //-- Session Management |
||||||
| 91 | $StateAgent = new \HexMakina\Smith\Smith(self::$box->get('settings.app.session_start_options') ?? []); |
||||||
| 92 | $StateAgent->addRuntimeFilters((array)self::$box->get('settings.filter')); |
||||||
| 93 | $StateAgent->addRuntimeFilters((array)($_SESSION['filter'] ?? [])); |
||||||
| 94 | $StateAgent->addRuntimeFilters((array)($_REQUEST['filter'] ?? [])); |
||||||
| 95 | |||||||
| 96 | return $StateAgent; |
||||||
| 97 | } |
||||||
| 98 | |||||||
| 99 | private static function internationalisation() |
||||||
| 100 | { |
||||||
| 101 | // ---- parametroj:signo |
||||||
| 102 | $setting = 'settings.default.charset'; |
||||||
| 103 | if (is_string(self::$box->get($setting))) { |
||||||
| 104 | ini_set('default_charset', self::$box->get($setting)); |
||||||
| 105 | header('Content-type: text/html; charset=' . strtolower(self::$box->get($setting))); |
||||||
| 106 | } else { |
||||||
| 107 | throw new \UnexpectedValueException($setting); |
||||||
| 108 | } |
||||||
| 109 | |||||||
| 110 | // ---- parametroj:linguo |
||||||
| 111 | $setting = 'settings.default.language'; |
||||||
| 112 | if (is_string(self::$box->get($setting))) { |
||||||
| 113 | putenv('LANG=' . self::$box->get($setting)); |
||||||
| 114 | setlocale(LC_ALL, self::$box->get($setting)); |
||||||
| 115 | } else { |
||||||
| 116 | throw new \UnexpectedValueException($setting); |
||||||
| 117 | } |
||||||
| 118 | |||||||
| 119 | // ---- parametroj:datoj |
||||||
| 120 | $setting = 'settings.default.timezone'; |
||||||
| 121 | if (is_string(self::$box->get($setting))) { |
||||||
| 122 | date_default_timezone_set(self::$box->get($setting)); |
||||||
| 123 | } else { |
||||||
| 124 | throw new \UnexpectedValueException($setting); |
||||||
| 125 | } |
||||||
| 126 | } |
||||||
| 127 | |||||||
| 128 | private static function templating() |
||||||
| 129 | { |
||||||
| 130 | $smarty = new \Smarty(); |
||||||
| 131 | self::$box->put('template_engine', $smarty); |
||||||
| 132 | |||||||
| 133 | // Load smarty template parser |
||||||
| 134 | $smarty->setTemplateDir(self::$box->get('settings.smarty.template_app_directory')); |
||||||
| 135 | |||||||
| 136 | foreach (self::$box->get('settings.smarty.template_extra_directories') as $i => $template_dir) { |
||||||
| 137 | $smarty->addTemplateDir($template_dir); |
||||||
| 138 | } |
||||||
| 139 | $smarty->addTemplateDir(__DIR__ . '/Views/'); //kadro templates |
||||||
| 140 | |||||||
| 141 | $setting = 'settings.smarty.compiled_path'; |
||||||
| 142 | if (is_string(self::$box->get($setting))) { |
||||||
| 143 | $smarty->setCompileDir(self::$box->get($setting)); |
||||||
| 144 | } else { |
||||||
| 145 | throw new \UnexpectedValueException($setting); |
||||||
| 146 | } |
||||||
| 147 | |||||||
| 148 | $setting = 'settings.smarty.debug'; |
||||||
| 149 | if (is_bool(self::$box->get($setting))) { |
||||||
| 150 | $smarty->setDebugging(self::$box->get($setting)); |
||||||
| 151 | } else { |
||||||
| 152 | throw new \UnexpectedValueException($setting); |
||||||
| 153 | } |
||||||
| 154 | |||||||
| 155 | $smarty->registerClass('Lezer', '\HexMakina\Lezer\Lezer'); |
||||||
| 156 | $smarty->registerClass('Marker', '\HexMakina\Marker\Marker'); |
||||||
| 157 | $smarty->registerClass('Form', '\HexMakina\Marker\Form'); |
||||||
| 158 | $smarty->registerClass('TableToForm', '\HexMakina\kadro\TableToForm'); |
||||||
| 159 | $smarty->registerClass('Dato', '\HexMakina\Tempus\Dato'); |
||||||
| 160 | |||||||
| 161 | $smarty->assign('APP_NAME', self::$box->get('settings.app.name')); |
||||||
| 162 | |||||||
| 163 | return $smarty; |
||||||
| 164 | } |
||||||
| 165 | } |
||||||
| 166 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.