*/ class Block extends View { private $file; /** * Establishes the block script to use for rendering * * Blocks are files contained in the base path of: * APPLICATION_HOME/blocks/$outpuform * * @param string $file * @param array $vars An associative array of variables to set */ public function __construct($file,array $vars=null) { $this->file = $file; if (count($vars)) { foreach ($vars as $name=>$value) { $this->vars[$name] = $value; } } } /** * Includes the block script and returns the output as a string * * @param string $outputFormat * @return string */ public function render($outputFormat='html') { $block = "/blocks/$outputFormat/{$this->file}"; if (file_exists(APPLICATION_HOME.$block)) { ob_start(); include APPLICATION_HOME.$block; return ob_get_clean(); } elseif (file_exists(FRAMEWORK.$block)) { ob_start(); include FRAMEWORK.$block; return ob_get_clean(); } throw new Exception('unknownBlock'); } }