ref: master
config/routes.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
<?php // TODO: Usar um autoload aqui require_once '../app/controllers/HelloController.php'; require_once '../app/controllers/AuthController.php'; require_once '../app/controllers/DashboardController.php'; require_once '../app/controllers/BillsController.php'; require_once '../app/controllers/TagsController.php'; require_once '../app/controllers/IncomesController.php'; return function() { $uri = explode('?', trim($_SERVER['REQUEST_URI'], '/'))[0]; $method = $_SERVER['REQUEST_METHOD']; // TODO: Meio burro isso if ($uri === '') { return (new HelloController())->index(); // POST /login } elseif ($uri === 'login' && $method === 'POST') { return (new AuthController())->login(); // GET /login } elseif ($uri === 'login') { return (new HelloController())->login(); // POST /register } elseif ($uri === 'register' && $method === 'POST') { return (new AuthController())->register(); // GET /register } elseif ($uri === 'register') { return (new HelloController())->register(); // GET /dashboard } elseif ($uri === 'dashboard') { return (new DashboardController())->index(); // GET /bills } elseif ($uri === 'bills' && $method === 'GET') { return (new BillsController())->index(); // GET /bills/create } elseif ($uri === 'bills/create' && $method === 'GET') { return (new BillsController())->create(); // POST /bills/create } elseif ($uri === 'bills/create' && $method === 'POST') { return (new BillsController())->store(); // GET /bills/edit/{id} } elseif (preg_match('/^bills\/edit\/(\d+)$/', $uri, $matches) && $method === 'GET') { return (new BillsController())->edit($matches[1]); // POST /bills/edit/{id} } elseif (preg_match('/^bills\/edit\/(\d+)$/', $uri, $matches) && $method === 'POST') { return (new BillsController())->update($matches[1]); // GET /bills/delete/{id} } elseif (preg_match('/^bills\/delete\/(\d+)$/', $uri, $matches) && $method === 'GET') { return (new BillsController())->destroy($matches[1]); // GET /tags } elseif ($uri === 'tags' && $method === 'GET') { return (new TagsController())->index(); // GET /tags/create } elseif ($uri === 'tags/create' && $method === 'GET') { return (new TagsController())->create(); // POST /tags/create } elseif ($uri === 'tags/create' && $method === 'POST') { return (new TagsController())->store(); // GET /tags/edit/{id} } elseif (preg_match('/^tags\/edit\/(\d+)$/', $uri, $matches) && $method === 'GET') { return (new TagsController())->edit($matches[1]); // POST /tags/edit/{id} } elseif (preg_match('/^tags\/edit\/(\d+)$/', $uri, $matches) && $method === 'POST') { return (new TagsController())->update($matches[1]); // GET /tags/delete/{id} } elseif (preg_match('/^tags\/delete\/(\d+)$/', $uri, $matches) && $method === 'GET') { return (new TagsController())->destroy($matches[1]); // GET /incomes } elseif ($uri === 'incomes' && $method === 'GET') { return (new IncomesController())->index(); // GET /incomes/create } elseif ($uri === 'incomes/create' && $method === 'GET') { return (new IncomesController())->create(); // POST /incomes/create } elseif ($uri === 'incomes/create' && $method === 'POST') { return (new IncomesController())->store(); // GET /incomes/edit/{id} } elseif (preg_match('/^incomes\/edit\/(\d+)$/', $uri, $matches) && $method === 'GET') { return (new IncomesController())->edit($matches[1]); // POST /incomes/edit/{id} } elseif (preg_match('/^incomes\/edit\/(\d+)$/', $uri, $matches) && $method === 'POST') { return (new IncomesController())->update($matches[1]); // GET /incomes/delete/{id} } elseif (preg_match('/^incomes\/delete\/(\d+)$/', $uri, $matches) && $method === 'GET') { return (new IncomesController())->destroy($matches[1]); // GET /logout } elseif ($uri === 'logout') { return (new AuthController())->logout(); } http_response_code(404); return '404 Not Found'; }; |