private static function _load_type($type) { // Procura o arquivo de tipo $type_data = core::get_modular_parts($type, array('path_clip' => true, 'path_repeat' => true, 'path_extension' => '/types', 'make_fullpath' => true)); // Obtém o nome e inclui a classe responsável $type_class = core::get_joined_class($type_data, 'types'); core::do_require($type_data->fullpath); // Inclui e prepara a classe $type_object = new $type_class(); $type_object->on_require(); // Retorna o objeto com o tipo selecionado return self::$_types[$type]; }
public function __construct($view_path, $view_args, $cancel_print) { // Corrige o path solicitado $this->_proposed_view = core::get_path_fixed($view_path); // Se o path estiver vazio é invalidado if (empty($this->_proposed_view)) { $this->_status = self::STATUS_VIEW_IS_INVALID | self::STATUS_VIEW_IS_EMPTY | self::STATUS_VIEW_NOT_FOUND; return; } // Se o path for inseguro ou mesmo inválido if (preg_match(CORE_VALID_PATH, $this->_proposed_view) === 0) { $this->_status = self::STATUS_VIEW_IS_INVALID | self::STATUS_VIEW_IS_INSECURE | self::STATUS_VIEW_NOT_FOUND; return; } // Remove os protetores $this->_proposed_view = str_replace(array('[', ']'), null, $this->_proposed_view); // Busca pelo caminho da view $view_path_data = core::get_modular_parts(explode('/', $this->_proposed_view), array('modular_path_auto' => true, 'path_repeat' => false, 'path_extension' => '/views', 'make_fullpath' => true)); // Armazena a informação modular encontrada $this->_modular_data = $view_path_data; // Se a busca retornar restos invalida if (isset($view_path_data->remains)) { $this->_status = self::STATUS_VIEW_IS_INVALID | self::STATUS_VIEW_HAS_REMAINS | self::STATUS_VIEW_NOT_FOUND; return; } // Define o fullpath proposto $this->_path = $view_path_data->fullpath; // Se o arquivo proposto não existir é inválido if (is_file($this->_path) === false) { $this->_status = self::STATUS_VIEW_IS_INVALID | self::STATUS_VIEW_NOT_FOUND; return; } // Se nenhuma invalidação ocorreu, o arquivo é finalmente chamado $this->_load_view($view_args); // Por fim, imprime o conteúdo, se for necessário $this->_result_printed = !$cancel_print; if ($cancel_print === false) { echo $this->_result_contents; } }
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_linear($model_path) { $model_path = core::get_modular_parts($model_path, array('modular_path_auto' => true, 'path_extension' => '/models', 'make_fullpath' => true)); return self::_get_instance(core::get_joined_class($model_path, 'model')); }
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; }
public function exception_unknow_key() { core::get_modular_parts(null, array('fake_config' => true)); }