예제 #1
0
 public function execute()
 {
     // クエリのビルド
     $sql = $this->buildQuery();
     // クエリを実行する。
     try {
         $connection = Vizualizer_Database_Factory::begin($this->module);
         Vizualizer_Logger::writeDebug($sql);
         $result = $connection->query($sql);
     } catch (Exception $e) {
         Vizualizer_Logger::writeError($sql, $e);
         throw new Vizualizer_Exception_Database($e);
     }
     return $result;
 }
예제 #2
0
 /**
  * 拡張ライブラリファイルを読み込む
  *
  * @param string $type 拡張ファイルの種別
  * @param string $name 拡張ファイルのオブジェクト名
  */
 private function load($type, $name, $params = array())
 {
     try {
         $names = explode(".", $name);
         $className = (!in_array($this->namespace, self::$callmap) ? "Vizualizer" . $this->namespace : self::$callmap[$this->namespace]) . "_" . $type . "_" . implode("_", $names);
         if (class_exists($className)) {
             Vizualizer_Logger::writeDebug("Loading: " . $className . "(" . memory_get_usage() . ")");
             return new $className($params);
         } else {
             $className = "Vizualizer_" . $type . "_" . $this->namespace . "_" . implode("_", $names);
             if (class_exists($className)) {
                 Vizualizer_Logger::writeDebug("Loading: " . $className . "(" . memory_get_usage() . ")");
                 return new $className($params);
             }
         }
         Vizualizer_Logger::writeDebug("No Plugin : " . $className);
         return null;
     } catch (Exception $e) {
         Vizualizer_Logger::writeError("Failed to load plugin", $e);
     }
 }
예제 #3
0
 public function fetch($limit = null, $offset = null)
 {
     // クエリのビルド
     $sql = $this->buildQuery();
     // クエリの検索件数を制限する。
     if ($limit != null) {
         $sql .= " LIMIT " . $limit;
         if ($offset != null) {
             $sql .= " OFFSET " . $offset;
         }
     }
     // クエリを実行する。
     try {
         $sql = $this->showQuery();
         Vizualizer_Logger::writeDebug($sql);
         $connection = Vizualizer_Database_Factory::conn($this->module);
         $result = $connection->query($sql);
     } catch (Exception $e) {
         Vizualizer_Logger::writeError($sql, $e);
         throw new Vizualizer_Exception_Database($e);
     }
     return new Vizualizer_Query_Select_Result($result);
 }
예제 #4
0
 /**
  * エラーログを出力する。
  * @param string $message ログメッセージ
  * @param Exception $exception エラーの原因となった例外オブジェクト
  */
 protected function error($message, $exception = null)
 {
     Vizualizer_Logger::writeError($message, $exception);
 }
예제 #5
0
 /**
  * 現在の状態で挿入クエリを実行する。
  *
  * @param s array $values 挿入データの連想配列
  */
 public function execute($values)
 {
     try {
         $connection = Vizualizer_Database_Factory::begin($this->module);
         $sql = $this->showQuery($values);
         Vizualizer_Logger::writeDebug($sql);
         $result = $connection->query($sql);
     } catch (Exception $e) {
         Vizualizer_Logger::writeError($sql, $e);
         throw new Vizualizer_Exception_Database($e);
     }
     return $result;
 }
/**
 * Smarty {loadmodule} function plugin
 *
 * Type: function<br>
 * Name: loadmodule<br>
 * Purpose: load framework module.<br>
 *
 * @author Naohisa Minagawa <minagawa at web-life dot co dot jp>
 * @param array $params parameters
 * @param object $smarty Smarty object
 * @param object $template template object
 * @return string null
 */
