示例#1
0
<?php

ini_set('display_errors', 1);
require __DIR__ . '/../config/autoload.php';
use Phroute\Phroute\RouteCollector;
use Phroute\Phroute\Dispatcher;
$router = new RouteCollector();
$router->any('/', ['wolfram\\Controllers\\IndexController', 'actionIndex']);
$router->any('create-tables', ['wolfram\\Controllers\\CreateTablesController', 'actionIndex']);
$router->any('vendor/create', ['wolfram\\Controllers\\VendorController', 'actionCreate']);
$router->any('vendor/update/{id}', ['wolfram\\Controllers\\VendorController', 'actionUpdate']);
$router->any('vendor/delete/{id}', ['wolfram\\Controllers\\VendorController', 'actionDelete']);
$router->any('vendor/view-transports/{id}', ['wolfram\\Controllers\\VendorController', 'actionViewTransports']);
$router->any('properties/create', ['wolfram\\Controllers\\PropertiesController', 'actionCreate']);
$router->any('properties/update/{id}', ['wolfram\\Controllers\\PropertiesController', 'actionUpdate']);
$router->any('properties/delete/{id}', ['wolfram\\Controllers\\PropertiesController', 'actionDelete']);
$router->any('transport/create', ['wolfram\\Controllers\\TransportController', 'actionCreate']);
$router->any('transport/update/{id}', ['wolfram\\Controllers\\TransportController', 'actionUpdate']);
$router->any('transport/delete/{id}', ['wolfram\\Controllers\\TransportController', 'actionDelete']);
$router->any('transport/delete-property/{id_transport}/{id_properties}', ['wolfram\\Controllers\\TransportController', 'actionDeleteProperty']);
$router->any('transport/add-property', ['wolfram\\Controllers\\TransportController', 'actionAddProperty']);
$dispatcher = new Dispatcher($router->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
示例#2
0
<?php

use Phroute\Phroute\RouteCollector;
require __DIR__ . '/config.php';
require __DIR__ . '/./vendor/autoload.php';
$router = new RouteCollector();
$router->get('/{id}', function ($id) {
    $shorts_path = __DIR__ . '/shorts/' . $id . '.php';
    if (file_exists($shorts_path)) {
        header("Status: 200 OK", false, 200);
        require $shorts_path;
        die;
    } else {
        header('Bad Request', true, 404);
        header('Content-Type: application/json');
        echo json_encode(array('error' => "Le shortcut {$id} n'existe pas."));
    }
});
// $router->get('/cut/{url:(http\:\/\/)?[a-zA-Z0-9+_\-\.]+\.[a-zA-Z]{2,3}}', function($uri){
//   require(__DIR__ . '/shorten.php');
// });
// $router->get('/cut/{url}/{shortid}', function($uri, $short_id){
//   require(__DIR__ . '/shorten.php');
// });
$router->any('/', function () {
    return 'Hello :) ';
});
$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
echo $response;
示例#3
0
 public function getDispatcher()
 {
     static $dispatcher;
     if ($dispatcher) {
         return $dispatcher;
     }
     $routes = (include $this->config['config'] . '/routes.php');
     //TODO: Check if routes have been cached
     if (true) {
         $collector = new RouteCollector();
         foreach ($routes as $left => $right) {
             // $left is something like 'GET /'
             // $right is a callable
             $left = explode(" ", $left);
             if (sizeof($left) === 2) {
                 switch ($left[0]) {
                     case 'GET':
                         $collector->get($left[1], $right);
                         break;
                     case 'POST':
                         $collector->post($left[1], $right);
                         break;
                     case 'ANY':
                         $collector->any($left[1], $right);
                         break;
                     case 'HEAD':
                         $collector->head($left[1], $right);
                         break;
                     case 'OPTIONS':
                         $collector->options($left[1], $right);
                         break;
                     case 'DELETE':
                         $collector->delete($left[1], $right);
                         break;
                     default:
                         throw new ConfigException("Don't understand the HTTP method '" . $left[0] . "' in routes.php.");
                 }
             }
         }
         $routeData = $collector->getData();
     }
     return $dispatcher = new Dispatcher($routeData, $this->getHandlerResolver());
 }