• R/O
  • SSH
  • HTTPS

maple: Commit


Commit MetaInfo

Revision81 (tree)
Time2006-10-20 16:11:28
Authorhawkring

Log Message

Debug Consoleの表示処理はregister_shutdown_functionを用いて最後に実行されるようにした
これによって、任意の位置にフィルタさえ登録すれば、処理の最後に表示されるようになった

_printDebugメソッド内のHTMLとJavaScriptを修正した

_detectEncodingメソッドはmb_detect_encodingではなく
mb_convert_encodingのauto指定を使うようにした。
(PHP5での文字化け対策)

Change Summary

Incremental Difference

--- maple/trunk/maple/filter/Filter_Debug.class.php (revision 80)
+++ maple/trunk/maple/filter/Filter_Debug.class.php (revision 81)
@@ -22,6 +22,11 @@
2222 * @version CVS: $Id$
2323 */
2424
25+/**
26+ * Debug Consoleの出力が行われたかどうかを示すフラグ
27+ */
28+$GLOBALS['MAPLE_FILTER_DEBUG_EXECUTED'] = false;
29+
2530 require_once MAPLE_DIR .'/dBug/DumpHelper.class.php';
2631
2732 /**
@@ -69,15 +74,24 @@
6974 $filterChain->execute();
7075
7176 $log->trace("Filter_Debugの後処理が実行されました", "Filter_Debug#execute");
72- // Debugはビューを表示した後のみ出力する必要あり
77+
78+ register_shutdown_function(array(&$this, '_postFilter'));
79+ }
80+
81+ /**
82+ * ResponseがHTMLだったかどうかを調べる
83+ *
84+ * @access private
85+ * @param Response $response
86+ * @return boolean
87+ */
88+ function _isHtmlResponse(&$response)
89+ {
7390 // ResponseオブジェクトのResultに値があるときはビューを出力するとみなす
74- $response =& $container->getComponent("Response");
7591 $result = $response->getResult();
7692 $contentType = $response->getContentType();
77- if ($result != '' && ($contentType == '' || strtolower($contentType) == 'text/html')) {
78- $this->_postFilter();
79- }
80-
93+ return ($result != '' &&
94+ ($contentType == '' || preg_match('|text/html|', $contentType)));
8195 }
8296
8397 /**
@@ -93,6 +107,16 @@
93107 */
94108 function _postFilter()
95109 {
110+ // Debugはビューを表示した後のみ出力する必要あり
111+ $container =& DIContainerFactory::getContainer();
112+ $response =& $container->getComponent("Response");
113+
114+ if(!$this->_isHtmlResponse($response) ||
115+ $GLOBALS['MAPLE_FILTER_DEBUG_EXECUTED']) {
116+ return;
117+ }
118+ $GLOBALS['MAPLE_FILTER_DEBUG_EXECUTED'] = true;
119+
96120 $NO = 'なし';
97121
98122 $var = (isset($_POST) && (0 < count($_POST)))? $_POST: $NO;
@@ -178,10 +202,7 @@
178202 */
179203 function _detectEncoding($var)
180204 {
181- $nowencode = mb_detect_encoding($var);
182- if ($nowencode != OUTPUT_CODE) {
183- $var = mb_convert_encoding($var, OUTPUT_CODE, $nowencode);
184- }
205+ $var = mb_convert_encoding($var, OUTPUT_CODE, "auto");
185206 return $var;
186207 }
187208
@@ -208,15 +229,15 @@
208229
209230 // 表示するHTMLの作成
210231 $html = <<<HTML
211-<HTML>
212-<HEAD>
213-<TITLE>Maple Debug Console</TITLE>
214-</HEAD>
215-<BODY bgcolor=#ffffff>
216-<table border=0 width=100%><tr bgcolor=#cccccc><th colspan=2>Maple Debug Console</th></tr></table>
232+<html>
233+<head>
234+<title>Maple Debug Console</title>
235+</head>
236+<body bgcolor="#ffffff">
237+<table border="0" width="100%"><tr bgcolor="#cccccc"><th colspan="2">Maple Debug Console</th></tr></table>
217238 {$debug}
218-</BODY>
219-</HTML>
239+</body>
240+</html>
220241 HTML;
221242
222243 // Javascript出力用にエスケープ処理
@@ -224,12 +245,12 @@
224245
225246 // Javascript出力
226247 $JS = <<<JS
227-<SCRIPT language=javascript>
248+<script type="text/javascript">
228249 var title = 'Console';
229- _smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes");
230- _smarty_console.document.write("$html");
231- _smarty_console.document.close();
232-</SCRIPT>
250+ var _maple_debug_console = window.open("",title,"width=680,height=600,resizable,scrollbars=yes");
251+ _maple_debug_console.document.write("$html");
252+ _maple_debug_console.document.close();
253+</script>
233254 JS;
234255 print $JS;
235256 }
Show on old repository browser