<?php
/**
 * -----------------------------------------------------------------------------
 *
 * SyL - Web Application Framework for PHP
 *
 * PHP version 4 (>= 4.3.x) or 5
 *
 * Copyright (C) 2006 k.watanabe
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * -----------------------------------------------------------------------------
 * @package   SyL
 * @author    k.watanabe <k.watanabe@syl.jp>
 * @copyright 2006 k.watanabe
 * @license   http://www.opensource.org/licenses/lgpl-license.php
 * @version   CVS: $Id: SyL_FilterDebughtml.php,v 1.6 2006/12/19 13:27:47 seasonstream Exp $
 * @link      http://www.syl.jp/
 * -----------------------------------------------------------------------------
 */

/**
 * フィルタクラス
 */
require_once SYL_INCLUDE_DIR . '/framework/SyL_Filter.php';

/**
 * デバック情報表示フィルタクラス
 *
 * @package   SyL
 * @author    k.watanabe <k.watanabe@syl.jp>
 * @copyright 2006 k.watanabe
 * @license   http://www.opensource.org/licenses/lgpl-license.php
 * @version   CVS: $Id: SyL_FilterDebughtml.php,v 1.6 2006/12/19 13:27:47 seasonstream Exp $
 * @link      http://www.syl.jp/
 */
class SyL_FilterDebughtml extends SyL_Filter
{
    /**
     * 表示情報格納配列
     *
     * @access public
     * @var array 表示情報格納配列
     */
    var $view_info = array(
        'GET'      => true,
        'POST'     => true,
        'COOKIE'   => true,
        'SESSION'  => true,
        'SERVER'   => true,
        'ENV'      => true,
        'INCLUDE'  => true,
        'CONSTANT' => false,
        'FUNCTION' => true,
        'CLASS'    => true,
        'MODULE'   => true
    );

    /**
     * ビュー表示後フィルタ
     *
     * @access public
     * @param object リクエストオブジェクト
     * @param object ビューデータオブジェクト
     */
    function renderAfter()
    {
        echo "<hr>";
        echo "<h3>***** デバック情報出力 *****</h3>";

        // リソース情報
        echo "<h4>リソース情報</h4>\r\n";
        echo "<table border='1' cellspacing='0' cellpadding='2'>\r\n";
        echo "<tr>\r\n";
        echo "<td>パラメータ名</td><td>パラメータ値</td>\r\n";
        echo "</tr>\r\n";
        echo "<tr>\r\n";
        echo "<td></td><td>パラメータ値</td>\r\n";
        echo "</tr>\r\n";
/*
        echo '<tr><td>スクリプトの実行者</td><td>' . '' . '</td></tr>' . "\r\n";
        echo '<tr><td>現在のスクリプトの実行時間</td><td>' . '' . '</td></tr>' . "\r\n";
        echo '<tr><td>現在のスクリプトの使用メモリ量</td><td>' . (function_exists('memory_get_usage') ? memory_get_usage() : '') . '</td></tr>' . "\r\n";
*/
        echo '</table>' . "\r\n";
        echo '<br>' . "\r\n";

        // GET情報表示判定
        if ($this->view_info['GET'] && isset($_GET)) {
            $this->viewDebugInfoCategory('$_GET', $_GET);
        }

        // POST情報表示判定
        if ($this->view_info['POST'] && isset($_POST)) {
            $this->viewDebugInfoCategory('$_POST', $_POST);
        }

        // COOKIE情報表示判定
        if ($this->view_info['COOKIE'] && isset($_COOKIE)) {
            $this->viewDebugInfoCategory('$_COOKIE', $_COOKIE);
        }

        // SESSION情報表示判定
        if ($this->view_info['SESSION'] && isset($_SESSION)) {
            $this->viewDebugInfoCategory('$_SESSION', $_SESSION);
        }

        // SERVER情報表示判定
        if ($this->view_info['SERVER'] && isset($_SERVER)) {
            $this->viewDebugInfoCategory('$_SERVER', $_SERVER);
        }

        // ENV情報表示判定
        if ($this->view_info['ENV'] && isset($_ENV)) {
            $this->viewDebugInfoCategory('$_ENV', $_ENV);
        }

        // インクルードファイル情報表示判定
        if ($this->view_info['INCLUDE']) {
            $include_list = get_included_files();
            //sort($include_list);
            $this->viewDebugInfoCategory('INCLUDE', $include_list);
        }

        // 定数情報表示判定
        if ($this->view_info['CONSTANT']) {
            $this->viewDebugInfoCategory('CONSTANT', get_defined_constants());
        }

        // 関数情報表示判定
        if ($this->view_info['FUNCTION']) {
            $function_list = get_defined_functions();
            if (isset($function_list['user'])) {
                $this->viewDebugInfoCategory('FUNCTION', $function_list['user']);
            }
        }

        // クラス情報表示判定
        if ($this->view_info['CLASS']) {
            $class_list = get_declared_classes();
            //sort($class_list);
            $this->viewDebugInfoCategory('CLASS', $class_list);
        }

        // モジュール情報表示判定
        if ($this->view_info['MODULE']) {
            $module_list = get_loaded_extensions();
            //sort($module_list);
            $this->viewDebugInfoCategory('MODULE', $module_list);
        }


        echo "<br><br><br><br><br><br><br><br>\r\n";
    }

    /**
     * デバック情報カテゴリを表示
     *
     * @access public
     * @param array 表示対象カテゴリ名
     * @param array 表示対象カテゴリ配列
     */
    function viewDebugInfoCategory($category_name, &$category_list)
    {
        echo "<h4>{$category_name}</h4>\r\n";
        echo "<table border='1' cellspacing='0' cellpadding='2'>\r\n";
        echo "<tr>\r\n";
        echo "<td bgcolor='#003399'><font color='#FFFFFF'><b>パラメータ名</b></font></td>\r\n";
        echo "<td bgcolor='#003399'><font color='#FFFFFF'><b>パラメータ値</b></font></td>\r\n";
        echo "</tr>\r\n";
        foreach ($category_list as $key => $value) {
            echo "<tr>\r\n";
            echo "<td>" . htmlspecialchars(var_export($key, true)) . "</td>\r\n";
            echo "<td>" . nl2br(str_replace(' ', '&nbsp;', htmlspecialchars(var_export($value, true)))) . "</td>\r\n";
            echo "</tr>\r\n";
        }
        echo "</table>\r\n";
        echo "<br>\r\n";
    }

}

?>
