4 * Smarty Method CompileAllTemplates
6 * Smarty::compileAllTemplates() method
9 * @subpackage PluginsInternal
12 class Smarty_Internal_Method_CompileAllTemplates
15 * Valid for Smarty object
22 * Compile all template files
24 * @api Smarty::compileAllTemplates()
26 * @param \Smarty $smarty passed smarty object
27 * @param string $extension file extension
28 * @param bool $force_compile force all to recompile
29 * @param int $time_limit
30 * @param int $max_errors
32 * @return integer number of template files recompiled
34 public function compileAllTemplates(Smarty $smarty, $extension = '.tpl', $force_compile = false, $time_limit = 0,
37 return $this->compileAll($smarty, $extension, $force_compile, $time_limit, $max_errors);
41 * Compile all template or config files
43 * @param \Smarty $smarty
44 * @param string $extension template file name extension
45 * @param bool $force_compile force all to recompile
46 * @param int $time_limit set maximum execution time
47 * @param int $max_errors set maximum allowed errors
48 * @param bool $isConfig flag true if called for config files
50 * @return int number of template files compiled
52 protected function compileAll(Smarty $smarty, $extension, $force_compile, $time_limit, $max_errors,
55 // switch off time limit
56 if (function_exists('set_time_limit')) {
57 @set_time_limit($time_limit);
61 $sourceDir = $isConfig ? $smarty->getConfigDir() : $smarty->getTemplateDir();
62 // loop over array of source directories
63 foreach ($sourceDir as $_dir) {
64 $_dir_1 = new RecursiveDirectoryIterator($_dir, defined('FilesystemIterator::FOLLOW_SYMLINKS') ?
65 FilesystemIterator::FOLLOW_SYMLINKS : 0);
66 $_dir_2 = new RecursiveIteratorIterator($_dir_1);
67 foreach ($_dir_2 as $_fileinfo) {
68 $_file = $_fileinfo->getFilename();
69 if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
72 if (!substr_compare($_file, $extension, - strlen($extension)) == 0) {
75 if ($_fileinfo->getPath() !== substr($_dir, 0, - 1)) {
76 $_file = substr($_fileinfo->getPath(), strlen($_dir)) . $smarty->ds . $_file;
78 echo "\n<br>", $_dir, '---', $_file;
80 $_start_time = microtime(true);
81 $_smarty = clone $smarty;
83 $_smarty->_cache = array();
84 $_smarty->ext = new Smarty_Internal_Extension_Handler();
85 $_smarty->ext->objType = $_smarty->_objType;
86 $_smarty->force_compile = $force_compile;
88 /* @var Smarty_Internal_Template $_tpl */
89 $_tpl = new $smarty->template_class($_file, $_smarty);
90 $_tpl->caching = Smarty::CACHING_OFF;
92 $isConfig ? Smarty_Template_Config::load($_tpl) : Smarty_Template_Source::load($_tpl);
93 if ($_tpl->mustCompile()) {
94 $_tpl->compileTemplateSource();
96 echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
99 echo ' is up to date';
103 catch (Exception $e) {
104 echo "\n<br> ------>Error: ", $e->getMessage(), "<br><br>\n";
109 $_smarty->_clearTemplateCache();
110 if ($max_errors !== null && $_error_count == $max_errors) {
111 echo "\n<br><br>too many errors\n";