phptal.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Fuel
  4. *
  5. * Fuel is a fast, lightweight, community driven PHP5 framework.
  6. *
  7. * @package Fuel
  8. * @version 1.5
  9. * @author Fuel Development Team
  10. * @license MIT License
  11. * @copyright 2010 - 2013 Fuel Development Team
  12. * @link http://fuelphp.com
  13. */
  14. namespace Parser;
  15. class View_Phptal extends \View
  16. {
  17. protected static $_parser;
  18. protected function process_file($file_override = false)
  19. {
  20. $file = $file_override ?: $this->file_name;
  21. try
  22. {
  23. $parser = static::parser();
  24. foreach($this->get_data() as $key => $value)
  25. {
  26. $parser->set($key,$value);
  27. }
  28. $parser->setTemplate($file);
  29. return $parser->execute();
  30. }
  31. catch (\Exception $e)
  32. {
  33. // Delete the output buffer & re-throw the exception
  34. ob_end_clean();
  35. throw $e;
  36. }
  37. }
  38. public $extension = 'phptal';
  39. public static function parser()
  40. {
  41. if ( ! empty(static::$_parser))
  42. {
  43. return static::$_parser;
  44. }
  45. static::$_parser = new \PHPTAL();
  46. static::$_parser->setEncoding(\Config::get('parser.View_Phptal.encoding', 'UTF-8'));
  47. static::$_parser->setOutputMode(constant('\\'.\Config::get('parser.View_Phptal.output_mode', 'PHPTAL::XHTML')));
  48. static::$_parser->setTemplateRepository(\Config::get('parser.View_Phptal.template_repository', ''));
  49. static::$_parser->setPhpCodeDestination(\Config::get('parser.View_Phptal.cache_dir', APPPATH.'cache'.DS.'PHPTAL'.DS));
  50. static::$_parser->setCacheLifetime(\Config::get('parser.View_Phptal.cache_lifetime', 0));
  51. static::$_parser->setForceReparse(\Config::get('parser.View_Phptal.force_reparse', false));
  52. return static::$_parser;
  53. }
  54. }
  55. // end of file phptal.php