Beispiel #1
0
 /**
  * Loads a PHP file (if it exists) using the autoload configuration
  *
  * @param string $className
  *            Name of the class to load
  * @return boolean
  */
 public function load($className)
 {
     $config = \Videogames\Config::get('autoload');
     $file = $config['class_path'] . '/' . str_replace("\\", "/", $className) . '.php';
     if (file_exists($file)) {
         require $file;
     } else {
         return false;
     }
 }
Beispiel #2
0
 /**
  * Checks a given route and loads the proper controller if
  * there is one.
  * Will 'generate' an error if not.
  *
  * @param unknown $route
  *            A route from a redirected URL that may contain some optional variables
  */
 public function start($route)
 {
     $this->config = \Videogames\Config::get('routes');
     if (empty($route) || $route == '/') {
         if (isset($this->config['default'])) {
             $route = $this->config['default'];
         } else {
             $this->error(1);
         }
     }
     try {
         foreach ($this->config['routes'] as $path => $defaults) {
             $regex = '@' . preg_replace('@:([\\w]+)@', '(?P<$1>[^/]+)', str_replace(')', ')?', (string) $path)) . '@';
             $matches = [];
             if (preg_match($regex, $route, $matches)) {
                 $options = $defaults;
                 foreach ($matches as $key => $value) {
                     if (is_numeric($key)) {
                         continue;
                     }
                     $options[$key] = $value;
                     if (isset($defaults[$key])) {
                         if (strpos($defaults[$key], ":{$key}") !== false) {
                             $options[$key] = str_replace(":{$key}", $value, $defaults[$key]);
                         }
                     }
                 }
                 if (isset($options['controller']) && isset($options['action'])) {
                     $callable = [$options['controller'], $options['action'] . 'Action'];
                     if (is_callable($callable)) {
                         $callable = [new $options['controller'](), $options['action'] . 'Action'];
                         $callable($options);
                         return;
                     } else {
                         $this->error(2);
                     }
                 } else {
                     $this->error(3);
                 }
             }
         }
     } catch (\Videogames\Controller\Exception $e) {
         $this->error(4);
     }
 }
Beispiel #3
0
 /**
  * Get configuration info and create a Template instance
  */
 public function __construct()
 {
     $this->config = \Videogames\Config::get('site');
     $this->template = new \Videogames\Template($this->config['view_path'] . "/base.phtml");
 }
Beispiel #4
0
Datei: Db.php Projekt: pko22/vgs
 /**
  * Will connect to configurated database using PDO
  */
 protected function __construct()
 {
     $config = \Videogames\Config::get('database');
     $this->connection = new \PDO("mysql:host=" . $config['hostname'] . ";dbname=" . $config['dbname'], $config['username'], $config['password']);
     $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
 }
Beispiel #5
0
<?php

/**
 * Initiate configuration
 */
require_once '../src/Videogames/Config.php';
\Videogames\Config::setDirectory('../config');
/**
 * Configure and start the Autoloader
 */
$config = \Videogames\Config::get('autoload');
require_once $config['class_path'] . '/Videogames/Autoloader.php';
/**
 * Get a route to pass on to the Router
 */
$route = null;
// optional use $_GET['route']
if (isset($_SERVER['REDIRECT_URL'])) {
    $route = $_SERVER['REDIRECT_URL'];
}
/**
 * Start the Router
 */
$router = new \Videogames\Router();
$router->start($route);