<?php
/********************************************************************************
 * (c)1337 aheadware.com - All rights reserved
 ********************************************************************************/


class AHDB_Core_Template {

    // Members
    protected $tplFile = NULL;
    protected $data;

    public function __construct( $tplFile, $data = array() ) {
        if ( file_exists( $tplFile ) ) {
            $this->tplFile = $tplFile;
            $this->data = $data;
        } else {
            throw new Exception( "Template file does not exists: " . $tplFile );
        }
    }

    public function addData( $keyOrDataArray, $value = NULL ) {
        if ( is_array( $keyOrDataArray ) ) {
            $this->data = $keyOrDataArray;
        } else {
            $this->data[ $keyOrDataArray ] = $value;
        }
    }


    public function get( array $data = NULL ) {
        $d = is_null( $data ) ? $this->data : $data;
        $content = "";

        ob_start();
        include $this->tplFile;
        $content = ob_get_contents();
        ob_get_clean();
        return $content;
    }
} 