public function add_type($type_name, $type_alias = null, $optional_value = null, $include_module = true, $same_both = false) { // Define o aliases $type_alias = $type_alias ? $type_alias : $type_name; // Se for necessário incluir o módulo atual no nome if ($include_module === true) { $type_name = join('_', core::get_caller_module_path()) . '_' . $type_name; } // Objeto de funcionamento $object = array('object' => $this, 'alias' => $type_alias, 'optional' => $optional_value, 'method' => $same_both); // Adiciona o objeto self::$_types[$type_name] = $object; }
public static function load_helper($helper) { // Primeiramente é necessário identificar se é um helper do próprio módulo // Para isto, o helper deve iniciar com duplo underline // Exemplo: __exemplo passará a ser site_exemplo if (substr($helper, 0, 2) === '__') { // Se for, a informação é substituida pelo módulo $helper = join('_', core::get_caller_module_path()) . '_' . substr($helper, 2); } // Agora é necessário localizar o helper e carregá-lo $modular_path = core::get_modular_parts($helper, array('path_extension' => '/helpers', 'make_fullpath' => true)); // Se o helper já tiver sido carregado, evita o processo $helper_key = $modular_path->fullpath . ":helper"; if (isset(self::$_loaded_classes[$helper_key])) { return $helper; } // Inclui o arquivo core::do_require($modular_path->fullpath); // Salva em loaded classes e retorna self::$_loaded_classes[$helper_key] = true; return $helper; }
public static function get_caller_module_path() { return core::get_caller_module_path(); }
public static function _create_controller($modular_path_data, $cancel_print = false, $auto_execute = true, $can_detect_caller_path = false) { // Armazena o método padrão, ele será usado em vários momentos $default_method = core_config::get_config(null, 'route_default_method'); // Define algumas informações principais $modular_path = new stdclass(); $modular_path->url = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . "://{$_SERVER['SERVER_NAME']}" . dirname($_SERVER['SCRIPT_NAME']) . '/'; // Se o path modular for false, então usa totalmente o padrão // Ex: http://127.0.0.1/ if ($modular_path_data === null || $modular_path_data === false) { $modular_path->modular = (array) core_config::get_config(null, 'route_default_modular'); $modular_path->path = (array) core_config::get_config(null, 'route_default_controller'); $modular_path->method = $default_method; $modular_path->class = core::get_joined_class($modular_path, 'controller'); } else { // Se puder detectar o path do caller (somente execute()) if ($can_detect_caller_path === true && isset($modular_path_data[0]) === true) { // Se o primeiro caractere for um $, indica rota estrita inline if ($modular_path_data[0] === '$') { $strict_route = true; $modular_path_data = substr($modular_path_data, 1); } // Se o modular começar por / apenas remove a informação // Caso contrário, deverá preencher com o path do módulo de chamada if ($modular_path_data[0] === '/') { $modular_path_data = substr($modular_path_data, 1); } else { $modular_path_data = join('/', core::get_caller_module_path()) . '/' . $modular_path_data; } } // Se não definir o modo estrito de rota, obtém a informação if (!isset($strict_route)) { $strict_route = config('route_strict_mode'); } // Extende a informação da URL $modular_path->url .= $modular_path_data; // Se houver uma definição de path, é necessário fazer uma busca por arquivos // Primeiramente, é necessário separar a chamada $modular_path_data = explode('/', $modular_path_data); // Depois é necessário buscar pelo modular do endereço solicitado // Ex: http://127.0.0.1/site $modular_path_data = core::get_modular_parts($modular_path_data, array('search_paths' => false, 'path_clip_empty' => true, 'make_fullpath' => true)); // Se a modular não for definida, retorna um controller neutro if (isset($modular_path_data->modular) === false) { if ($strict_route === true) { return new self($modular_path, null, $cancel_print, self::STATUS_CONTROLLER_INVALID | self::STATUS_MODULAR_REQUIRED, self::RETURN_TYPE_DEFAULT, false); } else { $modular_path_data->modular = (array) core_config::get_config(null, 'route_default_modular'); } } // Senão, armazena a informação $modular_path->modular = $modular_path_data->modular; // Depois é necessário buscar pelo controller do endereço solicitado // Ex: http://127.0.0.1/site/master ou simplesmente http://127.0.0.1/master $modular_path_data = core::get_modular_parts(@$modular_path_data->remains, array('start_dir' => $modular_path_data->fullpath . '/controllers', 'search_modules' => false)); // Se o controller não for definido, define com o valor padrão if (!empty($modular_path_data->path)) { $modular_path->path = $modular_path_data->path; } else { if ($strict_route === false) { $modular_path->path = (array) core_config::get_config(null, 'route_default_controller'); } else { return new self($modular_path, null, $cancel_print, self::STATUS_CONTROLLER_INVALID | self::STATUS_PATH_REQUIRED, self::RETURN_TYPE_DEFAULT, false); } } // Gera o nome completo da chamada $modular_path->class = core::get_joined_class($modular_path, 'controller'); // Se não existir mais informações para o method, usa o valor padrão if (empty($modular_path_data->remains) === false) { $modular_path->method = array_shift($modular_path_data->remains); } else { if ($strict_route === false) { $modular_path->method = $default_method; } else { return new self($modular_path, null, $cancel_print, self::STATUS_CONTROLLER_INVALID | self::STATUS_METHOD_REQUIRED, self::RETURN_TYPE_DEFAULT, false); } } } // Gera o caminho completo do arquivo $modular_path->fullpath = core::get_path_fixed(CORE_MODULES . '/' . join('/_', $modular_path->modular) . '/controllers/' . join('/', $modular_path->path) . '.php'); // Se o arquivo de controller não existir, usará o controler neutro if (is_file($modular_path->fullpath) === false) { return new self($modular_path, null, $cancel_print, self::STATUS_CONTROLLER_INVALID | self::STATUS_CONTROLLER_NOT_FOUND, self::RETURN_TYPE_DEFAULT, false); } // Senão, faz um require da classe solicitada if (class_exists($modular_path->class, false) === false) { core::do_require($modular_path->fullpath); } // Se for chamado um método diferente do padrão, mas este não existir, usa o método padrão try { if ($modular_path->method !== $default_method && method_exists($modular_path->class, $modular_path->method) === false) { if ($strict_route === true) { return new self($modular_path, null, $cancel_print, self::STATUS_CONTROLLER_INVALID | self::STATUS_METHOD_REQUIRED, self::RETURN_TYPE_DEFAULT, false); } array_unshift($modular_path_data->remains, $modular_path->method); $modular_path->method = $default_method; } } catch (core_exception $e) { $modular_path->method = $default_method; } // Por fim, cria o controller com as definições passadas return new $modular_path->class($modular_path, @$modular_path_data->remains, $cancel_print, self::STATUS_SUCCESS, self::RETURN_TYPE_DEFAULT, $auto_execute); }
public static function get_available($path = null, $lang_order = null) { // Se o path não for definido, usa o path atual if ($path === null) { $path = core::get_path_fixed(CORE_MODULES) . '/' . join('/_', core::get_caller_module_path()) . '/languages'; } else { // Busca pelo caminho do language $lang_path_data = core::get_modular_parts(explode('/', $path), array('modular_path_auto' => true, 'path_extension' => '/languages', 'make_fullpath' => true)); // Reconfigura o path $path = $lang_path_data->fullpath; } // Se a pasta não existir, retorna null //DEBUG: lançar uma exceção if (!is_dir($path)) { return null; } // Define a ordem de linguagem $lang_order_data = $lang_order === true ? null : $lang_order; // Obtém a tradução dos idiomas $lang = lang('/core/languages', $lang_order_data); // Obtém as pastas $dir_res = opendir($path); $dir_list = array(); while ($dir = readdir($dir_res)) { if ($dir !== '.' && $dir !== '..' && is_dir("{$path}/{$dir}")) { // Se a ordem de linguagem for true, usa a tradução local if ($lang_order === true) { $lang->set_language_order(array($dir, 'en')); } $dir_list[$dir] = $lang->get_value($dir); } } ksort($dir_list); return $dir_list; }