public function color($str, $cor = 'Blue') { $color = ['Black' => '0;30', 'Red' => '0;31', 'Green' => '0;32', 'Brown' => '0;33', 'Blue' => '0;34', 'Purple' => '0;35', 'Cyan' => '0;36']; $cor = Inflector::camelize($cor); if (empty($color[$cor])) { $cor = 'Black'; } $str = var_export($str, true); $this->out("[" . $color[$cor] . "m" . $str . "[0m"); }
/** * * Adiciona um helper * * @param string|array $class */ public function addHerper($class) { $default = ['nome' => '', 'class' => '']; if (!is_array($class)) { $class = ['nome' => $class, 'class' => '']; } $class = \Core\Hash::merge($default, $class); $class['nome'] = Inflector::camelize(Inflector::underscore($class['nome'])); $class['class'] = Inflector::camelize(Inflector::underscore(str_replace('Helper', '', $class['class']))) . 'Helper'; self::$_helpers[$class['nome']] = $class; }
public static function write($msg, $level = 'error') { $level = strtoupper(Inflector::camelize($level)); $diretorio = ROOT . 'src/tmp/logs/'; $filepath = $diretorio . 'log-' . $level . '-' . date('Y-m-d') . '.log'; $r = new Request(); $msg = var_export($msg, true); $message = ['Nivel: ' . $level, 'Time: ' . date('H:i:s'), 'Path: ' . implode('/', $r->path), 'Uri: ' . implode('/', $r->uri), 'Data: ' . print_r($r->data, true), 'Params: ' . implode('/', $r->params), 'Query: ' . print_r($r->query, true), $msg]; $message = implode("\n", $message) . "\n\n"; if (!($fp = @fopen($filepath, FOPEN_WRITE_CREATE))) { return FALSE; } flock($fp, LOCK_EX); fwrite($fp, $message); flock($fp, LOCK_UN); fclose($fp); @chmod($filepath, FILE_WRITE_MODE); return TRUE; }
/** * Executa as chamadas dos dados referente as informações vido da navegação. */ public function run() { $this->controller = $this->request->controller; $this->action = $this->request->action; if (!isset($this->uri)) { $this->uri = []; } else { $this->uri = array_slice($this->uri, 2); } $path = ''; if (count($this->path) > 0) { $path = implode('\\', $this->path); if (trim($path) != '') { $path = Inflector::camelize($path) . '\\'; } } $controller = 'App\\Controller\\' . $path . $this->controller . 'Controller'; $class_name = ROOT . str_replace('\\', DS, $controller) . '.php'; $class_name = str_replace(DS . 'App' . DS, DS . 'src' . DS, $class_name); if (!file_exists($class_name)) { $ex = new \Core\MyException(); $ex->layout = 'default'; $ex->show_404('pagina não localizada.'); } else { $controller = new $controller($this->request, new Session(), new Auth()); $action = $this->action; call_user_func_array([$controller, 'beforeController'], $this->uri); if (method_exists($controller, $action)) { call_user_func_array([$controller, $action], $this->uri); } else { call_user_func_array([$controller, '_error'], $this->uri); } call_user_func_array([$controller, 'afterController'], $this->uri); call_user_func_array([$controller, 'beforeRender'], $this->uri); $controller->render(); } }
/** * * cria uma url para chamar um arquivo CSS * * @param string $url * @param array $options * @return string */ public function image($url, $options = []) { $id = 'img-' . \Core\Inflector::underscore(\Core\Inflector::camelize(str_replace('/', '/', $url))); $default = ['src' => $this->request->url($url), 'alt' => '', 'title' => '', 'id' => $id]; return $this->tags('img', \Core\Hash::merge($default, $options), false); }
public function prepareUrl($url) { $defautl = ['action' => $this->action, 'controller' => $this->controller, 'path' => $this->path, 'params' => '', 'query' => []]; $url = array_merge($defautl, $url); if (!empty($url['path'])) { if (is_array($url['path'])) { foreach ($url['path'] as $key => $value) { $url['path'][$key] = Inflector::underscore(Inflector::camelize($value)); } } else { $url['path'] = Inflector::underscore(Inflector::camelize($url['path'])); } } if (!empty($url['params'])) { foreach ($url['params'] as $key => $value) { $url['params'][$key] = Inflector::slug($value); } } $oldUrl = $url; unset($oldUrl['action'], $oldUrl['controller'], $oldUrl['path'], $oldUrl['params'], $oldUrl['query'], $oldUrl['?']); if (!empty($oldUrl)) { //$url['params'] = array_merge($url['params'], $oldUrl); foreach ($oldUrl as $key => $value) { unset($url[$key]); $url['params'][$key] = $value; } } if (!empty($url['?'])) { $url['query'] = Hash::merge($url['query'], $url['?']); unset($url['?']); } $_url = []; if (!empty($url['path'])) { if (is_array($url['path'])) { $_url['path'] = implode('/', $url['path']); } else { $_url['path'] = $url['path']; } } if (!empty($url['controller'])) { $_url['controller'] = Inflector::underscore($url['controller']); } if (!empty($url['action'])) { $_url['action'] = Inflector::underscore($url['action']); } if (!empty($url['params']) and is_array($url['params'])) { $_url['params'] = implode('/', $url['params']); } if (!empty($url['query']) and is_array($url['query'])) { $_url['query'] = '?' . http_build_query($url['query']); } return $_url; }