/** * Returns a log trace. * Can be used for a exception page. * @return string */ public static function getTrace() { $traceString = ""; if (self::$instance != null) { $traceString = self::$instance->getTraceString(); } return $traceString; }
/** * Loads the given configs into \Pvik\Core\Config. * @param array $configPaths * @return \Pvik\Core\Core */ public function loadConfig(array $configPaths) { foreach ($configPaths as $configPath) { Config::load(Path::realPath($configPath)); } Log::writeLine('[Info] Loaded: ' . implode(",", $configPaths)); return $this; }
/** * Executes a statement. * @param string $queryString * @return mixed */ public function execute($queryString) { Log::writeLine('Executing querystring: ' . $queryString); $result = mysql_query($queryString); if (!$result) { throw new \Exception('Could not execute following statement: ' . $queryString . "\n" . 'MySQLError: ' . mysql_error()); } return $result; }
/** * * @param string $viewPath * @param Controller $controller */ public function __construct($viewPath, Controller $controller) { $this->contents = new KeyValueArray(); $this->viewPath = $viewPath; $this->controller = $controller; $this->viewData = $this->controller->getViewData(); $this->helper = new \Pvik\Web\ViewHelpers\HtmlHelper(); $this->executePartialCode($this->viewPath); if ($this->masterPagePath != null) { Log::writeLine('Executing masterpage: ' . $this->masterPagePath); $baseMasterPage = new MasterPage($this->realPath($this->masterPagePath), $this); } }
/** * Execute a action from a controller. * @param string $controllerName * @param string $actionName * @param KeyValueArray $parameters */ public static function executeController($controllerName, $actionName, Request $request) { $controllerClassName = $controllerName; if ($controllerClassName[0] !== '\\') { $controllerClassName = Config::$config['DefaultNamespace'] . Config::$config['DefaultNamespaceControllers'] . '\\' . $controllerClassName; } $controllerInstance = new $controllerClassName($request, $controllerName); /* @var $controllerInstance \Pvik\Web\Controller */ $actionFunctionName = $actionName . 'Action'; if (method_exists($controllerInstance, $actionFunctionName)) { Log::writeLine('Executing action: ' . $actionFunctionName); $controllerInstance->setCurrentActionName($actionName); // execute action $controllerInstance->{$actionFunctionName}(); } else { throw new \Exception('Action doesn\'t exists: ' . $controllerClassName . '->' . $actionFunctionName); } }
/** * Tries to load a class. * @param String $class */ protected function loadClass($class) { if ($class[0] !== '\\') { $class = '\\' . $class; } $name = $class; foreach ($this->getNamespaceAssociationList() as $namespace => $path) { if (strpos($name, $namespace . '\\') === 0) { // starts with $name = str_replace($namespace, $path, $name); break; } } $path = str_replace('\\', '/', $name); $path = str_replace('//', '/', $path); $path = Path::realPath($path . '.php'); if (file_exists($path)) { require $path; if (class_exists('\\Pvik\\Core\\Log')) { Log::writeLine('[Include] ' . $path); } return true; } }
/** * Checks if a url matches with an route. * @param string $orignalUrl * @param array $route * @return bool */ protected function urlIsMatching($orignalUrl, $route) { $routeUrl = $route['Url']; if ($routeUrl == '*' || strtolower($orignalUrl) == $routeUrl) { $request = new Request(); $request->setRoute($route); $request->setUrl($orignalUrl); return $request; } elseif (strpos($routeUrl, '{') !== false && strpos($routeUrl, '}') !== false) { // contains a variable $routeUrlParts = explode('/', $routeUrl); $orignalUrlParts = explode('/', $orignalUrl); // have the same part length if (count($routeUrlParts) == count($orignalUrlParts)) { for ($index = 0; $index < count($routeUrlParts); $index++) { if (strlen($routeUrlParts[$index]) >= 3 && $routeUrlParts[$index][0] == '{') { // it's a variable $key = substr($routeUrlParts[$index], 1, -1); if (isset($route['Parameters'][$key]) && !preg_match($route['Parameters'][$key], $orignalUrlParts[$index])) { return null; } } else { if (strtolower($routeUrlParts[$index]) != $orignalUrlParts[$index]) { // not matching return null; } } } Log::writeLine('Route matching: ' . $route['Url']); $request = new Request(); $request->setRoute($route); $request->setUrl($orignalUrl); // matching successfull // save url parameter for ($index = 0; $index < count($routeUrlParts); $index++) { if (strlen($routeUrlParts[$index]) >= 3 && $routeUrlParts[$index][0] == '{') { // it's a variable // the key is the name between the brakets $key = substr($routeUrlParts[$index], 1, -1); // add to url parameters $request->getParameters()->add($key, $orignalUrlParts[$index]); if (isset($route['Parameters'][$key])) { Log::writeLine('Url parameter: ' . $key . ' -> ' . $route['Parameters'][$key] . ' -> ' . $orignalUrlParts[$index]); } else { Log::writeLine('Url parameter: ' . $key . ' -> ' . $orignalUrlParts[$index]); } } } return $request; } } return null; }
/** * Redirects to another controllers action with passing the original parameters. * @param string $controllerName * @param string $actionName */ protected function redirectToController($controllerName, $actionName, Request $request = null) { if ($request == null) { $request = $this->request; } Log::writeLine('Redirecting to controller: ' . $controllerName); Log::writeLine('Redirecting to action: ' . $actionName); ControllerManager::executeController($controllerName, $actionName, $request); }
<div id="message"><?php echo nl2br($Exception->getMessage()); ?> </div> <span>File:</span> <div id="file">File <?php echo $Exception->getFile(); ?> at line <?php echo $Exception->getLine(); ?> </div> <span>Stacktrace:</span> <div id="stacktrace"><?php echo nl2br($Exception->getTraceAsString()); ?> </div> <span>Logtrace:</span> <div id="logtrace"><?php echo nl2br(\Pvik\Core\Log::GetTrace()); ?> </div> <span>Code:</span> <div id="code"><?php echo nl2br($Exception->getCode()); ?> </div> </div> </body> </html>