4 * Smarty Internal Plugin Resource PHP
5 * Implements the file system as resource for PHP templates
8 * @subpackage TemplateResources
12 class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
15 * Flag that it's an uncompiled resource
19 public $uncompiled = true;
22 * container for short_open_tag directive's value before executing PHP templates
26 protected $short_open_tag;
29 * Resource does implement populateCompiledFilepath() method
33 public $hasCompiledHandler = true;
36 * Create a new PHP Resource
38 public function __construct()
40 $this->short_open_tag = ini_get('short_open_tag');
44 * Load template's source from file into current template object
46 * @param Smarty_Template_Source $source source object
48 * @return string template source
49 * @throws SmartyException if source cannot be loaded
51 public function getContent(Smarty_Template_Source $source)
53 if ($source->exists) {
56 throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
60 * Render and output the template (without using the compiler)
62 * @param Smarty_Template_Source $source source object
63 * @param Smarty_Internal_Template $_template template object
66 * @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
68 public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
70 if (!$source->smarty->allow_php_templates) {
71 throw new SmartyException("PHP templates are disabled");
73 if (!$source->exists) {
74 throw new SmartyException("Unable to load template {$source->type} '{$source->name}'" .
75 ($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : ''));
79 extract($_template->getTemplateVars());
81 // include PHP template with short open tags enabled
82 ini_set('short_open_tag', '1');
83 /** @var Smarty_Internal_Template $_smarty_template
84 * used in included file
86 $_smarty_template = $_template;
87 include($source->filepath);
88 ini_set('short_open_tag', $this->short_open_tag);
92 * populate compiled object with compiled filepath
94 * @param Smarty_Template_Compiled $compiled compiled object
95 * @param Smarty_Internal_Template $_template template object (is ignored)
97 public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
99 $compiled->filepath = $_template->source->filepath;
100 $compiled->timestamp = $_template->source->timestamp;
101 $compiled->exists = $_template->source->exists;
102 $compiled->file_dependency[ $_template->source->uid ] =
103 array($compiled->filepath, $compiled->timestamp,
104 $_template->source->type,);