HexMakina /
kadro
| 1 | <?php |
||
| 2 | |||
| 3 | namespace HexMakina\kadro; |
||
| 4 | |||
| 5 | use \HexMakina\LeMarchand\LeMarchand; |
||
| 6 | use \HexMakina\Debugger\Debugger; |
||
| 7 | use \HexMakina\Lezer\Lezer; |
||
| 8 | use \HexMakina\Smith\Smith; |
||
| 9 | use \HexMakina\LogLaddy\LogLaddy; |
||
| 10 | use \HexMakina\Hopper\hopper; |
||
| 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); |
||
|
0 ignored issues
–
show
|
|||
| 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 | $locale_path = self::$box->get('settings.locale.directory_path'); |
||
| 40 | $file_name = self::$box->get('settings.locale.file_name'); |
||
| 41 | $fallback_lang = self::$box->get('settings.locale.fallback_lang'); |
||
| 42 | |||
| 43 | $lezer = new Lezer($locale_path . '/' . $file_name, $locale_path . '/cache', $fallback_lang); |
||
| 44 | $language = $lezer->availableLanguage(); |
||
| 45 | $lezer->init(); |
||
| 46 | |||
| 47 | self::$box->get('template_engine')->assign('lezer', $lezer); |
||
| 48 | self::$box->get('template_engine')->assign('language', $language); |
||
| 49 | |||
| 50 | setcookie('lang', $language, time() + (365 * 24 * 60 * 60), "/", ""); |
||
| 51 | |||
| 52 | return self::$box; |
||
| 53 | } |
||
| 54 | |||
| 55 | |||
| 56 | private static function reporting(): \HexMakina\LogLaddy\LoggerInterface |
||
| 57 | { |
||
| 58 | //-- logger |
||
| 59 | error_reporting(E_ALL); |
||
| 60 | define('PRODUCTION', $_SERVER['HTTP_HOST'] === self::$box->get('settings.app.production_host')); |
||
| 61 | ini_set('display_errors', PRODUCTION ? 0 : 1); |
||
| 62 | |||
| 63 | $log_laddy = new \HexMakina\LogLaddy\LogLaddy(); |
||
| 64 | $log_laddy->setHandlers(); |
||
| 65 | return $log_laddy; |
||
| 66 | } |
||
| 67 | |||
| 68 | private static function routing() |
||
| 69 | { |
||
| 70 | $Hup = new \HexMakina\Hopper\hopper(self::$box->get('settings.RouterInterface')); |
||
| 71 | |||
| 72 | $Hup->map('GET', 'checkin', 'ReceptionController::checkin', 'checkin'); |
||
| 73 | $Hup->map('GET', 'checkout', 'ReceptionController::checkout', 'checkout'); |
||
| 74 | $Hup->map('POST', 'identify', 'ReceptionController::identify', 'identify'); |
||
| 75 | |||
| 76 | $Hup->map('GET', 'operator/[*:username]/toggle/active', 'OperatorController::change_active', 'operator_change_active'); |
||
| 77 | $Hup->map('GET', 'operator/[*:username]/change-acl/[i:permission_id]', 'OperatorController::change_acl', 'acl_toggle'); |
||
| 78 | |||
| 79 | |||
| 80 | // ---------------------------------------------------- SEARCH |
||
| 81 | // $Hup->map( 'GET' , 'search', 'SearchController::search', 'search_advanced'); |
||
| 82 | $Hup->map('POST|GET', 'search', 'SearchController::results', 'search'); |
||
| 83 | // $Hup->map( 'POST' , 'search', 'SearchController::results', 'search'); |
||
| 84 | |||
| 85 | // ---------------------------------------------------- TRADUKO |
||
| 86 | $Hup->map('POST', 'traduko/update_file', 'TradukoController::update_file', 'traduko_update_file'); |
||
| 87 | |||
| 88 | // ---------------------------------------------------- LOCALE JSON |
||
| 89 | $Hup->map('GET', 'locale/language_codes.[a:format]', 'ExportController::otto_languages', 'otto_languages'); |
||
| 90 | |||
| 91 | |||
| 92 | // ---------------------------------------------------- EXPORT |
||
| 93 | $Hup->map('GET', 'export', 'ExportController::dashboard', 'export'); // default ExportController is dashboard |
||
| 94 | $Hup->map('GET', 'otto/language_codes.[a:format]/term/[a:search]?', 'ExportController::otto_languages', 'otto_languages_search'); |
||
| 95 | $Hup->map('GET', 'otto/[a:model]/distinct/[*:field].[a:format]', 'ExportController::otto_distinct_field', 'otto_distinct_field'); |
||
| 96 | $Hup->map('GET', 'otto/[a:model]/distinct/[*:field].[a:format]/term/[*:search]?', 'ExportController::otto_distinct_field', 'otto_distinct_field_where'); |
||
| 97 | $Hup->map('GET', 'export/[*:action].[a:format]', 'ExportController::dynamic_action_call', 'export_action_call'); |
||
| 98 | |||
| 99 | return $Hup; |
||
| 100 | } |
||
| 101 | |||
| 102 | private static function state() |
||
| 103 | { |
||
| 104 | //-- kuketoj |
||
| 105 | // setcookie('cookie_test', 'test_value', time()+(365 * 24 * 60 * 60), "/", ""); |
||
| 106 | // $cookies_enabled=isset($_COOKIE['cookie_test']); // houston, do we have cookies ? |
||
| 107 | |||
| 108 | // if($cookies_enabled === false) |
||
| 109 | // { |
||
| 110 | // ini_set('session.use_cookies', 0); |
||
| 111 | // ini_set('session.use_only_cookies', 0); |
||
| 112 | // ini_set('session.use_trans_sid', 1); |
||
| 113 | // ini_set('session.cache_limiter', 'nocache'); |
||
| 114 | // } |
||
| 115 | |||
| 116 | //-- Session Management |
||
| 117 | $StateAgent = new \HexMakina\Smith\Smith(self::$box->get('settings.app.session_start_options') ?? []); |
||
| 118 | $StateAgent->addRuntimeFilters((array)self::$box->get('settings.filter')); |
||
| 119 | $StateAgent->addRuntimeFilters((array)($_SESSION['filter'] ?? [])); |
||
| 120 | $StateAgent->addRuntimeFilters((array)($_REQUEST['filter'] ?? [])); |
||
| 121 | |||
| 122 | return $StateAgent; |
||
| 123 | } |
||
| 124 | |||
| 125 | private static function internationalisation() |
||
| 126 | { |
||
| 127 | // ---- parametroj:signo |
||
| 128 | $setting = 'settings.default.charset'; |
||
| 129 | if (is_string(self::$box->get($setting))) { |
||
| 130 | ini_set('default_charset', self::$box->get($setting)); |
||
| 131 | header('Content-type: text/html; charset=' . strtolower(self::$box->get($setting))); |
||
| 132 | } else { |
||
| 133 | throw new \UnexpectedValueException($setting); |
||
| 134 | } |
||
| 135 | |||
| 136 | // ---- parametroj:linguo |
||
| 137 | $setting = 'settings.default.language'; |
||
| 138 | if (is_string(self::$box->get($setting))) { |
||
| 139 | putenv('LANG=' . self::$box->get($setting)); |
||
| 140 | setlocale(LC_ALL, self::$box->get($setting)); |
||
| 141 | } else { |
||
| 142 | throw new \UnexpectedValueException($setting); |
||
| 143 | } |
||
| 144 | |||
| 145 | // ---- parametroj:datoj |
||
| 146 | $setting = 'settings.default.timezone'; |
||
| 147 | if (is_string(self::$box->get($setting))) { |
||
| 148 | date_default_timezone_set(self::$box->get($setting)); |
||
| 149 | } else { |
||
| 150 | throw new \UnexpectedValueException($setting); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | private static function templating() |
||
| 155 | { |
||
| 156 | $smarty = new \Smarty(); |
||
| 157 | self::$box->put('template_engine', $smarty); |
||
| 158 | |||
| 159 | // Load smarty template parser |
||
| 160 | $smarty->setTemplateDir(self::$box->get('settings.smarty.template_app_directory')); |
||
| 161 | |||
| 162 | foreach (self::$box->get('settings.smarty.template_extra_directories') as $i => $template_dir) { |
||
| 163 | $smarty->addTemplateDir($template_dir); |
||
| 164 | } |
||
| 165 | $smarty->addTemplateDir(__DIR__ . '/Views/'); //kadro templates |
||
| 166 | |||
| 167 | $setting = 'settings.smarty.compiled_path'; |
||
| 168 | if (is_string(self::$box->get($setting))) { |
||
| 169 | $smarty->setCompileDir(self::$box->get($setting)); |
||
| 170 | } else { |
||
| 171 | throw new \UnexpectedValueException($setting); |
||
| 172 | } |
||
| 173 | |||
| 174 | $setting = 'settings.smarty.debug'; |
||
| 175 | if (is_bool(self::$box->get($setting))) { |
||
| 176 | $smarty->setDebugging(self::$box->get($setting)); |
||
| 177 | } else { |
||
| 178 | throw new \UnexpectedValueException($setting); |
||
| 179 | } |
||
| 180 | |||
| 181 | $smarty->registerClass('Lezer', '\HexMakina\Lezer\Lezer'); |
||
| 182 | $smarty->registerClass('Marker', '\HexMakina\Marker\Marker'); |
||
| 183 | $smarty->registerClass('Form', '\HexMakina\Marker\Form'); |
||
| 184 | $smarty->registerClass('TableToForm', '\HexMakina\kadro\TableToForm'); |
||
| 185 | $smarty->registerClass('Dato', '\HexMakina\Tempus\Dato'); |
||
| 186 | |||
| 187 | $smarty->assign('APP_NAME', self::$box->get('settings.app.name')); |
||
| 188 | |||
| 189 | return $smarty; |
||
| 190 | } |
||
| 191 | } |
||
| 192 |
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.