<?php
/**
  * @method 模板
  * @author soul
  * @copyright 2017/7/19
  */
class LibTpl
{
	protected static $setArr = [];
	
	/**
	  * @method 赋值
	  * @author soul
	  */
	public static function Set($key, $value = null) 
	{
		self::$setArr[$key] = $value;
	}
	
	/**
	  * @method 输出模板
	  * @param  $tplFile  模板名称
	  * @param  $tplPath  模板目录[默认mvc::$cfg['PATH_TPL']]
	  * @author soul
	  */
	public static function Put($tplFile='', $tplPath = null)
	{
        /* 当参数为空时，取默认的 action/function.php 模板路径 */
        if(empty($tplFile)){
            if(!empty(mvc::$URL_CLASS_PATH)) $tplFile = mvc::$URL_CLASS_PATH . '/';
            $tplFile .= mvc::$URL_CLASS .'/'. mvc::$URL_METHOD . '.php';
        }else{
            if(strpos($tplFile,'.')===false) $tplFile .= '.php';
        }
		foreach(self::$setArr as $key=>$value)
		{
			$$key = $value;
		}
		include($tplFile);
	}


	/**
	  * @method 得到处理模板后的结果(HTML)
	  * @param  $tplFile  模板名称
	  * @param  $tplPath  模板目录[默认mvc::$cfg['PATH_TPL']]
	  * @author soul
	  */
	public static function Fetch($tplFile='', $tplPath = null)
	{
		ob_start();
		self::Put($tplFile, $tplPath);
		$html = ob_get_contents(); 
		ob_end_clean();
		return $html;
	}
}