aggiunto controllo sul metodo post in modo da non poter raggiungere la route destroy utilizzando il get (parte 144)
| | |
| | | $router->add("/{controller}/{id:\d}/edit", ["action"=> "edit"]); |
| | | $router->add("/{controller}/{id:\d}/update", ["action"=> "update"]); |
| | | $router->add("/{controller}/{id:\d}/delete", ["action"=> "delete"]); |
| | | $router->add("/{controller}/{id:\d}/destroy", ["action"=> "destroy"]); |
| | | $router->add("/{controller}/{id:\d}/destroy", ["action"=> "destroy", "method" => "post"]); |
| | | |
| | | |
| | | $router->add("/home/index", ["controller" => "home", "action" => "index"]); |
| | |
| | | |
| | | $dispatcher = new Framework\Dispatcher($router, $container); |
| | | |
| | | $dispatcher->handle($path); |
| | | $dispatcher->handle($path, $_SERVER["REQUEST_METHOD"]); |
| | | |
| | |
| | | public function __construct(private Router $router, |
| | | private Container $container) { } |
| | | |
| | | public function handle(string $path) { |
| | | $params = $this->router->match($path); |
| | | public function handle(string $path, $method) { |
| | | $params = $this->router->match($path, $method); |
| | | |
| | | if($params === false) { |
| | | throw new PageNotFoundException("No route matched for '$path'"); |
| | | throw new PageNotFoundException("No route matched for '$path' with method '$method'"); |
| | | } |
| | | |
| | | $controller = "App\Controllers\\" . ucwords($params["controller"]); |
| | |
| | | |
| | | |
| | | } |
| | | public function match (string $path): array|bool { |
| | | public function match (string $path, string $method): array|bool { |
| | | $path = urldecode($path); |
| | | |
| | | $path = trim($path, "/"); |
| | |
| | | |
| | | $params = array_merge($matches, $route["params"]); |
| | | |
| | | if(array_key_exists("method", $params)) { |
| | | if(strtolower($method) !== strtolower($params["method"])) { |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | return $params; |
| | | } |
| | | } |