index.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. require_once __DIR__.'/../vendor/autoload.php';
  3. /*
  4. * Carga variables de entorno
  5. * desde el archivo .env
  6. */
  7. $dotenv = \Dotenv\Dotenv::createImmutable(dirname(__DIR__));
  8. $dotenv->load();
  9. /*
  10. * Establece opciones de configuración.
  11. */
  12. $config = [
  13. 'userClass' => \App\Models\UserModel::class,
  14. 'db' => [
  15. 'dsn' => $_ENV['DB_DSN'],
  16. 'username' => $_ENV['DB_USERNAME'],
  17. 'password' => $_ENV['DB_PASSWORD'],
  18. ],
  19. ];
  20. /*
  21. * Crea una instancia de la aplicación.
  22. */
  23. $app = new \App\Core\Application(dirname(__DIR__), $config);
  24. //$app->router->get('/', function () {
  25. // return 'Página principal';
  26. //});
  27. //$app->router->get('/', 'home');
  28. //$app->on(\App\Core\Application::EVENT_BEFORE_REQUEST, function () {
  29. // echo 'Ejecución de un evento antes de la petición.';
  30. //});
  31. //$app->on(\App\Core\Application::EVENT_AFTER_REQUEST, function () {
  32. // echo 'Ejecución de un evento después de la petición.';
  33. //});
  34. $app->router->get('/', [\App\Controllers\PageController::class, 'home']);
  35. $app->router->get('/contacto', [\App\Controllers\ContactController::class, 'create']);
  36. $app->router->post('/contacto', [\App\Controllers\ContactController::class, 'create']);
  37. $app->router->get('/login', [\App\Controllers\AuthController::class, 'login']);
  38. $app->router->post('/login', [\App\Controllers\AuthController::class, 'login']);
  39. $app->router->get('/registrate', [\App\Controllers\AuthController::class, 'register']);
  40. $app->router->post('/registrate', [\App\Controllers\AuthController::class, 'register']);
  41. $app->router->get('/logout', [\App\Controllers\AuthController::class, 'logout']);
  42. $app->router->get('/perfil', [\App\Controllers\AuthController::class, 'profile']);
  43. /*
  44. * Ejecuta la aplicación.
  45. */
  46. $app->run();