示例#1
0
 public static function do_call($command, $arguments)
 {
     // Separa o objeto do método
     if (preg_match(CORE_VALID_CALLER, $command, $command_details) === 1) {
         // Se um objeto for definido, significa que é uma chamada a um método estático de uma library
         if (!empty($command_details['object'])) {
             // Carrega a biblioteca, se necessário
             $command_details['object'] = self::load_library($command_details['object']);
             // Executa a chamada e retorna a informação obtida
             return call_user_func_array(array($command_details['object'], $command_details['method']), $arguments);
         }
         // Executa a chamada e retorna a informação obtida
         return call_user_func_array(self::load_helper($command_details['method']), $arguments);
     }
     // Se não for possível, lança uma exceção
     $error = new core_error('Cx2001', array('arguments' => $arguments, 'command_format' => CORE_VALID_CALLER), array('command' => $command));
     $error->run();
 }
示例#2
0
 private function _type_transform($type_data, $default_type = null)
 {
     if ($type_data === null) {
         $type_data = $default_type;
     }
     if (is_string($type_data) || is_array($type_data)) {
         $list = core::parse_setlist($type_data);
         $code = 0;
         foreach ($list as $item) {
             switch ($item) {
                 case 'ok':
                     $code |= self::TYPE_OK;
                     break;
                 case 'info':
                     $code |= self::TYPE_INFO;
                     break;
                 case 'error':
                     $code |= self::TYPE_ERROR;
                     break;
                 case 'warning':
                     $code |= self::TYPE_WARNING;
                     break;
                 case 'exception':
                     $code |= self::TYPE_EXCEPTION;
                     break;
                 case 'all':
                     $code = self::TYPE_ALL;
                     break;
                 default:
                     $error = new core_error('Cx2007', null, array('args' => array($item, $type_data)));
                     $error->run();
             }
         }
         return $code;
     }
     return $type_data;
 }
示例#3
0
 private function _throw_exception()
 {
     if (($this->_status & self::STATUS_CONTROLLER_NOT_FOUND) === self::STATUS_CONTROLLER_NOT_FOUND) {
         $error = new core_error('Cx2002', null, array('args' => array($this->_modular_data->fullpath)));
     } else {
         if (($this->_status & self::STATUS_METHOD_REQUIRED) === self::STATUS_METHOD_REQUIRED) {
             $error = new core_error('Cx2003', null, array('args' => array($this->_modular_data->url)));
         } else {
             if (($this->_status & self::STATUS_PATH_REQUIRED) === self::STATUS_PATH_REQUIRED) {
                 $error = new core_error('Cx2004', null, array('args' => array($this->_modular_data->url)));
             } else {
                 if (($this->_status & self::STATUS_MODULAR_REQUIRED) === self::STATUS_MODULAR_REQUIRED) {
                     $error = new core_error('Cx2005', null, array('args' => array($this->_modular_data->url)));
                 } else {
                     if (($this->_status & self::STATUS_METHOD_NOT_EXISTS) === self::STATUS_METHOD_NOT_EXISTS) {
                         $error = new core_error('Cx2006', null, array('args' => array("{$this->_modular_data->class}::{$this->_modular_data->method}")));
                     }
                 }
             }
         }
     }
     $error->run();
 }
示例#4
0
 public function required()
 {
     if ($this->_status !== self::STATUS_SUCCESS) {
         if (($this->_status & self::STATUS_VIEW_IS_INSECURE) === self::STATUS_VIEW_IS_INSECURE) {
             $error = new core_error('Cx2008', null, array('args' => array($this->_proposed_view)));
         } else {
             if (($this->_status & self::STATUS_VIEW_HAS_REMAINS) === self::STATUS_VIEW_HAS_REMAINS) {
                 $remains = join('/', $this->_modular_data->remains);
                 $error = new core_error('Cx2009', null, array('args' => array($remains, $this->_proposed_view)));
             } else {
                 if (($this->_status & self::STATUS_VIEW_IS_EMPTY) === self::STATUS_VIEW_IS_EMPTY) {
                     $error = new core_error('Cx200A');
                 } else {
                     if (($this->_status & self::STATUS_VIEW_NOT_FOUND) === self::STATUS_VIEW_NOT_FOUND) {
                         $error = new core_error('Cx200B', null, array('args' => array($this->_path)));
                     }
                 }
             }
         }
         $error->run();
     }
     return $this;
 }
