Exemple #1
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $_SERVER['REQUEST_METHOD'] = 'GET';
     router::route('/blog/:arg', function ($arg) {
         echo 'Argument: ' . $arg;
     }, 'GET', 'blog');
     router::route('/blog/*', function () {
         echo 'CatchAll';
     });
     router::route('/blog/arg', function () {
         echo 'NoArg';
     });
     router::route('/test.php', function () {
         echo 'test.php';
     });
     router::route('/proiecs/aed[]te\\*', function () {
         echo '/proiecs/aed[]te\\*';
     });
     router::route('/proiecs/:ala/bala/:korhaz/:edit/:buha', function ($arg1, $arg2, $arg3) {
         echo 'proiecs ' . $arg1 . $arg2 . $arg3;
     }, 'GET', 'proiecs');
     router::route('/proiecs/asfv', function () {
         echo '/proiecs/asfv/';
     });
     router::route(' /infinity', function () {
         echo 'infinity';
     }, 'GET', 'infinity');
     router::route('/infinity/ourubors/ternary', function () {
         echo '/infinity/ourubors/ternary';
     }, 'GET', 'infinity2');
     router::set('BASE', 'framework');
 }
Exemple #2
0
 public static function run()
 {
     spl_autoload_register(__CLASS__ . "::" . 'autoload');
     if (app_config::$use_db == true) {
         db::set_db_config(app_config::$db);
     }
     url::init(app_config::$url);
     router::route(app_config::$router, app_config::$re_route);
 }
Exemple #3
0
 static function findroute()
 {
     $vars = array();
     $elts = array();
     router::$url = str_replace(_URL_ . '/', '', 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI']);
     foreach (router::$routes as $name => &$route) {
         if (preg_match($route['route'], router::$url)) {
             router::$route = $name;
             if (preg_match($route['route'], router::$url, $vars)) {
                 foreach ($vars as $k => $v) {
                     if (!is_numeric($k)) {
                         $elts[$k] = $v;
                     }
                 }
             }
             // si des droits on étais définis dans le router
             if (isset($route['rights'])) {
                 if (is_array($route['rights'])) {
                     // on contrôle si REQUEST_METHOD existe
                     if (isset($_SERVER['REQUEST_METHOD'])) {
                         $requestMethod = $_SERVER['REQUEST_METHOD'];
                         if (isset($route['rights'][$requestMethod])) {
                             $rights = $route['rights'][$requestMethod];
                         } else {
                             trigger_error("methode " . $requestMethod . " invalide", E_USER_ERROR);
                         }
                     } else {
                         trigger_error("REQUEST_METHOD obligatoire", E_USER_ERROR);
                     }
                 } else {
                     $rights = $route['rights'];
                 }
             } else {
                 $rights = false;
             }
             if (isset($route['module'])) {
                 router::CallController($route['module'], $elts, $rights);
             }
             if (isset($route['redirect'])) {
                 router::Redirect($route['redirect']);
             }
             break;
         }
     }
 }
Exemple #4
0
 public function __construct()
 {
     /**
      * Get the database and set the config
      */
     $db = new database();
     $db->setup($a = array('hostname' => 'localhost', 'username' => 'govhack', 'password' => 'govhack', 'database' => 'govhack_ip'))->connect();
     /**
      * Load the page controllers
      */
     $search = new search($db);
     $index = new index();
     $about = new about();
     /**
      * Get the application router
      */
     $router = new router();
     $router->add('/', $index)->add('/index', $index)->add('/about', $about)->add('/search', $search)->add('/*', $search);
     $router->route();
 }
Exemple #5
0
    private static $method;
    private static $params;
    public static function route()
    {
        self::$URI = isset($_SERVER['REDIRECT_URL']) ? explode('/', $_SERVER['REDIRECT_URL']) : NULL;
        self::$class = isset(self::$URI[URI_Level + 0]) ? self::$URI[URI_Level + 0] : 'main';
        self::$method = isset(self::$URI[URI_Level + 1]) ? self::$URI[URI_Level + 1] : 'index';
        $file_path = 'controllers/' . self::$class . '.php';
        if (!file_exists($file_path)) {
            self::$method = self::$class;
            self::$class = 'main';
            self::$params = isset(self::$URI[URI_Level + 1]) ? array_slice(self::$URI, URI_Level + 1) : array();
        } else {
            self::$params = isset(self::$URI[URI_Level + 2]) ? array_slice(self::$URI, URI_Level + 1) : array();
        }
        $file_path = 'controllers/' . self::$class . '.php';
        include_once $file_path;
        if (!method_exists(self::$class, self::$method)) {
            //echo '404';
            //echo self::$class, self::$method;
            show_404();
        }
        //Static Way
        //call_user_func_array(array(self::$class,self::$method),self::$params);
        //Normal?
        $class = new self::$class();
        call_user_func_array(array($class, self::$method), self::$params);
    }
}
router::route();
Exemple #6
0
 /**
  * @see router::route
  */
 public static function route($pattern, $funcs, $http = 'GET', $name = FALSE)
 {
     if (!class_exists('router', FALSE)) {
         include_once 'router.php';
     }
     router::route($pattern, $funcs, $http, $name);
 }
<?php

/**
 * miniJSON
 * - a very super simple, basic json php framework.
 */
error_reporting(E_ALL);
// New app
require 'app.php';
$app = new App();
// Set doc root
$root = '/miniJSONApp/miniJSON';
// Prod
$root = '/angularjs-crud-test/miniJSON';
// Dev
// Init routes, create router and route
require 'routes.php';
require 'router.php';
$router = new router($app, $root, $routes);
$router->route();