本文整理汇总了PHP中Smarty::getConfigDir方法的典型用法代码示例。如果您正苦于以下问题:PHP Smarty::getConfigDir方法的具体用法?PHP Smarty::getConfigDir怎么用?PHP Smarty::getConfigDir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smarty
的用法示例。
在下文中一共展示了Smarty::getConfigDir方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compileAll
/**
* Compile all template or config files
*
* @param \Smarty $smarty
* @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 bool $isConfig flag true if called for config files
*
* @return int number of template files compiled
*/
protected function compileAll(Smarty $smarty, $extension, $force_compile, $time_limit, $max_errors, $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 {
/* @var Smarty_Internal_Template $_tpl */
$_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->_clearTemplateCache();
if ($max_errors !== null && $_error_count == $max_errors) {
echo "\n<br><br>too many errors\n";
exit;
}
}
}
echo "\n<br>";
return $_count;
}
示例2: testInstall
//.........这里部分代码省略.........
if (!is_dir($_cache_dir)) {
$status = false;
$message = "FAILED: {$_cache_dir} is not a directory";
if ($errors === null) {
echo $message . ".\n";
} else {
$errors['cache_dir'] = $message;
}
} elseif (!is_readable($_cache_dir)) {
$status = false;
$message = "FAILED: {$_cache_dir} is not readable";
if ($errors === null) {
echo $message . ".\n";
} else {
$errors['cache_dir'] = $message;
}
} elseif (!is_writable($_cache_dir)) {
$status = false;
$message = "FAILED: {$_cache_dir} is not writable";
if ($errors === null) {
echo $message . ".\n";
} else {
$errors['cache_dir'] = $message;
}
} else {
if ($errors === null) {
echo "{$_cache_dir} is OK.\n";
}
}
if ($errors === null) {
echo "Testing configs directory...\n";
}
// test if all registered config_dir are accessible
foreach ($smarty->getConfigDir() as $config_dir) {
if (!is_dir($config_dir)) {
$status = false;
$message = "FAILED: {$config_dir} is not a directory";
if ($errors === null) {
echo $message . ".\n";
} else {
$errors['config_dir'] = $message;
}
} elseif (!is_readable($config_dir)) {
$status = false;
$message = "FAILED: {$config_dir} is not readable";
if ($errors === null) {
echo $message . ".\n";
} else {
$errors['config_dir'] = $message;
}
} else {
if ($errors === null) {
echo "{$config_dir} is OK.\n";
}
}
}
if ($errors === null) {
echo "Testing sysplugin files...\n";
}
// test if sysplugins are available
$source = SMARTY_SYSPLUGINS_DIR;
if (is_dir($source)) {
$expected = array("smarty_cacheresource.php" => true, "smarty_cacheresource_custom.php" => true, "smarty_cacheresource_keyvaluestore.php" => true, "smarty_config_source.php" => true, "smarty_internal_cacheresource_file.php" => true, "smarty_internal_compile_append.php" => true, "smarty_internal_compile_assign.php" => true, "smarty_internal_compile_block.php" => true, "smarty_internal_compile_break.php" => true, "smarty_internal_compile_call.php" => true, "smarty_internal_compile_capture.php" => true, "smarty_internal_compile_config_load.php" => true, "smarty_internal_compile_continue.php" => true, "smarty_internal_compile_debug.php" => true, "smarty_internal_compile_eval.php" => true, "smarty_internal_compile_extends.php" => true, "smarty_internal_compile_for.php" => true, "smarty_internal_compile_foreach.php" => true, "smarty_internal_compile_function.php" => true, "smarty_internal_compile_if.php" => true, "smarty_internal_compile_include.php" => true, "smarty_internal_compile_include_php.php" => true, "smarty_internal_compile_insert.php" => true, "smarty_internal_compile_ldelim.php" => true, "smarty_internal_compile_nocache.php" => true, "smarty_internal_compile_private_block_plugin.php" => true, "smarty_internal_compile_private_function_plugin.php" => true, "smarty_internal_compile_private_modifier.php" => true, "smarty_internal_compile_private_object_block_function.php" => true, "smarty_internal_compile_private_object_function.php" => true, "smarty_internal_compile_private_print_expression.php" => true, "smarty_internal_compile_private_registered_block.php" => true, "smarty_internal_compile_private_registered_function.php" => true, "smarty_internal_compile_private_special_variable.php" => true, "smarty_internal_compile_rdelim.php" => true, "smarty_internal_compile_section.php" => true, "smarty_internal_compile_setfilter.php" => true, "smarty_internal_compile_while.php" => true, "smarty_internal_compilebase.php" => true, "smarty_internal_config.php" => true, "smarty_internal_config_file_compiler.php" => true, "smarty_internal_configfilelexer.php" => true, "smarty_internal_configfileparser.php" => true, "smarty_internal_data.php" => true, "smarty_internal_debug.php" => true, "smarty_internal_filter_handler.php" => true, "smarty_internal_function_call_handler.php" => true, "smarty_internal_get_include_path.php" => true, "smarty_internal_nocache_insert.php" => true, "smarty_internal_parsetree.php" => true, "smarty_internal_resource_eval.php" => true, "smarty_internal_resource_extends.php" => true, "smarty_internal_resource_file.php" => true, "smarty_internal_resource_registered.php" => true, "smarty_internal_resource_stream.php" => true, "smarty_internal_resource_string.php" => true, "smarty_internal_smartytemplatecompiler.php" => true, "smarty_internal_template.php" => true, "smarty_internal_templatebase.php" => true, "smarty_internal_templatecompilerbase.php" => true, "smarty_internal_templatelexer.php" => true, "smarty_internal_templateparser.php" => true, "smarty_internal_utility.php" => true, "smarty_internal_write_file.php" => true, "smarty_resource.php" => true, "smarty_resource_custom.php" => true, "smarty_resource_recompiled.php" => true, "smarty_resource_uncompiled.php" => true, "smarty_security.php" => true);
$iterator = new DirectoryIterator($source);
foreach ($iterator as $file) {
if (!$file->isDot()) {
示例3: compileAllConfig
/**
* 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 {
$_config = new Smarty_Internal_Config($_config_file, $smarty);
if ($_config->mustCompile()) {
$_config->compileConfigSource();
$_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;
}
示例4: my_config_handler_file
function my_config_handler_file($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty)
{
return $smarty->getConfigDir(0) . 'test.conf';
}