mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- rewrite compileAll... utility methods
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
===== 3.1.28-dev===== (xx.xx.2015)
|
||||
06.08.2015
|
||||
- avoid possible circular object referances caused by parser/lexer objects
|
||||
- rewrite compileAll... utility methods
|
||||
|
||||
03.08.2015
|
||||
- rework clear cache methods
|
||||
|
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.28-dev/40';
|
||||
const SMARTY_VERSION = '3.1.28-dev/41';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
85
libs/sysplugins/smarty_internal_extension_compileall.php
Normal file
85
libs/sysplugins/smarty_internal_extension_compileall.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Extension CompileAll
|
||||
*
|
||||
* $smarty->clearCompiledTemplate() method
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
class Smarty_Internal_Extension_CompileAll
|
||||
{
|
||||
/**
|
||||
* Compile all template or config files
|
||||
*
|
||||
* @param string $extension template file name extension
|
||||
* @param bool $force_compile force all to recompile
|
||||
* @param int $time_limit set maximum execution time
|
||||
* @param int $max_errors set maximum allowed errors
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param bool $isConfig flag true if called for config files
|
||||
*
|
||||
* @return int number of template files compiled
|
||||
*/
|
||||
public static function compileAll($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty, $isConfig = false)
|
||||
{
|
||||
// switch off time limit
|
||||
if (function_exists('set_time_limit')) {
|
||||
@set_time_limit($time_limit);
|
||||
}
|
||||
$_count = 0;
|
||||
$_error_count = 0;
|
||||
$sourceDir = $isConfig ? $smarty->getConfigDir() : $smarty->getTemplateDir();
|
||||
// loop over array of source directories
|
||||
foreach ($sourceDir as $_dir) {
|
||||
$_dir_1 = new RecursiveDirectoryIterator($_dir);
|
||||
$_dir_2 = new RecursiveIteratorIterator($_dir_1);
|
||||
foreach ($_dir_2 as $_fileinfo) {
|
||||
$_file = $_fileinfo->getFilename();
|
||||
if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
|
||||
continue;
|
||||
}
|
||||
if (!substr_compare($_file, $extension, - strlen($extension)) == 0) {
|
||||
continue;
|
||||
}
|
||||
if ($_fileinfo->getPath() == !substr($_dir, 0, - 1)) {
|
||||
$_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
|
||||
}
|
||||
echo "\n<br>", $_dir, '---', $_file;
|
||||
flush();
|
||||
$_start_time = microtime(true);
|
||||
$_smarty = clone $smarty;
|
||||
$_smarty->force_compile = $force_compile;
|
||||
try {
|
||||
$_tpl = new $smarty->template_class($_file, $_smarty);
|
||||
$_tpl->caching = Smarty::CACHING_OFF;
|
||||
$_tpl->source = $isConfig ? Smarty_Template_Config::load($_tpl) : Smarty_Template_Source::load($_tpl);
|
||||
if ($_tpl->mustCompile()) {
|
||||
$_tpl->compileTemplateSource();
|
||||
$_count ++;
|
||||
echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
|
||||
flush();
|
||||
} else {
|
||||
echo ' is up to date';
|
||||
flush();
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
echo "\n<br> ------>Error: ", $e->getMessage(), "<br><br>\n";
|
||||
$_error_count ++;
|
||||
}
|
||||
// free memory
|
||||
unset($_tpl);
|
||||
$_smarty->template_objects = array();
|
||||
if ($max_errors !== null && $_error_count == $max_errors) {
|
||||
echo "\n<br><br>too many errors\n";
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "\n<br>";
|
||||
return $_count;
|
||||
}
|
||||
}
|
@@ -43,144 +43,6 @@ class Smarty_Internal_Utility
|
||||
// intentionally left blank
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile all template files
|
||||
*
|
||||
* @param string $extension template file name extension
|
||||
* @param bool $force_compile force all to recompile
|
||||
* @param int $time_limit set maximum execution time
|
||||
* @param int $max_errors set maximum allowed errors
|
||||
* @param Smarty $smarty Smarty instance
|
||||
*
|
||||
* @return integer number of template files compiled
|
||||
*/
|
||||
public static function compileAllTemplates($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty)
|
||||
{
|
||||
// switch off time limit
|
||||
if (function_exists('set_time_limit')) {
|
||||
@set_time_limit($time_limit);
|
||||
}
|
||||
$smarty->force_compile = $force_compile;
|
||||
$_count = 0;
|
||||
$_error_count = 0;
|
||||
// loop over array of template directories
|
||||
foreach ($smarty->getTemplateDir() as $_dir) {
|
||||
$_compileDirs = new RecursiveDirectoryIterator($_dir);
|
||||
$_compile = new RecursiveIteratorIterator($_compileDirs);
|
||||
foreach ($_compile as $_fileinfo) {
|
||||
$_file = $_fileinfo->getFilename();
|
||||
if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
|
||||
continue;
|
||||
}
|
||||
if (!substr_compare($_file, $extension, - strlen($extension)) == 0) {
|
||||
continue;
|
||||
}
|
||||
if ($_fileinfo->getPath() == substr($_dir, 0, - 1)) {
|
||||
$_template_file = $_file;
|
||||
} else {
|
||||
$_template_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
|
||||
}
|
||||
echo '<br>', $_dir, '---', $_template_file;
|
||||
flush();
|
||||
$_start_time = microtime(true);
|
||||
try {
|
||||
$_tpl = $smarty->createTemplate($_template_file, null, null, null, false);
|
||||
if ($_tpl->mustCompile()) {
|
||||
$_tpl->compileTemplateSource();
|
||||
$_count ++;
|
||||
echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
|
||||
flush();
|
||||
} else {
|
||||
echo ' is up to date';
|
||||
flush();
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
echo 'Error: ', $e->getMessage(), "<br><br>";
|
||||
$_error_count ++;
|
||||
}
|
||||
// free memory
|
||||
$smarty->template_objects = array();
|
||||
$_tpl->smarty->template_objects = array();
|
||||
$_tpl = null;
|
||||
if ($max_errors !== null && $_error_count == $max_errors) {
|
||||
echo '<br><br>too many errors';
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile all config files
|
||||
*
|
||||
* @param string $extension config file name extension
|
||||
* @param bool $force_compile force all to recompile
|
||||
* @param int $time_limit set maximum execution time
|
||||
* @param int $max_errors set maximum allowed errors
|
||||
* @param Smarty $smarty Smarty instance
|
||||
*
|
||||
* @return integer number of config files compiled
|
||||
*/
|
||||
public static function compileAllConfig($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty)
|
||||
{
|
||||
// switch off time limit
|
||||
if (function_exists('set_time_limit')) {
|
||||
@set_time_limit($time_limit);
|
||||
}
|
||||
$smarty->force_compile = $force_compile;
|
||||
$_count = 0;
|
||||
$_error_count = 0;
|
||||
// loop over array of template directories
|
||||
foreach ($smarty->getConfigDir() as $_dir) {
|
||||
$_compileDirs = new RecursiveDirectoryIterator($_dir);
|
||||
$_compile = new RecursiveIteratorIterator($_compileDirs);
|
||||
foreach ($_compile as $_fileinfo) {
|
||||
$_file = $_fileinfo->getFilename();
|
||||
if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
|
||||
continue;
|
||||
}
|
||||
if (!substr_compare($_file, $extension, - strlen($extension)) == 0) {
|
||||
continue;
|
||||
}
|
||||
if ($_fileinfo->getPath() == substr($_dir, 0, - 1)) {
|
||||
$_config_file = $_file;
|
||||
} else {
|
||||
$_config_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
|
||||
}
|
||||
echo '<br>', $_dir, '---', $_config_file;
|
||||
flush();
|
||||
$_start_time = microtime(true);
|
||||
try {
|
||||
$confObj = new $smarty->template_class($_config_file, $smarty);
|
||||
$confObj->caching = Smarty::CACHING_OFF;
|
||||
$confObj->source = Smarty_Template_Config::load($confObj);
|
||||
if ($confObj->mustCompile()) {
|
||||
$confObj->compileTemplateSource();
|
||||
$_count ++;
|
||||
echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
|
||||
flush();
|
||||
} else {
|
||||
echo ' is up to date';
|
||||
flush();
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
echo 'Error: ', $e->getMessage(), "<br><br>";
|
||||
$_error_count ++;
|
||||
}
|
||||
if ($max_errors !== null && $_error_count == $max_errors) {
|
||||
echo '<br><br>too many errors';
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of tag/attributes of all tags used by an template
|
||||
*
|
||||
|
Reference in New Issue
Block a user