Ejemplo n.º 1
0
 protected function __construct()
 {
     if ($_SERVER['SERVER_NAME'] == 'localhost') {
         $config = \Bovinetracker\Config::get('database_test');
     } else {
         $config = \Bovinetracker\Config::get('database_prod');
     }
     $this->connection = new \PDO($config['dsn'], $config['username'], $config['password']);
 }
Ejemplo n.º 2
0
 public function start($route)
 {
     $this->config = \Bovinetracker\Config::get('routes');
     if (empty($route) || $route == '/') {
         if (isset($this->config['default'])) {
             $route = $this->config['default'];
         } else {
             $this->error($e->getMessage());
         }
     }
     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('Page not found.');
                     }
                 } else {
                     $this->error('Page not found.');
                 }
             }
         }
     } catch (\Bovinetracker\Controller\Exception $e) {
         $this->error($e->getMessage());
     }
 }
Ejemplo n.º 3
0
 public function __construct()
 {
     $this->config = \Bovinetracker\Config::get('site');
     $this->template = new \Bovinetracker\Template($this->config['view_path'] . "/base.phtml");
 }
Ejemplo n.º 4
0
<?php

//8-9-2015, Houston Giles
//Bovine Tracker
require '../vendor/autoload.php';
\Bovinetracker\Config::setDirectory('../config');
$route = null;
if (isset($_SERVER['REQUEST_URI'])) {
    $route = $_SERVER['REQUEST_URI'];
}
//Include the following to see what server variables are available.
// include 'indices.php';
// exit;
$router = new \Bovinetracker\Router();
$router->start($route);