public function redirectIf(string $dir, string $to = '/', bool $exit = true): void
    {
        if ($this->acl != null) {
            $app = $this->acl->getService()->getApp();
            if ($dir == 'in' && $this->isLoggedIn()) {
                $app->response()->redirect($to);
            } elseif ($dir == 'out' && !$this->isLoggedIn()) {
                $app->response()->redirect($to);
            }
        } else {
            if (headers_sent($file, $line)) {
                throw new AclException(sprintf("Cannot use '%s()', headers already sent in %s:%s",
                    __method__, $file, $line));
            }

            header('Location: '. trim($to));
            if ($exit) {
                exit(0);
            }
        }
    }