function smarty_function_loadmodule($params, $template)
{
    // nameパラメータは必須です。
    if (empty($params['name'])) {
        trigger_error("loadmodule: missing name parameter", E_USER_WARNING);
        return;
    }
    if (!empty($params["if"])) {
        $result = true;
        $expression = '$result = ' . str_replace('_POST', '$_POST', $params["if"]) . ';';
        eval($expression);
        if (!$result) {
            return;
        }
    }
    // パラメータを変数にコピー
    $name = $params['name'];
    // errorパラメータはエラー例外時に指定されたテンプレートに変更する。
    if (isset($params["error"])) {
        $error = $params['error'];
    } else {
        $error = "";
    }
    // モジュールのクラスが利用可能か調べる。
    $errors = null;
    try {
        // モジュール用のクラスをリフレクション
        list($namespace, $class) = explode(".", $name, 2);
        $loader = new Vizualizer_Plugin($namespace);
        $object = $loader->loadModule($class);
        if (method_exists($object, "start")) {
            Vizualizer_Logger::writeDebug("=========== " . $name . " start ===========");
            // 検索条件と並べ替えキー以外を無効化する。
            if (isset($params["clear"]) && $params["clear"] == "1") {
                if (isset($params["sort_key"]) && !empty($params["sort_key"])) {
                    $_POST = array("search" => $_POST["search"], $params["sort_key"] => $_POST[$params["sort_key"]]);
                } else {
                    $_POST = array("search" => $_POST["search"]);
                }
            }
            if (!empty($params["key_prefix"])) {
                $object->key_prefix = $params["key_prefix"];
            } else {
                $object->key_prefix = "";
            }
            if (!empty($params["continue"])) {
                $object->continue = $params["continue"];
            } else {
                $object->continue = "";
            }
            $object->execute(new Vizualizer_Plugin_Module_Parameters($params));
            Vizualizer_Logger::writeDebug("=========== " . $name . " end ===========");
        } else {
            Vizualizer_Logger::writeAlert($name . " is not plugin module.");
        }
    } catch (Vizualizer_Exception_Invalid $e) {
        // 入力エラーなどの例外(ただし、メッセージリストを空にすると例外処理を行わない)
        Vizualizer_Logger::writeError($e->getMessage(), $e);
        $errors = $e->getErrors();
    } catch (Vizualizer_Exception_Database $e) {
        // システムエラーの例外処理
        Vizualizer_Logger::writeError($e->getMessage(), $e);
        $errors = array(Vizualizer::ERROR_TYPE_DATABASE => $e->getMessage());
    } catch (Vizualizer_Exception_System $e) {
        // システムエラーの例外処理
        Vizualizer_Logger::writeError($e->getMessage(), $e);
        $errors = array(Vizualizer::ERROR_TYPE_SYSTEM => $e->getMessage());
    } catch (Exception $e) {
        // 不明なエラーの例外処理
        Vizualizer_Logger::writeError($e->getMessage(), $e);
        $errors = array(Vizualizer::ERROR_TYPE_UNKNOWN => $e->getMessage());
    }
    // エラー配列をスタックさせる
    if (is_array($errors) && !empty($errors)) {
        $attr = Vizualizer::attr();
        // エラー用配列が配列になっていない場合は初期化
        $errorData = $attr[Vizualizer::ERROR_KEY];
        if (!is_array($errorData)) {
            $errorData = array();
        }
        // エラー内容をマージさせる。
        foreach ($errors as $key => $message) {
            if ($key != "" && !array_key_exists($key, $errorData)) {
                $errorData[$key] = $message;
            }
        }
        $templateEngine = $attr["template"];
        if (!empty($error)) {
            // errorパラメータが渡っている場合はスタックさせたエラーを全て出力してエラー画面へ
            $templateEngine->assign("ERRORS", $errorData);
            unset($attr[Vizualizer::ERROR_KEY]);
            $info = pathinfo($error);
            switch ($info["extension"]) {
                case "php":
                    // PHPを実行する場合、インクルードパスの最優先をテンプレートのディレクトリに設定
                    ini_set("include_path", Vizualizer_Configure::get("site_home") . $attr["userTemplate"] . PATH_SEPARATOR . ini_get("include_path"));
                    $source = file_get_contents(Vizualizer_Configure::get("site_home") . $attr["userTemplate"] . DIRECTORY_SEPARATOR . $error);
                    // 先頭のPHPタグを除去
                    $source = "?>" . $source;
                    // バッファを除去
                    ob_end_clean();
                    ob_start();
                    eval($source);
                    // 実行後のデータを取得し、バッファを再度除去
                    $source = ob_get_contents();
                    ob_end_clean();
                    ob_start();
                    // ソースデータをリソース化
                    $source = "eval:" . $source;
                    // テンプレートを表示
                    $templateEngine->display($source);
                    exit;
                default:
                    $templateEngine->display($error);
                    exit;
            }
        } else {
            $attr[Vizualizer::ERROR_KEY] = $errorData;
        }
    }
}
예제 #7
0
 /**
  * フレームワークでエラーが発生してキャッチされなかった場合の処理を記述するメソッドです。
  */
 public static final function error($code, $message, $ex = null)
 {
     // ダウンロードの際は、よけいなバッファリングをクリア
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     // エラーログに書き込み
     Vizualizer_Logger::writeError($message . "(" . $code . ")", $ex);
     // カスタムエラーページのパス
     $path = $_SERVER["CONFIGURE"]->site_home . $_SERVER["USER_TEMPLATE"] . DIRECTORY_SEPARATOR . "ERROR_" . $code . ".html";
     // ファイルがある場合はエラーページを指定ファイルで出力
     if (file_exists($path)) {
         try {
             header("HTTP/1.0 " . $code . " " . $message, true, $code);
             header("Status: " . $code . " " . $message);
             header("Content-Type: text/html; charset=utf-8");
             $_SERVER["TEMPLATE"]->display("ERROR_" . $code . ".html");
         } catch (Exception $e) {
             // エラーページでのエラーは何もしない
         }
     } else {
         // エラーページが無い場合はデフォルト
         header("HTTP/1.0 " . $code . " " . $message, true, $code);
         header("Status: " . $code . " " . $message);
         header("Content-Type: text/html; charset=utf-8");
         echo $message;
     }
     exit;
 }