dwoo.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. use Dwoo;
  16. use Dwoo_Compiler;
  17. use Dwoo_Security_Policy;
  18. class View_Dwoo extends \View
  19. {
  20. protected static $_parser;
  21. protected static $_parser_compiler;
  22. protected static $_parser_security;
  23. protected function process_file($file_override = false)
  24. {
  25. $file = $file_override ?: $this->file_name;
  26. $data = $this->get_data();
  27. try
  28. {
  29. return static::parser()->get($file, $data);
  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 = 'tpl';
  39. /**
  40. * Returns the Parser lib object
  41. *
  42. * @return Dwoo
  43. */
  44. public static function parser()
  45. {
  46. if ( ! empty(static::$_parser))
  47. {
  48. return static::$_parser;
  49. }
  50. // Parser
  51. static::$_parser = new Dwoo();
  52. static::$_parser->setCacheTime(\Config::get('parser.View_Dwoo.environment.cache_time', 0));
  53. static::$_parser->setCacheDir(\Config::get('parser.View_Dwoo.environment.cache_dir', APPPATH.'cache'.DS.'dwoo'.DS));
  54. static::$_parser->setCompileDir(\Config::get('parser.View_Dwoo.environment.compile_dir', APPPATH.'cache'.DS.'dwoo'.DS.'compiled'.DS));
  55. // Compiler
  56. static::$_parser_compiler = new Dwoo_Compiler;
  57. static::$_parser_compiler->setAutoEscape(\Config::get('parser.View_Dwoo.environment.autoescape', false));
  58. static::$_parser_compiler->setLooseOpeningHandling(\Config::get('parser.View_Dwoo.environment.allow_spaces', false));
  59. static::$_parser_compiler->setNestedCommentsHandling(\Config::get('parser.View_Dwoo.environment.nested_comments', false));
  60. static::$_parser_compiler->setDelimiters(
  61. \Config::get('parser.View_Dwoo.delimiters.left', '{'),
  62. \Config::get('parser.View_Dwoo.delimiters.right', '}')
  63. );
  64. // Security
  65. static::$_parser_security = new Dwoo_Security_Policy;
  66. static::$_parser_security->setPhpHandling(\Config::get('parser.View_Dwoo.environment.allow_php_tags', 2));
  67. static::$_parser_security->allowPhpFunction(\Config::get('parser.View_Dwoo.environment.allow_php_func', array()));
  68. static::$_parser->setSecurityPolicy(static::$_parser_security);
  69. return static::$_parser;
  70. }
  71. }
  72. // end of file dwoo.php