Example #1
0
 /**
  * Add a route
  *
  * @param string $name
  * @param string $path
  *
  * @return Route
  */
 public function route($name, $path)
 {
     $route = $this->routeFactory->build($name, $path);
     return $this->routes[$name] = $route;
 }
Example #2
0
        $this->contentBody = 'Hello World!';
    }
    public function addRoute($route, $callback)
    {
        $this->routes[$route] = $callback->bindTo($this, __CLASS__);
    }
    public function dispatch($endpoint)
    {
        foreach ($this->routes as $route => $callback) {
            if ($route === $endpoint) {
                $callback();
            }
        }
    }
}
$router = new RouteFactory();
$router->addRoute('show/me', function () {
    echo $this->contentType . ', ' . $this->contentBody;
});
$router->addRoute('show/him', function () {
    $this->contentType = 'html';
    $this->contentBody = '{"message": "Hello World!"}';
    echo $this->contentType . ', ' . $this->contentBody;
});
print_r($argv);
$router->dispatch($argv[1]);
$dt = new \DateTime();
$di = \DateInterval::createFromDateString('-1 week');
$dp = new \DatePeriod($dt, $di, 10);
foreach ($dp as $date) {
    # code...
Example #3
0
 public static function implementRouteGroup($group, $endpint, $namespace = "")
 {
     $obj = RouteFactory::fetchGroup($group);
     $obj->run($endpint);
 }
Example #4
0
<?php

defined('SYSPATH') or die('No direct script access.');
require SYSPATH . 'route' . EXT;
try {
    $_default = 'welcome';
    $_action = 'index';
    $route = RouteFactory::intance()->set('');
    $controller = APPPATH . 'controller' . DIRECTORY_SEPARATOR . $route['controller'];
    $action = $route['action'];
    if ($action == 'login' || $action == 'logout') {
        require $controller . DIRECTORY_SEPARATOR . 'index' . EXT;
        exit;
    }
    if ($route['controller'] == '') {
        $controller = $controller . $_default;
    }
    if ($action == '') {
        $action = $_action;
    }
    if (count($route) > 2) {
        $opt = $route['opt'];
        require $controller . DIRECTORY_SEPARATOR . $action . DIRECTORY_SEPARATOR . $opt . EXT;
    } else {
        if (is_dir($controller) && file_exists($controller . DIRECTORY_SEPARATOR . $action . EXT)) {
            require $controller . DIRECTORY_SEPARATOR . $action . EXT;
        } else {
            //@header('HTTP/1.1 404 Not Found');
            //@header('Location: /404.php');
            //die();
        }