<?php

namespace App\Filters;

use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;


class Database implements FilterInterface
{
    public function before(RequestInterface $request, $arguments = null)
    {
        $db = db_connect();
        if ($db) {
            // Check if the connection is successful
            if (!$db->connect(false)) {
                // Jika koneksi gagal, arahkan ke halaman maintenance
                return redirect()->to(base_url('maintenance'));
            }
        } else {
            return redirect()->to(base_url('maintenance'));
        }

        return;
    }

    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {
        // Do something here
    }
}
