<?php
/**
 * Maple - PHP Web Application Framework
 * Copyright (C) 2005 TyoHo
 **/
require_once MAPLE_DIR .'/core/DBAccess.class.php';
/**
 * Validateの実行準備および実行を行うFilter
 *
 * @author  TyoHo
 * @package maple.filter
 * @since   3.0.0
 **/
class Filter_DBAccess extends Filter {
    /**
     * コンストラクター
     *
     * @access  public
     * @since   3.0.0
     */
    function Filter_DBAccess() {
        parent::Filter();
    }

    /**
     * DBAccess処理を実行
     *
     * @access  public
     * @since   3.0.0
     **/
    function execute() {
        $log =& LogFactory::getLog();
        $log->trace("Filter_DBAccessの前処理が実行されました", "Filter_DBAccess#execute");

        $container =& DIContainerFactory::getContainer();

                $DBAccess= new DBAccess;
                $container->register($DBAccess, "DBAccess");

        $attributes = $this->getAttributes();

        if (isset($attributes["dbtype"])){
                    $dbtype = trim(strtolower($attributes["dbtype"]));
                } else {
                    $dbtype = "";
                }

                if (isset($attributes["dbserver"])){
                    $dbserver = trim($attributes["dbserver"]);
                } else {
                    $dbserver = "";
                }

                if (isset($attributes["dbport"])){
                    $dbport = trim($attributes["dbport"]);
                } else {
                    $dbport = "";
                }

                if (isset($attributes["dbname"])){
                    $dbname = trim($attributes["dbname"]);
                } else {
                    $dbname = "";
                }

                if (isset($attributes["dbuser"])){
                    $dbuser = trim($attributes["dbuser"]);
                } else {
                    $dbuser = "";
                }

                if (isset($attributes["dbpass"])){
                    $dbpass = trim($attributes["dbpass"]);
                } else {
                    $dbpass = "";
                }

                $DBAccess->setDBAccess($dbtype,$dbserver,$dbport,$dbname,$dbuser,$dbpass);

                //Connect TEST 用
                if ($DBAccess->getConnect()) {
                     $log->trace("DBAccess Connect 成功", "Filter_DBAccess#execute");
                } else {
                     $log->trace("DBAccess Connect 失敗", "Filter_DBAccess#execute");
                }

        $filterChain =& $container->getComponent("FilterChain");
        $filterChain->execute();

        $log->trace("Filter_DBAccessの後処理が実行されました", "Filter_DBAccess#execute");
    }
}
?>
