Lazy-loading template cache.
Group a set of templates together and only parse them on an as-needed basis.
api | |
---|---|
package |
Pablotron\Luigi |
__construct(array $templates, array $filters = array())
Example:
# load cache class
use \Pablotron\Luigi\Cache;
# create template cache
$cache = new Cache([
'hi' => 'hi %{name}!',
]);
array
Map of template keys to template strings.
array
Custom filter map (optional).
offsetExists(string $key) : boolean
Example:
# load cache class
use \Pablotron\Luigi\Cache;
# create cache
$cache = new Cache([
'hi' => 'hi %{name}!',
]);
# get template 'hi' from cache
foreach (array('hi', 'nope') as $tmpl_key) {
echo "$key: " . (isset($cache[$key]) ? 'Yes' : 'No') . "\n"
}
# prints "hi: Yes" and "nope: No"
string
Template key.
boolean
Returns true if the template key exists.
offsetGet(string $key) : \Pablotron\Luigi\Template
Example:
# load cache class
use \Pablotron\Luigi\Cache;
# create cache
$cache = new Cache([
'hi' => 'hi %{name}!',
]);
# get template 'hi' from cache
$tmpl = $cache['hi'];
echo $tmpl->run([
'name' => 'Paul',
]);
# prints "hi Paul!"
Throws |
|
---|
string
Template key.
\Pablotron\Luigi\Template
Returns template associated with this key.
offsetSet(string $key, string $val) : void
Example:
# load cache class
use \Pablotron\Luigi\Cache;
# create cache
$cache = new Cache();
# add template to cache as 'hash-name'
$cache['hash-name'] = 'hashed name: %{name | hash sha1}';
echo $cache['hash-name']->run([
'name' => 'Paul',
]);
# prints "sha1 of name: c3687ab9880c26dfe7ab966a8a1701b5e017c2ff"
string
Template key.
string
Template string.
offsetUnset(array $key) : void
Example:
# load cache class
use \Pablotron\Luigi\Cache;
# create cache
$cache = new Cache([
'hi' => 'hi %{name}!',
]);
# remove template 'hi' from cache
unset($cache['hi']);
echo $cache['hi']->run([
'name' => 'Paul',
]);
# throws UnknownTemplateError
array
Template key.
run(string $key, array $args = array()) : string
Example:
# load cache class
use \Pablotron\Luigi\Cache;
# create cache
$cache = new Cache([
'my-template' => 'hello %{name | uc}',
]);
# run template
echo $cache->run('my-template', [
'name' => 'Paul',
]);
# prints "hello PAUL"
string
Template key.
array
Template arguments.
string
Returns the expanded template result.
templates : array
var |
Map of keys to template strings. Filter map (optional). Parsed template cache. |
---|
array
filters : array
var |
Map of keys to template strings. Filter map (optional). Parsed template cache. |
---|
array
lut : array
var |
Map of keys to template strings. Filter map (optional). Parsed template cache. |
---|
array