<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv='Content-Type' content='text/html; charset=EUC-JP'>

<style type="text/css">

/* タイトル */
h2 {
  font-size: 12pt;
  font-weight: bold;
  color: #666666;
}

/* エラー概要 */
table.error_digest {
  width: 400px;
  border-width: 2px;
  border-style: solid;
  border-color: #666666; 
  border-collapse: collapse;
}

th.error_digest {
  background-color: gray;
  color: white;
  font-size: 9pt;
  border: 1px #666666 solid;
}

td.error_digest {
  background-color: white;
  color: darkblue;
  font-size: 9pt;
  border: 1px #666666 solid;
}

/* エラー詳細 */
table.error_detail {
  border-width: 2px;
  border-style: solid;
  border-color: #666666; 
  border-collapse: collapse;
}

th.error_detail {
  background-color: gray;
  color: white;
  font-size: 9pt;
  border: 1px #666666 solid;
  padding: 2px;
}

td.error_detail {
  background-color: white;
  color: darkblue;
  font-size: 9pt;
  border: 1px #666666 solid;
  padding: 2px;
}
</style>

</HEAD>
<BODY>

<h2>例外スタック</h2>
<TABLE class="error_detail">
<TR>
	  <TH class="error_detail">レベル</TH>
	  <TH class="error_detail">例外</TH>
	  <TH class="error_detail">メッセージ</TH>
	  <TH class="error_detail">ソース</TH>
	  <TH class="error_detail">行番号</TH>
</TR>

<?
$level = 0;
foreach( $cause_list as $cause )
{
	$class_name = get_class($cause);
	$message 	= $cause->getMessage();
	$file 		= basename($cause->getFile());
	$line 		= $cause->getLine();

	print '<TR>';
	print '   <TD class="error_detail">' . $level . '</TD>';
	print '   <TD class="error_detail">' . $class_name . '</TD>';
	print '   <TD class="error_detail">' . $message . '</TD>';
	print '   <TD class="error_detail">' . $file . '</TD>';
	print '   <TD class="error_detail">' . $line . '</TD>';
	print '</TR>';

	$level ++;
}
?>

</TABLE>

<P>

<?
foreach( $cause_list as $cause ){

	if ( $cause instanceof charcoal_Exception ){

		$backtraces = $cause->getBackTrace();
?>
		<h2>バックトレース</h2>
		<TABLE class="error_detail">
		<TR>
			  <TH class="error_detail">ファイル名(行番号)</TH>
			  <TH class="error_detail">関数名</TH>
			  <TH class="error_detail">引数</TH>
		</TR>
<?
		$level = 0;
		foreach( $backtraces as $trace ){
			$class     = $trace[ 'class' ];
			$function  = $trace[ 'function' ];
			$line      = $trace[ 'line' ];
			$dir       = dirname($trace[ 'file' ]);
			$file      = basename($trace[ 'file' ]);
			$args      = $trace[ 'args' ];

			// メソッド引数を取得
			$method    = new ReflectionMethod( $class, $function );
			$params    = $method->getParameters();
			$param_cnt = $method->getNumberOfParameters();

			$str_method = $method->getName() . '(' . PHP_EOL;
			foreach( $params as $p ){
				$dec_class       = $p->getDeclaringClass();
				$param_name      = $p->getName();
				$is_array        = $p->isArray();
				$reference       = $p->isPassedByReference();
				$default_exsits  = $p->isDefaultValueAvailable();
				$default_value   = $default_exsits ? $p->getDefaultValue() : '';

				$str_method .= str_repeat('&nbsp;',3);
				$str_method .= $dec_class->getName() . ($is_array ? '[] ' : ' ') . ($reference ? '&amp;' : '');
				$str_method .= $param_name;
				if ( $default_exsits ){
					$str_method .= ' = ' . ($default_value ? $default_value : 'NULL');
				}
				if ( --$param_cnt > 0 ){
					$str_method .= ',';
				}
				$str_method .= PHP_EOL;
			}
			$str_method .= ')' . PHP_EOL;

			// メソッド引数
			$str_args = '';
			$args_cnt = count($args);
			for($i=0;$i<$args_cnt;$i++){
				$param = $params[$i];
				$str_args .= $param->getName() . '&nbsp;==&gt;&nbsp;' . $args[$i] . PHP_EOL;
			}

			// ファイルリンク
			

			print '<TR>';
			print '   <TD class="error_detail">' . $dir . '<BR>' . $file . '(' . $line . ')</TD>';
			print '   <TD class="error_detail">' . $class . ':' . nl2br($str_method) . '</TD>';
			print '   <TD class="error_detail">' . nl2br($str_args) . '</TD>';
			print '</TR>';

			$level ++;
		}
?>
		</TABLE>
<?
		break;
	}
}
?>

</BODY>
</HTML>
