function index() { //_cfg::$fileIni = 'magé'; echo o::pt(_cfg::this()); //_cfg::saveConfig(RPATH.'teste.ini'); _view::set('inicial'); }
static function run($config = '') { //carregando uma instância da classe $main = self::this(); //Carregando a configuração if ($config != '') { _cfg::this()->loadConfig(CTRL . $config . '.ini'); } //Rodar o Controller/função $main->runController(\_cfg::$url); //Criando a visualização e enviando ao navegador do usuário \_view::produce(); return $main; }
/** * verifica se o charset é compatível com o usuário/browser */ function getCharset($c = '') { if ($c == '') { $c = \_cfg::this()->charset; } if (isset($_SERVER['HTTP_ACCEPT_CHARSET']) && strrpos(strtoupper($_SERVER['HTTP_ACCEPT_CHARSET']), strtoupper($c)) !== false) { return true; } else { return false; } }
/** * Procura por uma ajuda sobre o erro * * @param $nHelpCod number Código de erro interno * @return html Retorna uma ajuda sobre o erro atual ou uma string vazia se não existir */ protected function _errorGetHelp() { if ($this->classPath == null) { return ''; } //Definindo os caminhos $neos = strpos(PATH_NEOS, 'phar:') === false ? PATH_NEOS : dirname(str_replace('phar://', '', PATH_NEOS)); $app = strpos(PATH_APP, 'phar:') === false ? PATH_APP : dirname(str_replace('phar://', '', PATH_APP)); //Procurando os arquivos de help if (!\_cfg::this()->error['helpPath'] == '' && file_exists(\_cfg::this()->error['helpPath'])) { $dir = 'phar://' . trim(\_cfg::$error['helpPath'], ' /\\') . '/'; } elseif (file_exists(PATH . '/help.phar')) { $dir = 'phar://' . PATH . '/help.phar/'; } elseif (file_exists($neos . '/help.phar')) { $dir = 'phar://' . $neos . '/help.phar/'; } elseif (file_exists($app . '/help.phar')) { $dir = 'phar://' . $app . '/help.phar/'; } else { return ''; } $o = false; $x = explode('/', str_replace(array('\\', '/'), '/', strtolower($this->classPath))); for ($i = count($x); $i > 0; $i--) { $path = $dir . implode('/', $x) . '/error_' . $this->codigo . '.php'; if (file_exists($path)) { ob_start(); eval('?>' . file_get_contents($path)); $o = ob_get_clean(); break; } array_pop($x); } //checando se o arquivo foi encontrado - [não -> carrega o default] if (isset($o)) { return '<h2>Informações</h2> <div id="ajuda"> ' . $o . '</div>'; } return ''; }
function index() { o::go('inicialize'); _cfg::loadConfig('app'); exit(o::pt(_cfg::this())); }
/** * carrega os parametros de configuração */ private function _config() { $this->setup['db'] = ''; if (isset(\_cfg::this()->user)) { foreach (\_cfg::this()->user as $k => $v) { $this->setup[$k] = $v; } return true; } else { return false; } }
private function runController($url) { $url = strtolower($url); //definindo os valores default $ctrl = \_cfg::this()->ctrl; $func = \_cfg::this()->func; $args = \_cfg::this()->args; //pegando os elementos (controller/function/args) if ($url != '') { $uri = explode('/', $url); if (isset($uri[0])) { $ctrl = array_shift($uri); } //pegando o controller if (isset($uri[0])) { $func = array_shift($uri); } //pegando o método if (isset($uri[0])) { $args = $uri; } //pegando os dados } //controller $fctrl = CTRL . $ctrl . '.php'; //pegando os dados 'default' se o controller não existir if (!file_exists($fctrl)) { $ctrl = \_cfg::this()->ctrl; $func = \_cfg::this()->func; $args = \_cfg::this()->args; } //carregando o arquivo do controller include CTRL . $ctrl . '.php'; //instanciando a classe $ctrl = 'Controller_' . ucfirst($ctrl); $class = new $ctrl(); //definendo e chamando o método do controller if (is_callable(array($class, $func))) { call_user_func_array(array($class, $func), $args); } elseif (is_callable(array($class, \_cfg::this()->func))) { $func = \_cfg::this()->func; call_user_func_array(array($class, $func), $args); } else { exit('FATAL ERROR :: Método "' . \_cfg::this()->func . '" não existe'); } //atualizando os dados no config \_cfg::this()->ctrl = $ctrl; \_cfg::this()->func = $func; \_cfg::this()->args = $args; //retornando a instância do controller return $class; }