示例#1
0
文件: Log.php 项目: roccosportal/pvik
 /**
  * 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;
 }
示例#2
0
 /**
  * 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;
 }
示例#3
0
 /**
  * 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;
 }
示例#4
0
 /**
  *
  * @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);
     }
 }
示例#5
0
 /**
  * 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);
     }
 }
示例#6
0
 /**
  * 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;
     }
 }
示例#7
0
 /**
  * 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;
 }
示例#8
0
 /**
  * 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);
 }
示例#9
0
            <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>