newInstance(); Component::$loaded[$path] = $obj; return $obj; } /** * Loads a model * @param string $name - the name of the model to load */ protected function load_model($name): Model|NULL { $dir = WEB_ROOT . '/_model'; return $this->load_type($name, $dir, 'model'); } /** * Loads a controller * @param string $name - the name of the controller to load */ public function load_controller($name): Controller|NULL { $dir = WEB_ROOT . '/_controller'; return $this->load_type($name, $dir, 'controller'); } // ========================================= LANG == /** * Loads a php lang file into the lang array */ private static function load_lang_file(string $file): void { $lang = $GLOBALS['__lang']; require($file); $GLOBALS['__lang'] = $lang; } /** * Loads each php file lang strings in a directory */ private static function load_lang_dir(string $dir): void { if ($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { if ($entry === '.' || $entry === '..') continue; Component::load_lang_file($entry); } } } /** * Loads the given common lang */ protected static function load_lang(string ...$langs): void { $root = WEB_ROOT . '/lang'; foreach ($langs as $lang) { $file = "{$root}/{$lang}.php"; $dir = "{$root}/{$lang}"; if (file_exists($file)) Component::load_lang_file($file); else if (is_dir($dir)) Component::load_lang_dir($dir); } } }