Open gabrybarr opened 2 years ago
Can you try using exceptions to check these problems?
try {
$response = (new Dispatcher($collector->getData()))->dispatch(
$_SERVER['REQUEST_METHOD'],
implode('/', array_slice(explode('/', $_SERVER['REQUEST_URI']), 0))
);
echo($response);
} catch (HttpRouteNotFoundException $e) {
echo($e->getMessage());
} catch (HttpMethodNotAllowedException $e) {
echo($e->getMessage());
}
$collector = new Phroute\Phroute\RouteCollector();
$collector->get('/', function(){ echo 'Home Page'; });
$collector->post('products', function(){ return 'Create Product'; });
$collector->put('items/{id}', function($id){ return 'Amend Item ' . $id; });
$dispatcher = new Phroute\Phroute\Dispatcher($collector->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
// Print out the value returned from the dispatched function echo $response;
i have this code But it restores me this error. How can i solve it?
Fatal error: Uncaught Error: Class 'Phroute\Phroute\HttpRouteNotFoundException' not found in /var/www/html/gab/kiosk-mvc/Phroute/Dispatcher.php:222 Stack trace: #0 /var/www/html/gab/kiosk-mvc/Phroute/Dispatcher.php(127): Phroute\Phroute\Dispatcher->dispatchVariableRoute() #1 /var/www/html/gab/kiosk-mvc/Phroute/Dispatcher.php(51): Phroute\Phroute\Dispatcher->dispatchRoute() #2 /var/www/html/gab/kiosk-mvc/index.php(59): Phroute\Phroute\Dispatcher->dispatch() #3 {main} thrown in /var/www/html/gab/kiosk-mvc/Phroute/Dispatcher.php on line 222