<?php
/**
* バックトレースクラス
*
* PHP version 5
*
* @package    debug
* @author     stk2k <stk2k@sazysoft.com>
* @copyright  2008 stk2k, sazysoft
*/

class BackTrace extends Object
{
	private $_backtraces;

	/*
	 *	コンストラクタ
	 */
	public function __construct()
	{
		parent::__construct();

		$this->_backtraces = debug_backtrace();

		array_shift($this->_backtraces);
	}

	/*
	 *	詳細情報を作成
	 */
	public function build()
	{
		$details = array();

		$backtraces = $this->_backtraces;
		$level = 0;
		foreach( $backtraces as $trace )
		{
			$class     = isset($trace[ 'class' ]) ? $trace[ 'class' ] : NULL;
			$function  = $trace[ 'function' ];
			$line      = $trace[ 'line' ];
			$file      = $trace[ 'file' ];
			$args      = $trace[ 'args' ];

			// メソッド仕様
			$spec      = $class ? new MethodSpec( $class, $function ) : new FunctionSpec( $function );
			// ソース情報
			$source    = new PhpSourceInfo( $file, $line );
			// 呼び出し履歴
			$history   = new CallHistory( $args );

			// 要素を追加
			$details[$level++] = new BackTraceElement( $spec, $source, $history );
		}

		return $details;
	}

}
return __FILE__;
