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}!',
]);arrayMap of template keys to template strings.
arrayCustom 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"stringTemplate key.
booleanReturns 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 |
|
|---|
stringTemplate key.
\Pablotron\Luigi\TemplateReturns 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"stringTemplate key.
stringTemplate 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 UnknownTemplateErrorarrayTemplate 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"stringTemplate key.
arrayTemplate arguments.
stringReturns 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