FuelPHP Bin
<?php /** * Part of the Fuel framework. * * @package Fuel * @version 1.0 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ /** * View class * * Acts as an object wrapper for HTML pages with embedded PHP, called "views". * Variables can be assigned with the view object and referenced locally within * the view. * * @package Fuel * @category Core * @link http://docs.fuelphp.com/classes/view.html */ class View extends \Fuel\Core\View { /** * @var string string used as a view, instead of a viewfile */ protected $view_string = null; /** * Our version supports views in strings instead of files * * @param string File override * @param array variables * @return string */ protected function process_file($file_override = false) { // normal view, let the parent deal with it if (empty($this->view_string)) { return parent::process_file($file_override); } // process the view string $clean_room = function($__file_name, array $__data) { extract($__data, EXTR_REFS); // Capture the view output ob_start(); try { if (preg_match('~(.*)?(\<\?php.*\?\>)(.*)?~', $this->view_string, $matches)) { unset($matches[0]); foreach ($matches as $index => $match) { strpos($match, '<?php') === 0 and $match = eval(str_replace(array('<?php', '?>'), '', $match)); echo $match; } } else { echo $this->view_string; } } catch (\Exception $e) { // Delete the output buffer ob_end_clean(); // Re-throw the exception throw $e; } // Get the captured output and close the buffer return ob_get_clean(); }; return $clean_room($file_override ?: $this->file_name, $this->get_data()); } /** * Sets the view filename. * * $view->set_filename($file); * * @param string view filename * @return View * @throws FuelException */ public function set_filename($file, $reverse = false) { try { parent::set_filename($file, $reverse); } catch (\FuelException $e) { // assume what was passed is a string, not a filename $this->view_string = $file; $this->file_name = true; } } }