\Smarty_Resource_Mysql

MySQL Resource Resource Implementation based on the Custom API to use MySQL as the storage resource for Smarty's templates and configs.

Table definition:

CREATE TABLE IF NOT EXISTS `templates` (
  `name` varchar(100) NOT NULL,
  `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `source` text,
  PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Demo data:

INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');

Summary

Methods
Properties
Constants
populate()
getContent()
getBasename()
populateTimestamp()
buildUniqueResourceName()
load()
parseResourceName()
getUniqueTemplateName()
checkTimestamps()
source()
__construct()
renderUncompiled()
populateCompiledFilepath()
process()
$uncompiled
$recompiled
$sysplugins
$hasCompiledHandler
No constants found
fetch()
fetchTimestamp()
$db
$fetch
$mtime
N/A
No private methods found
No private properties found
N/A

Properties

$uncompiled

$uncompiled : boolean

Source is bypassing compiler

Type

boolean

$recompiled

$recompiled : boolean

Source must be recompiled on every occasion

Type

boolean

$sysplugins

$sysplugins : array

resource types provided by the core

Type

array

$hasCompiledHandler

$hasCompiledHandler : boolean

Flag if resource does implement populateCompiledFilepath() method

Type

boolean

$db

$db : 

Type

$fetch

$fetch : 

Type

$mtime

$mtime : 

Type

Methods

populate()

populate(\Smarty_Template_Source  $source, \Smarty_Internal_Template  $_template = null) 

populate Source Object with meta data from Resource

Parameters

\Smarty_Template_Source $source

source object

\Smarty_Internal_Template $_template

template object

getContent()

getContent(\Smarty_Template_Source  $source) : string

Load template's source into current template object

Parameters

\Smarty_Template_Source $source

source object

Throws

\SmartyException

if source cannot be loaded

Returns

string —

template source

getBasename()

getBasename(\Smarty_Template_Source  $source) : string

Determine basename for compiled filename

Parameters

\Smarty_Template_Source $source

source object

Returns

string —

resource's basename

populateTimestamp()

populateTimestamp(\Smarty_Template_Source  $source) 

populate Source Object with timestamp and exists from Resource

Parameters

\Smarty_Template_Source $source

source object

buildUniqueResourceName()

buildUniqueResourceName(\Smarty  $smarty, string  $resource_name, boolean  $isConfig = false) : string

modify resource_name according to resource handlers specifications

Parameters

\Smarty $smarty

Smarty instance

string $resource_name

resource_name to make unique

boolean $isConfig

flag for config resource

Returns

string —

unique resource name

load()

load(\Smarty  $smarty, string  $type) : \Smarty_Resource

Load Resource Handler

Parameters

\Smarty $smarty

smarty object

string $type

name of the resource

Throws

\SmartyException

Returns

\Smarty_Resource

Resource Handler

parseResourceName()

parseResourceName(string  $resource_name, string  $default_resource) : array

extract resource_type and resource_name from template_resource and config_resource

Parameters

string $resource_name

template_resource or config_resource to parse

string $default_resource

the default resource_type defined in $smarty

Returns

array —

with parsed resource name and type

getUniqueTemplateName()

getUniqueTemplateName(\Smarty_Internal_Template|\Smarty  $obj, string  $template_resource) : string

modify template_resource according to resource handlers specifications

Parameters

\Smarty_Internal_Template|\Smarty $obj

Smarty instance

string $template_resource

template_resource to extract resource handler and name of

Returns

string —

unique resource name

checkTimestamps()

checkTimestamps() 

source()

source(\Smarty_Internal_Template  $_template = null, \Smarty  $smarty = null, string  $template_resource = null) : \Smarty_Template_Source

initialize Source Object for given resource wrapper for backward compatibility to versions < 3.1.22 Either [$_template] or [$smarty, $template_resource] must be specified

Parameters

\Smarty_Internal_Template $_template

template object

\Smarty $smarty

smarty object

string $template_resource

resource identifier

Returns

\Smarty_Template_Source

Source Object

__construct()

__construct() 

renderUncompiled()

renderUncompiled(\Smarty_Template_Source  $source, \Smarty_Internal_Template  $_template) : void

Parameters

\Smarty_Template_Source $source
\Smarty_Internal_Template $_template

populateCompiledFilepath()

populateCompiledFilepath(\Smarty_Template_Compiled  $compiled, \Smarty_Internal_Template  $_template) : void

Parameters

\Smarty_Template_Compiled $compiled
\Smarty_Internal_Template $_template

process()

process(\Smarty_Internal_Template  $_smarty_tpl) : void

Parameters

\Smarty_Internal_Template $_smarty_tpl

fetch()

fetch(string  $name, string  $source, integer  $mtime) : void

Fetch a template and its modification time from database

Parameters

string $name

template name

string $source

template source

integer $mtime

template modification timestamp (epoch)

fetchTimestamp()

fetchTimestamp(string  $name) : integer

Fetch a template's modification time from database

Only implement it if modification times can be accessed faster than loading the complete template source.}}

Parameters

string $name

template name

Returns

integer —

timestamp (epoch) the template was modified