示例#5
0
 public function query($query_string)
 {
     // Inicia a conexão, se necessário
     if ($this->_connected === false) {
         $this->connect();
     }
     // Armazena o resultado da query
     $query = $this->_connection->query($this->_last_query = $query_string);
     // Se a query falhar
     if ($query === false) {
         $error = new core_error('Cx3000', array('error' => $this->_connection->error, 'errno' => $this->_connection->errno, 'sql' => $this->_last_query));
         $error->set_fatal(true);
         $error->run();
     }
     return $query;
 }
示例#6
0
文件: core.php 项目: rentalhost/core
 public static function get_modular_parts($modular_path, $configs = null)
 {
     $configs = (array) $configs;
     // Aplica o modular path
     !isset($configs['modular_path_auto']) && ($configs['modular_path_auto'] = false);
     // Se for uma string, é necessário quebrar a informação
     if (is_string($modular_path)) {
         !isset($configs['split_by']) && ($configs['split_by'] = '_');
         !isset($configs['group_by']) && ($configs['group_by'] = '__');
         !isset($configs['neutral_by']) && ($configs['neutral_by'] = "");
         !isset($configs['make_underlined']) && ($configs['make_underlined'] = true);
         $modular_path = str_replace($configs['group_by'], $configs['neutral_by'], $modular_path);
         $modular_path = explode($configs['split_by'], $modular_path);
         foreach ($modular_path as $key => $item) {
             $modular_path[$key] = str_replace($configs['neutral_by'], $configs['split_by'], $item);
         }
         if ($configs['modular_path_auto'] === true && $modular_path[0][0] === '_') {
             $modular_path[0] = substr($modular_path[0], 1);
         }
     } else {
         if ($modular_path === null) {
             $modular_path = array();
         }
     }
     // Após ter a array, é necessário fazer a busca pelos arquivos
     !isset($configs['start_dir']) && ($configs['start_dir'] = CORE_MODULES);
     !isset($configs['search_modules']) && ($configs['search_modules'] = true);
     !isset($configs['search_paths']) && ($configs['search_paths'] = true);
     !isset($configs['path_repeat']) && ($configs['path_repeat'] = true);
     !isset($configs['path_clip']) && ($configs['path_clip'] = false);
     !isset($configs['path_clip_empty']) && ($configs['path_clip_empty'] = false);
     !isset($configs['path_extension']) && ($configs['path_extension'] = null);
     !isset($configs['file_extension']) && ($configs['file_extension'] = 'php');
     !isset($configs['make_fullpath']) && ($configs['make_fullpath'] = false);
     !isset($configs['make_underlined']) && ($configs['make_underlined'] = false);
     // Em modo depuração, verifica se alguma configuração não suportada foi definida
     if (CORE_DEBUG === true) {
         static $config_keys = array('modular_path_auto', 'split_by', 'group_by', 'neutral_by', 'make_underlined', 'start_dir', 'search_modules', 'search_paths', 'path_repeat', 'path_clip', 'path_clip_empty', 'path_extension', 'file_extension', 'make_fullpath');
         $config_diff = array_diff(array_keys($configs), $config_keys);
         if (!empty($config_diff)) {
             $error = new core_error('Cx2000', null, array('unknow_keys' => $config_diff));
             $error->run();
         }
     }
     // Define o diretório de partida
     $current_path = $configs['start_dir'];
     // Prepara os resultados
     $result = new stdclass();
     // Se for necessário "clipar" o último elemento do path...
     if ($configs['path_clip'] === true) {
         $result->clipped = array_pop($modular_path);
     }
     // Se necessário, remove o último elemento do path se ele estiver vazio
     if ($configs['path_clip_empty'] === true && end($modular_path) === '') {
         array_pop($modular_path);
     }
     // Repete a última definição do path, se possível
     $last_try = $configs['path_repeat'];
     $using_last_try = false;
     // Se necessário, aplica a raiz do módulo
     if ($configs['modular_path_auto'] === true) {
         if (empty($modular_path[0])) {
             array_shift($modular_path);
         } else {
             $modular_path = array_merge(self::get_caller_module_path(), $modular_path);
         }
     }
     // Se for necessário buscar por módulos...
     if ($configs['search_modules'] === true && empty($modular_path) === false) {
         $result->modular = array();
         // Para cada parte do array, verifica se é um diretório
         $last_key = count($modular_path) - 1;
         foreach ($modular_path as $key => $value) {
             // Propõe um diretório, a partir do segundo é usado um underline submodular
             $proposed_path = $current_path . ($key === 0 ? "/{$value}" : "/_{$value}");
             // Se o diretório for aceito, adiciona aos módulos, aceita a proposta e continua a busca
             if (is_dir($proposed_path)) {
                 // Se for necessário dar duplo underline...
                 if ($configs['make_underlined'] === true) {
                     $value = str_replace('_', '__', $value);
                 }
                 // Registra a ocorrência
                 $result->modular[] = $value;
                 $current_path = $proposed_path;
                 // Se for a última chave, limpa o modular
                 if ($last_key === $key) {
                     $modular_path = array();
                     break;
                 }
                 continue;
             }
             // Quando terminar os diretórios, remove os caminhos encontrados do modular path
             $modular_path = array_slice($modular_path, $key);
             break;
         }
         // Se nenhum modular for cadastro, apaga a variável
         if (empty($result->modular)) {
             unset($result->modular);
         }
         // Se for necessário repetir
         if ($last_try === true && empty($modular_path) && !empty($result->modular)) {
             $last_try = false;
             $using_last_try = true;
             array_unshift($modular_path, end($result->modular));
         }
     }
     // Após buscar o módulo, se for necessário, anexa o complemento
     if (!empty($configs['path_extension'])) {
         $current_path .= $configs['path_extension'];
     }
     // Se for necessário buscar por paths...
     if ($configs['search_paths'] === true && empty($modular_path) === false) {
         $result->path = array();
         // Para cada modular, busca pelo sub-diretório
         while (true) {
             $last_key = count($modular_path) - 1;
             foreach ($modular_path as $key => $item_value) {
                 $value = $item_value;
                 // Propõe um diretório
                 $proposed_path = $current_path . "/{$value}";
                 // Se o diretório for aceito, adiciona aos paths, aceita a proposta e continua a busca
                 if (is_dir($proposed_path)) {
                     // Se for necessário dar duplo underline...
                     if ($configs['make_underlined'] === true) {
                         $value = str_replace('_', '__', $value);
                     }
                     // Registra a ocorrência
                     $result->path[] = $value;
                     $current_path = $proposed_path;
                     // Se for a última chave, limpa o modular
                     if ($last_key === $key) {
                         // Em última chance, verifica se pode ser um arquivo
                         if ($last_try === true) {
                             $proposed_file = "{$current_path}/{$item_value}.{$configs['file_extension']}";
                             if (is_file($proposed_file)) {
                                 $last_try = false;
                                 $result->path[] = $value;
                                 $current_path = $proposed_file;
                                 // Adiciona um informativo
                                 $result->repeated = true;
                             }
                         }
                         $modular_path = array();
                         break 2;
                     }
                     continue;
                 }
                 // Propõe um arquivo
                 $proposed_file = $proposed_path . ".{$configs['file_extension']}";
                 // Se for um arquivo, adiciona aos paths
                 // Ao achar um arquivo, fecha a busca e avança a chave, simulando uma nova proposta
                 if (is_file($proposed_file)) {
                     // Se for necessário dar duplo underline...
                     if ($configs['make_underlined'] === true) {
                         $value = str_replace('_', '__', $value);
                     }
                     // Registra a ocorrência
                     $result->path[] = $value;
                     $current_path = $proposed_file;
                     $key++;
                     $last_try = false;
                 }
                 // Quando terminar os diretórios, remove os caminhos encontrados do modular path
                 $modular_path = array_slice($modular_path, $key);
                 break 2;
             }
         }
         // Se nenhum path for cadastro, apaga a variável
         if (empty($result->path)) {
             unset($result->path);
         }
     }
     // Se sobrar alguma informação no path, armazena
     if ($using_last_try === false) {
         if (!empty($modular_path)) {
             $result->remains = $modular_path;
         }
     } else {
         if (empty($modular_path)) {
             $result->repeated = true;
         }
     }
     // Se for necessário gerar o path completo...
     if ($configs['make_fullpath'] === true) {
         $result->fullpath = self::get_path_fixed(realpath($current_path));
     }
     // Retorna o resultado gerado
     return $result;
 }