mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-02 10:16:41 +03:00
Add cache->set method to engine
Signed-off-by: fzerorubigd <fzerorubigd@gmail.com>
This commit is contained in:
parent
eba64322c5
commit
c550491841
@ -2,9 +2,9 @@
|
|||||||
/**
|
/**
|
||||||
* This file is part of Handlebars-php
|
* This file is part of Handlebars-php
|
||||||
* Base on mustache-php https://github.com/bobthecow/mustache.php
|
* Base on mustache-php https://github.com/bobthecow/mustache.php
|
||||||
*
|
*
|
||||||
* PHP version 5.3
|
* PHP version 5.3
|
||||||
*
|
*
|
||||||
* @category Xamin
|
* @category Xamin
|
||||||
* @package Handlebars
|
* @package Handlebars
|
||||||
* @author fzerorubigd <fzerorubigd@gmail.com>
|
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||||
@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache interface
|
* Cache interface
|
||||||
* Base cache interface
|
* Base cache interface, Note that Handlebars.php never call for remove.
|
||||||
*
|
* Driver should take care of expiered cache.
|
||||||
|
*
|
||||||
* @category Xamin
|
* @category Xamin
|
||||||
* @package Handlebars
|
* @package Handlebars
|
||||||
* @author fzerorubigd <fzerorubigd@gmail.com>
|
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||||
@ -31,11 +32,11 @@
|
|||||||
interface Handlebars_Cache
|
interface Handlebars_Cache
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get cache for $name if exist.
|
* Get cache for $name if exist.
|
||||||
*
|
*
|
||||||
* @param string $name Cache id
|
* @param string $name Cache id
|
||||||
*
|
*
|
||||||
* @return data on hit, boolean false on cache not found
|
* @return data on hit, boolean false on cache not found
|
||||||
*/
|
*/
|
||||||
public function get($name);
|
public function get($name);
|
||||||
|
|
||||||
@ -50,11 +51,11 @@ interface Handlebars_Cache
|
|||||||
public function set($name, $value);
|
public function set($name, $value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove cache
|
* Remove cache
|
||||||
*
|
*
|
||||||
* @param string $name Cache id
|
* @param string $name Cache id
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function remove($name);
|
public function remove($name);
|
||||||
}
|
}
|
@ -2,9 +2,9 @@
|
|||||||
/**
|
/**
|
||||||
* This file is part of Handlebars-php
|
* This file is part of Handlebars-php
|
||||||
* Base on mustache-php https://github.com/bobthecow/mustache.php
|
* Base on mustache-php https://github.com/bobthecow/mustache.php
|
||||||
*
|
*
|
||||||
* PHP version 5.3
|
* PHP version 5.3
|
||||||
*
|
*
|
||||||
* @category Xamin
|
* @category Xamin
|
||||||
* @package Handlebars
|
* @package Handlebars
|
||||||
* @author fzerorubigd <fzerorubigd@gmail.com>
|
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||||
@ -18,7 +18,7 @@
|
|||||||
/**
|
/**
|
||||||
* Handlebars parser (infact its a mustache parser)
|
* Handlebars parser (infact its a mustache parser)
|
||||||
* This class is responsible for turning raw template source into a set of Mustache tokens.
|
* This class is responsible for turning raw template source into a set of Mustache tokens.
|
||||||
*
|
*
|
||||||
* @category Xamin
|
* @category Xamin
|
||||||
* @package Handlebars
|
* @package Handlebars
|
||||||
* @author fzerorubigd <fzerorubigd@gmail.com>
|
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||||
@ -42,7 +42,7 @@ class Handlebars_Engine
|
|||||||
*/
|
*/
|
||||||
private $_parser;
|
private $_parser;
|
||||||
/**
|
/**
|
||||||
* @var Handlebars_Helpers
|
* @var Handlebars_Helpers
|
||||||
*/
|
*/
|
||||||
private $_helpers;
|
private $_helpers;
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ class Handlebars_Engine
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Handlebars_Loader
|
* @var Handlebars_Loader
|
||||||
*/
|
*/
|
||||||
private $_partialsLoader;
|
private $_partialsLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,7 +67,7 @@ class Handlebars_Engine
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array parametes to pass to escape function, script prepend string to this array
|
* @var array parametes to pass to escape function, script prepend string to this array
|
||||||
*/
|
*/
|
||||||
private $_escapeArgs = array (
|
private $_escapeArgs = array (
|
||||||
ENT_COMPAT,
|
ENT_COMPAT,
|
||||||
'UTF-8'
|
'UTF-8'
|
||||||
@ -75,7 +75,7 @@ class Handlebars_Engine
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handlebars engine constructor
|
* Handlebars engine constructor
|
||||||
* $options array can contain :
|
* $options array can contain :
|
||||||
* helpers => Handlebars_Helpers object
|
* helpers => Handlebars_Helpers object
|
||||||
* escape => a callable function to escape values
|
* escape => a callable function to escape values
|
||||||
* escapeArgs => array to pass as extra parameter to escape function
|
* escapeArgs => array to pass as extra parameter to escape function
|
||||||
@ -93,15 +93,15 @@ class Handlebars_Engine
|
|||||||
|
|
||||||
if (isset($options['loader'])) {
|
if (isset($options['loader'])) {
|
||||||
$this->setLoader($options['loader']);
|
$this->setLoader($options['loader']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['partials_loader'])) {
|
if (isset($options['partials_loader'])) {
|
||||||
$this->setPartialsLoader($options['partials_loader']);
|
$this->setPartialsLoader($options['partials_loader']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['cache'])) {
|
if (isset($options['cache'])) {
|
||||||
$this->setCache($options['cache']);
|
$this->setCache($options['cache']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['escape'])) {
|
if (isset($options['escape'])) {
|
||||||
if (!is_callable($options['escape'])) {
|
if (!is_callable($options['escape'])) {
|
||||||
@ -110,15 +110,15 @@ class Handlebars_Engine
|
|||||||
|
|
||||||
$this->_escape = $options['escape'];
|
$this->_escape = $options['escape'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['escapeArgs'])) {
|
if (isset($options['escapeArgs'])) {
|
||||||
if (!is_array($options['escapeArgs'])) {
|
if (!is_array($options['escapeArgs'])) {
|
||||||
$options['escapeArgs'] = array($options['escapeArgs']);
|
$options['escapeArgs'] = array($options['escapeArgs']);
|
||||||
}
|
}
|
||||||
$this->_escapeArgs = $options['escapeArgs'];
|
$this->_escapeArgs = $options['escapeArgs'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut 'render' invocation.
|
* Shortcut 'render' invocation.
|
||||||
@ -150,7 +150,7 @@ class Handlebars_Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get helpers, or create new one if ther is no helper
|
* Get helpers, or create new one if ther is no helper
|
||||||
*
|
*
|
||||||
* @return Handlebars_Helpers
|
* @return Handlebars_Helpers
|
||||||
*/
|
*/
|
||||||
@ -158,7 +158,7 @@ class Handlebars_Engine
|
|||||||
{
|
{
|
||||||
if (!isset($this->_helpers)) {
|
if (!isset($this->_helpers)) {
|
||||||
$this->_helpers = new Handlebars_Helpers();
|
$this->_helpers = new Handlebars_Helpers();
|
||||||
}
|
}
|
||||||
return $this->_helpers;
|
return $this->_helpers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,10 +212,10 @@ class Handlebars_Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set current loader
|
* Set current loader
|
||||||
*
|
*
|
||||||
* @param Handlebars_Loader $loader handlebars loader
|
* @param Handlebars_Loader $loader handlebars loader
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setLoader(Handlebars_Loader $loader)
|
public function setLoader(Handlebars_Loader $loader)
|
||||||
@ -224,7 +224,7 @@ class Handlebars_Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get current loader
|
* get current loader
|
||||||
*
|
*
|
||||||
* @return Handlebars_Loader
|
* @return Handlebars_Loader
|
||||||
*/
|
*/
|
||||||
@ -232,15 +232,15 @@ class Handlebars_Engine
|
|||||||
{
|
{
|
||||||
if (!isset($this->_loader)) {
|
if (!isset($this->_loader)) {
|
||||||
$this->_loader = new Handlebars_Loader_StringLoader();
|
$this->_loader = new Handlebars_Loader_StringLoader();
|
||||||
}
|
}
|
||||||
return $this->_loader;
|
return $this->_loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set current partials loader
|
* Set current partials loader
|
||||||
*
|
*
|
||||||
* @param Handlebars_Loader $loader handlebars loader
|
* @param Handlebars_Loader $loader handlebars loader
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setPartialsLoader(Handlebars_Loader $loader)
|
public function setPartialsLoader(Handlebars_Loader $loader)
|
||||||
@ -249,7 +249,7 @@ class Handlebars_Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get current partials loader
|
* get current partials loader
|
||||||
*
|
*
|
||||||
* @return Handlebars_Loader
|
* @return Handlebars_Loader
|
||||||
*/
|
*/
|
||||||
@ -257,7 +257,7 @@ class Handlebars_Engine
|
|||||||
{
|
{
|
||||||
if (!isset($this->_partialsLoader)) {
|
if (!isset($this->_partialsLoader)) {
|
||||||
$this->_partialsLoader = new Handlebars_Loader_StringLoader();
|
$this->_partialsLoader = new Handlebars_Loader_StringLoader();
|
||||||
}
|
}
|
||||||
return $this->_partialsLoader;
|
return $this->_partialsLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,14 +282,14 @@ class Handlebars_Engine
|
|||||||
{
|
{
|
||||||
if (!isset($this->_cache)) {
|
if (!isset($this->_cache)) {
|
||||||
$this->_cache = new Handlebars_Cache_Dummy();
|
$this->_cache = new Handlebars_Cache_Dummy();
|
||||||
}
|
}
|
||||||
return $this->_cache;
|
return $this->_cache;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get current escape function
|
* Get current escape function
|
||||||
*
|
*
|
||||||
* @return callable
|
* @return callable
|
||||||
*/
|
*/
|
||||||
public function getEscape()
|
public function getEscape()
|
||||||
{
|
{
|
||||||
return $this->_escape;
|
return $this->_escape;
|
||||||
@ -306,15 +306,15 @@ class Handlebars_Engine
|
|||||||
{
|
{
|
||||||
if (!is_callable($escape)) {
|
if (!is_callable($escape)) {
|
||||||
throw new InvalidArgumentException('Escape function must be a callable');
|
throw new InvalidArgumentException('Escape function must be a callable');
|
||||||
}
|
}
|
||||||
$this->_escape = $escape;
|
$this->_escape = $escape;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current escape function
|
* Get current escape function
|
||||||
*
|
*
|
||||||
* @return callable
|
* @return callable
|
||||||
*/
|
*/
|
||||||
public function getEscapeArgs()
|
public function getEscapeArgs()
|
||||||
{
|
{
|
||||||
return $this->_escapeArgs;
|
return $this->_escapeArgs;
|
||||||
@ -331,7 +331,7 @@ class Handlebars_Engine
|
|||||||
{
|
{
|
||||||
if (!is_array($escapeArgs)) {
|
if (!is_array($escapeArgs)) {
|
||||||
$escapeArgs = array($escapeArgs);
|
$escapeArgs = array($escapeArgs);
|
||||||
}
|
}
|
||||||
$this->_escapeArgs = $escapeArgs;
|
$this->_escapeArgs = $escapeArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +339,7 @@ class Handlebars_Engine
|
|||||||
/**
|
/**
|
||||||
* Set the Handlebars Tokenizer instance.
|
* Set the Handlebars Tokenizer instance.
|
||||||
*
|
*
|
||||||
* @param Handlebars_Tokenizer $tokenizer tokenizer
|
* @param Handlebars_Tokenizer $tokenizer tokenizer
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -394,7 +394,7 @@ class Handlebars_Engine
|
|||||||
* Load a template by name with current template loader
|
* Load a template by name with current template loader
|
||||||
*
|
*
|
||||||
* @param string $name template name
|
* @param string $name template name
|
||||||
*
|
*
|
||||||
* @return Handlebars_Template
|
* @return Handlebars_Template
|
||||||
*/
|
*/
|
||||||
public function loadTemplate($name)
|
public function loadTemplate($name)
|
||||||
@ -417,7 +417,7 @@ class Handlebars_Engine
|
|||||||
$tree = $this->_tokenize($source);
|
$tree = $this->_tokenize($source);
|
||||||
return new Handlebars_Template($this, $tree, $source);
|
return new Handlebars_Template($this, $tree, $source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* try to tokenize source, or get them from cache if available
|
* try to tokenize source, or get them from cache if available
|
||||||
*
|
*
|
||||||
@ -432,7 +432,8 @@ class Handlebars_Engine
|
|||||||
if ($tree === false) {
|
if ($tree === false) {
|
||||||
$tokens = $this->getTokenizer()->scan($source);
|
$tokens = $this->getTokenizer()->scan($source);
|
||||||
$tree = $this->getParser()->parse($tokens);
|
$tree = $this->getParser()->parse($tokens);
|
||||||
}
|
$this->getCache()->set($hash, $tree);
|
||||||
|
}
|
||||||
return $tree;
|
return $tree;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user