Source

Ray / Ray / View / File / View.php

Full commit
<?php

class Ray_View_File_View{
    
    private $__file;
    
    private $__render;
    
    private $__params;
    
    private $__config;
    
    private $__options;
    
    public function __construct($file, $params=array(), $config, $options){
        
        $this->__file = $file;
        
        $this->__config = $config;
        
        $this->__options = $options;
        
        $this->__params = $params;
        
        foreach($params as $key => $value){
            if(is_string($key)){
                $this->$key = $value;
            }
        }
        
    }
    
    public function element($element, $params=array(), $dir='element'){
        $file = $this->__config['templates'] . DS . $this->__options['actionDir']
              . ($dir ? DS . $dir : '' ) . DS . $element . $this->__options['ext'];
              
        if(file_exists($file)){
            $view = new self($file, array_merge($this->__params, $params), $this->__config, $this->__options);
            
            return $view->render();
        }else{
            throw new Ray_Exception_View_File('Element template file not found. Path: '. $file);
        }
        
        return;
    }
    
    public function render(){
        if(!$this->__render){
            ob_start();
            
            require $this->__file;
            
            $this->__render = ob_get_contents();
            
            ob_end_clean();
        }
        
        return $this->__render;
    }
    
}