Re: [SMARTY-DEV] smarty recompiling with op-code accelerators
[email protected] ("Jan Rosier")
| Newsgroups | php.smarty.dev |
|---|---|
| Message-ID | <01f801c464f2$b65b0c60$8f00a8c0@victoria> |
pete M wrote:
> Boots wrote:
>
> In my custom Smarty class, for example, I have it track the
>> version of the files in the cache/compiled directories by writing a
>> version file and comparing it to the running version of Smarty. It
>> will clear the directory on a mismatch (and then rewrite the version
>> file).
>
>
>>
>> xo boots
>
>
> I really like this idea ;-))
>
> pete
I think this has been on the list before, but anyway here is a example howto
extend Smarty to do this
I also attached a bigger example that shows howto customize Smarty futher
<?php
/**
* Template object...
* http://smarty.php.net/
*/
require_once 'Smarty/2.6.3/Smarty.class.php';
class Smarty_Extension extends Smarty
{
/**
* Constructor
*
* @access public
*
* @return void
*/
function Smarty_Extension()
{
parent::Smarty();
$this->checkVersion();
}
/**
* This method checks the current version of Smarty. On different
* versions the compiled and cached templates are deleted.
*
* @access public
*
* @return void
*/
function checkVersion()
{
$fname = $this->compile_dir . '/.version-' . $this->_version;
if (!file_exists($fname)) {
$this->clear_all_cache();
$this->clear_compiled_tpl();
touch($fname);
}
}
}
$smarty = new Smarty_Extension;
?>
Just my 2 cent,
Jan Rosier
smarty.txt
(text/plain, 2.5 KB)
<?php
/**
* Template object...
* http://smarty.php.net/
*/
require_once 'Smarty/2.6.3/Smarty.class.php';
class Smarty_Extension extends Smarty
{
/**
* The directory where config files are located.
*
* @var string
*/
var $config_dir = '';
/**
* The left delimiter used for the template tags.
*
* @var string
*/
var $left_delimiter = '<!--{';
/**
* An array of directories searched for plugins.
*
* @var array
*/
var $plugins_dir = Array('plugins', '../plugins');
/**
* The right delimiter used for the template tags.
*
* @var string
*/
var $right_delimiter = '}-->';
/**
* Constructor
*
* @access public
*
* @return void
*/
function Smarty_Extension()
{
parent::Smarty();
$this->checkVersion();
}
/**
* This replacement methode gives more readeable names to the compiled templates
* and is also quicker then the orginal methode ($use_sub_dirs is ignored)
*
* @access private
*
* @param string $auto_base
* @param string $auto_source
* @param string $auto_id
*
* @return string
*/
function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null)
{
$_return = $auto_base . DIRECTORY_SEPARATOR;
if (isset($auto_id)) {
$_return .= str_replace(DIRECTORY_SEPARATOR, '_', $auto_id) . '.';
}
if (isset($auto_source)) {
$_return .= str_replace(DIRECTORY_SEPARATOR, '_', $auto_source);
}
return $_return;
}
/**
* This replacement methode is using the file_get_contents function of PHP >= 4.3.0
* to read the contents of a file
*
* @access private
*
* @param string $file
*
* @return string
*/
function _read_file($file)
{
if (is_readable($file)) {
return file_get_contents($file);
} else {
return false;
}
}
/**
* This method check the current version of Smarty. On different
* versions the compiled and cached templates are deleted.
*
* @access public
*
* @return void
*/
function checkVersion()
{
$fname = $this->compile_dir . '/.version-' . $this->_version;
if (!file_exists($fname)) {
$this->clear_all_cache();
$this->clear_compiled_tpl();
touch($fname);
}
}
}
$smarty = new Smarty_Extension;
?>