AuthMiddleware.php 605 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Core\Middlewares;
  3. use App\Core\Application;
  4. use App\Core\Exceptions\ForbiddenException;
  5. /*
  6. * Comprueba que un usuario inició sesión.
  7. */
  8. class AuthMiddleware extends BaseMiddleware
  9. {
  10. public array $actions = [];
  11. public function __construct(array $actions = [])
  12. {
  13. $this->actions = $actions;
  14. }
  15. public function execute()
  16. {
  17. if (Application::isGuest()) {
  18. if (empty($this->actions) || in_array(Application::$app->controller->action, $this->actions)) {
  19. throw new ForbiddenException();
  20. }
  21. }
  22. }
  23. }