/** * show. * * @return string anchor element */ public function show() { if ($this->src == '#') { $src = '#'; } else { $src = !preg_match('#^\\w+\\:\\/\\/#', $this->src) ? Configure::siteurl($this->src) : $this->src; } $text = empty($this->text) ? $src : $this->text; $title = empty($this->title) ? $text : $this->title; if ($this->autoActive === true) { if ($href == Request::currenturl()) { $this->addAttr('class', 'active'); } } $this->addAttr('title', $title)->addAttr('href', $src); return "<a{$this->htmlAttribute}>{$text}</a>"; }
/** * redirect. * * @param string dynamic/static url * * @return string fixed url */ public static function redirect($target) { $url = !preg_match('#^\\w+\\:\\/\\/#', $target) ? Configure::siteurl($target) : $target; if (!headers_sent()) { header("Location: {$url}"); exit; } printf('<script type="text/javascript">window.location.href = "%s";</script>', $url); }
/** * setConnection. * * @param string group name * @param string|array config */ public static function setConnection($group, $params = array()) { if (self::hasConnection($group)) { return false; } $class = '\\App\\Drivers\\DB\\' . implode('', array_map('ucfirst', explode('-', $group))); if (class_exists($class)) { try { $check = new ReflectionClass($class); if (!$check->implementsInterface('\\Viloveul\\Database\\IConnection')) { throw new Exception('Database driver must implement of \\Viloveul\\Database\\IConnection'); } self::$connections[$group] = $check->newInstance(); } catch (ReflectionException $e) { throw new Exception($e->getMessage()); } } else { $config = Configure::read('db', function ($value) use($group, $params) { return isset($value[$group]) ? $value[$group] : $params; }); $dbconf = self::parseConfiguration($config); extract($dbconf); self::$connections[$group] = new Database\Manager($dsn, $username, $password, $prefix); } }
/** * run * execute or running the application. */ public function run() { $this->dispatcher->dispatch(Http\Request::createFromGlobals(), Configure::read('url_suffix')); $handler = $this->dispatcher->fetchHandler(); if (empty($handler)) { throw new Exception('handler does not found'); } try { $reflection = new ReflectionFunction($handler); $output = $reflection->invoke($this->dispatcher->fetchParams()); $this->response->send($output); } catch (ReflectionException $e) { Debugger::handleException($e); } }
/** * currenturl. * * @return bool */ public static function currenturl() { $uriString = self::parseRequestUri(); $query = Configure::server('query_string'); return empty($query) ? Configure::siteurl($uriString) : Configure::siteurl("/{$uriString}?{$query}"); }
/** * printScript. * * @param string source id * @param string|array dependency(s) * @param string type * * @return bool */ public static function printScript($id, $type = 'js') { $key = "{$id}-{$type}"; if (!isset(self::$registeredSources[$key])) { return; } extract(self::$registeredSources[$key]); if (isset($dependencies) && !empty($dependencies)) { foreach ($dependencies as $dependency_id) { self::printScript($dependency_id, $type); } } self::load($type, $id, $source); return true; $format = $type == 'css' ? '<link rel="stylesheet" type="text/css" id="%s" href="%s" />' : '<script type="text/javascript" id="%s" src="%s"></script>'; printf("{$format}\n", $key, sprintf($source, rtrim(Configure::baseurl(), '/'))); return true; }