<?php
namespace library;

use \IFilter;
use \Request;
use \Response;
use \FilterChain;
use \IoC;

class InstallFilter implements IFilter {

    /**
     * @param Request request Request object
     * @param Response response Response object
     * @access public
     */
    public function execute( Request $request, Response $response, FilterChain $filterchain ) {
        if ( !is_writable( VAR_DIR ) ) {
            die( '/var directory is not writable.' );
        }
        if ( !file_exists( VAR_DIR . 'database.db' ) ) {
            $createDatabase = IoC::resolve( 'createDatabase' );
            $createDatabase->perform();
        }
        $filterchain->execute( $request, $response );
    }
}
