Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Class not found #104

Open
gabrybarr opened this issue Jul 8, 2022 · 1 comment
Open

Error Class not found #104

gabrybarr opened this issue Jul 8, 2022 · 1 comment

Comments

@gabrybarr
Copy link

$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

@Sleon4
Copy link

Sleon4 commented Apr 6, 2023

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());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants