Merge branch 'release/2.5.0'
This commit is contained in:
@@ -3,3 +3,4 @@ php:
|
|||||||
- 5.2
|
- 5.2
|
||||||
- 5.3
|
- 5.3
|
||||||
- 5.4
|
- 5.4
|
||||||
|
- 5.5
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
@@ -34,6 +34,10 @@ if (file_exists($file)) {
|
|||||||
// and load the new one
|
// and load the new one
|
||||||
SymfonyClassCollectionLoader::load(array(
|
SymfonyClassCollectionLoader::load(array(
|
||||||
'Mustache_Engine',
|
'Mustache_Engine',
|
||||||
|
'Mustache_Cache',
|
||||||
|
'Mustache_Cache_AbstractCache',
|
||||||
|
'Mustache_Cache_FilesystemCache',
|
||||||
|
'Mustache_Cache_NoopCache',
|
||||||
'Mustache_Compiler',
|
'Mustache_Compiler',
|
||||||
'Mustache_Context',
|
'Mustache_Context',
|
||||||
'Mustache_Exception',
|
'Mustache_Exception',
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Mustache.php.
|
||||||
|
*
|
||||||
|
* (c) 2013 Justin Hileman
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mustache Cache interface.
|
||||||
|
*
|
||||||
|
* Interface for caching and loading Mustache_Template classes
|
||||||
|
* generated by the Mustache_Compiler.
|
||||||
|
*/
|
||||||
|
interface Mustache_Cache
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Load a compiled Mustache_Template class from cache.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
*
|
||||||
|
* @return boolean indicates successfully class load
|
||||||
|
*/
|
||||||
|
public function load($key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache and load a compiled Mustache_Template class.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function cache($key, $value);
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Mustache.php.
|
||||||
|
*
|
||||||
|
* (c) 2013 Justin Hileman
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract Mustache Cache class.
|
||||||
|
*
|
||||||
|
* Provides logging support to child implementations.
|
||||||
|
*
|
||||||
|
* @abstract
|
||||||
|
*/
|
||||||
|
abstract class Mustache_Cache_AbstractCache implements Mustache_Cache
|
||||||
|
{
|
||||||
|
private $logger = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current logger instance.
|
||||||
|
*
|
||||||
|
* @return Mustache_Logger|Psr\Log\LoggerInterface
|
||||||
|
*/
|
||||||
|
public function getLogger()
|
||||||
|
{
|
||||||
|
return $this->logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a logger instance.
|
||||||
|
*
|
||||||
|
* @param Mustache_Logger|Psr\Log\LoggerInterface $logger
|
||||||
|
*/
|
||||||
|
public function setLogger($logger = null)
|
||||||
|
{
|
||||||
|
if ($logger !== null && !($logger instanceof Mustache_Logger || is_a($logger, 'Psr\\Log\\LoggerInterface'))) {
|
||||||
|
throw new Mustache_Exception_InvalidArgumentException('Expected an instance of Mustache_Logger or Psr\\Log\\LoggerInterface.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a log record if logging is enabled.
|
||||||
|
*
|
||||||
|
* @param integer $level The logging level
|
||||||
|
* @param string $message The log message
|
||||||
|
* @param array $context The log context
|
||||||
|
*/
|
||||||
|
protected function log($level, $message, array $context = array())
|
||||||
|
{
|
||||||
|
if (isset($this->logger)) {
|
||||||
|
$this->logger->log($level, $message, $context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Mustache.php.
|
||||||
|
*
|
||||||
|
* (c) 2013 Justin Hileman
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mustache Cache filesystem implementation.
|
||||||
|
*
|
||||||
|
* A FilesystemCache instance caches Mustache Template classes from the filesystem by name:
|
||||||
|
*
|
||||||
|
* $cache = new Mustache_Cache_FilesystemCache(dirname(__FILE__).'/cache');
|
||||||
|
* $cache->cache($className, $compiledSource);
|
||||||
|
*
|
||||||
|
* The FilesystemCache benefits from any opcode caching that may be setup in your environment. So do that, k?
|
||||||
|
*/
|
||||||
|
class Mustache_Cache_FilesystemCache extends Mustache_Cache_AbstractCache
|
||||||
|
{
|
||||||
|
private $baseDir;
|
||||||
|
private $fileMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filesystem cache constructor.
|
||||||
|
*
|
||||||
|
* @param string $baseDir Directory for compiled templates.
|
||||||
|
* @param int $fileMode Override default permissions for cache files. Defaults to using the system-defined umask.
|
||||||
|
*/
|
||||||
|
public function __construct($baseDir, $fileMode = null)
|
||||||
|
{
|
||||||
|
$this->baseDir = $baseDir;
|
||||||
|
$this->fileMode = $fileMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the class from cache using `require_once`.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function load($key)
|
||||||
|
{
|
||||||
|
$fileName = $this->getCacheFilename($key);
|
||||||
|
if (!is_file($fileName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once $fileName;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache and load the compiled class
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function cache($key, $value)
|
||||||
|
{
|
||||||
|
$fileName = $this->getCacheFilename($key);
|
||||||
|
|
||||||
|
$this->log(
|
||||||
|
Mustache_Logger::DEBUG,
|
||||||
|
'Writing to template cache: "{fileName}"',
|
||||||
|
array('fileName' => $fileName)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->writeFile($fileName, $value);
|
||||||
|
$this->load($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the cache filename.
|
||||||
|
* Subclasses should override for custom cache directory structures.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getCacheFilename($name)
|
||||||
|
{
|
||||||
|
return sprintf('%s/%s.php', $this->baseDir, $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create cache directory
|
||||||
|
*
|
||||||
|
* @throws Mustache_Exception_RuntimeException If unable to create directory
|
||||||
|
*
|
||||||
|
* @param string $fileName
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function buildDirectoryForFilename($fileName)
|
||||||
|
{
|
||||||
|
$dirName = dirname($fileName);
|
||||||
|
if (!is_dir($dirName)) {
|
||||||
|
$this->log(
|
||||||
|
Mustache_Logger::INFO,
|
||||||
|
'Creating Mustache template cache directory: "{dirName}"',
|
||||||
|
array('dirName' => $dirName)
|
||||||
|
);
|
||||||
|
|
||||||
|
@mkdir($dirName, 0777, true);
|
||||||
|
if (!is_dir($dirName)) {
|
||||||
|
throw new Mustache_Exception_RuntimeException(sprintf('Failed to create cache directory "%s".', $dirName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dirName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write cache file
|
||||||
|
*
|
||||||
|
* @throws Mustache_Exception_RuntimeException If unable to write file
|
||||||
|
*
|
||||||
|
* @param string $fileName
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function writeFile($fileName, $value)
|
||||||
|
{
|
||||||
|
$dirName = $this->buildDirectoryForFilename($fileName);
|
||||||
|
|
||||||
|
$this->log(
|
||||||
|
Mustache_Logger::DEBUG,
|
||||||
|
'Caching compiled template to "{fileName}"',
|
||||||
|
array('fileName' => $fileName)
|
||||||
|
);
|
||||||
|
|
||||||
|
$tempFile = tempnam($dirName, basename($fileName));
|
||||||
|
if (false !== @file_put_contents($tempFile, $value)) {
|
||||||
|
if (@rename($tempFile, $fileName)) {
|
||||||
|
$mode = isset($this->fileMode) ? $this->fileMode : (0666 & ~umask());
|
||||||
|
@chmod($fileName, $mode);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->log(
|
||||||
|
Mustache_Logger::ERROR,
|
||||||
|
'Unable to rename Mustache temp cache file: "{tempName}" -> "{fileName}"',
|
||||||
|
array('tempName' => $tempFile, 'fileName' => $fileName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Mustache_Exception_RuntimeException(sprintf('Failed to write cache file "%s".', $fileName));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Mustache.php.
|
||||||
|
*
|
||||||
|
* (c) 2013 Justin Hileman
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mustache Cache in-memory implementation.
|
||||||
|
*
|
||||||
|
* The in-memory cache is used for uncached lambda section templates. It's also useful during development, but is not
|
||||||
|
* recommended for production use.
|
||||||
|
*/
|
||||||
|
class Mustache_Cache_NoopCache extends Mustache_Cache_AbstractCache
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Loads nothing. Move along.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function load($key)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the compiled Mustache Template class without caching.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function cache($key, $value)
|
||||||
|
{
|
||||||
|
$this->log(
|
||||||
|
Mustache_Logger::WARNING,
|
||||||
|
'Template cache disabled, evaluating "{className}" class at runtime',
|
||||||
|
array('className' => $key)
|
||||||
|
);
|
||||||
|
eval('?>' . $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
@@ -33,9 +33,9 @@ class Mustache_Compiler
|
|||||||
* @param string $tree Parse tree of Mustache tokens
|
* @param string $tree Parse tree of Mustache tokens
|
||||||
* @param string $name Mustache Template class name
|
* @param string $name Mustache Template class name
|
||||||
* @param bool $customEscape (default: false)
|
* @param bool $customEscape (default: false)
|
||||||
* @param int $entityFlags (default: ENT_COMPAT)
|
|
||||||
* @param string $charset (default: 'UTF-8')
|
* @param string $charset (default: 'UTF-8')
|
||||||
* @param bool $strictCallables (default: false)
|
* @param bool $strictCallables (default: false)
|
||||||
|
* @param int $entityFlags (default: ENT_COMPAT)
|
||||||
*
|
*
|
||||||
* @return string Generated PHP source code
|
* @return string Generated PHP source code
|
||||||
*/
|
*/
|
||||||
@@ -178,7 +178,8 @@ class Mustache_Compiler
|
|||||||
|
|
||||||
const SECTION_CALL = '
|
const SECTION_CALL = '
|
||||||
// %s section
|
// %s section
|
||||||
$buffer .= $this->section%s($context, $indent, $context->%s(%s));
|
$value = $context->%s(%s);%s
|
||||||
|
$buffer .= $this->section%s($context, $indent, $value);
|
||||||
';
|
';
|
||||||
|
|
||||||
const SECTION = '
|
const SECTION = '
|
||||||
@@ -187,9 +188,14 @@ class Mustache_Compiler
|
|||||||
$buffer = \'\';
|
$buffer = \'\';
|
||||||
if (%s) {
|
if (%s) {
|
||||||
$source = %s;
|
$source = %s;
|
||||||
|
$result = call_user_func($value, $source, $this->lambdaHelper);
|
||||||
|
if (strpos($result, \'{{\') === false) {
|
||||||
|
$buffer .= $result;
|
||||||
|
} else {
|
||||||
$buffer .= $this->mustache
|
$buffer .= $this->mustache
|
||||||
->loadLambda((string) call_user_func($value, $source, $this->lambdaHelper)%s)
|
->loadLambda((string) $result%s)
|
||||||
->renderInternal($context);
|
->renderInternal($context);
|
||||||
|
}
|
||||||
} elseif (!empty($value)) {
|
} elseif (!empty($value)) {
|
||||||
$values = $this->isIterable($value) ? $value : array($value);
|
$values = $this->isIterable($value) ? $value : array($value);
|
||||||
foreach ($values as $value) {
|
foreach ($values as $value) {
|
||||||
@@ -216,6 +222,12 @@ class Mustache_Compiler
|
|||||||
*/
|
*/
|
||||||
private function section($nodes, $id, $start, $end, $otag, $ctag, $level)
|
private function section($nodes, $id, $start, $end, $otag, $ctag, $level)
|
||||||
{
|
{
|
||||||
|
$filters = '';
|
||||||
|
|
||||||
|
if (isset($this->pragmas[Mustache_Engine::PRAGMA_FILTERS])) {
|
||||||
|
list($id, $filters) = $this->getFilters($id, $level);
|
||||||
|
}
|
||||||
|
|
||||||
$method = $this->getFindMethod($id);
|
$method = $this->getFindMethod($id);
|
||||||
$id = var_export($id, true);
|
$id = var_export($id, true);
|
||||||
$source = var_export(substr($this->source, $start, $end - $start), true);
|
$source = var_export(substr($this->source, $start, $end - $start), true);
|
||||||
@@ -233,12 +245,12 @@ class Mustache_Compiler
|
|||||||
$this->sections[$key] = sprintf($this->prepare(self::SECTION), $key, $callable, $source, $delims, $this->walk($nodes, 2));
|
$this->sections[$key] = sprintf($this->prepare(self::SECTION), $key, $callable, $source, $delims, $this->walk($nodes, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf($this->prepare(self::SECTION_CALL, $level), $id, $key, $method, $id);
|
return sprintf($this->prepare(self::SECTION_CALL, $level), $id, $method, $id, $filters, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
const INVERTED_SECTION = '
|
const INVERTED_SECTION = '
|
||||||
// %s inverted section
|
// %s inverted section
|
||||||
$value = $context->%s(%s);
|
$value = $context->%s(%s);%s
|
||||||
if (empty($value)) {
|
if (empty($value)) {
|
||||||
%s
|
%s
|
||||||
}';
|
}';
|
||||||
@@ -254,15 +266,21 @@ class Mustache_Compiler
|
|||||||
*/
|
*/
|
||||||
private function invertedSection($nodes, $id, $level)
|
private function invertedSection($nodes, $id, $level)
|
||||||
{
|
{
|
||||||
|
$filters = '';
|
||||||
|
|
||||||
|
if (isset($this->pragmas[Mustache_Engine::PRAGMA_FILTERS])) {
|
||||||
|
list($id, $filters) = $this->getFilters($id, $level);
|
||||||
|
}
|
||||||
|
|
||||||
$method = $this->getFindMethod($id);
|
$method = $this->getFindMethod($id);
|
||||||
$id = var_export($id, true);
|
$id = var_export($id, true);
|
||||||
|
|
||||||
return sprintf($this->prepare(self::INVERTED_SECTION, $level), $id, $method, $id, $this->walk($nodes, $level));
|
return sprintf($this->prepare(self::INVERTED_SECTION, $level), $id, $method, $id, $filters, $this->walk($nodes, $level));
|
||||||
}
|
}
|
||||||
|
|
||||||
const PARTIAL = '
|
const PARTIAL = '
|
||||||
if ($partial = $this->mustache->loadPartial(%s)) {
|
if ($partial = $this->mustache->loadPartial(%s)) {
|
||||||
$buffer .= $partial->renderInternal($context, %s);
|
$buffer .= $partial->renderInternal($context, $indent . %s);
|
||||||
}
|
}
|
||||||
';
|
';
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
@@ -133,11 +133,13 @@ class Mustache_Context
|
|||||||
private function findVariableInStack($id, array $stack)
|
private function findVariableInStack($id, array $stack)
|
||||||
{
|
{
|
||||||
for ($i = count($stack) - 1; $i >= 0; $i--) {
|
for ($i = count($stack) - 1; $i >= 0; $i--) {
|
||||||
if (is_object($stack[$i]) && !$stack[$i] instanceof Closure) {
|
if (is_object($stack[$i]) && !($stack[$i] instanceof Closure)) {
|
||||||
if (method_exists($stack[$i], $id)) {
|
if (method_exists($stack[$i], $id)) {
|
||||||
return $stack[$i]->$id();
|
return $stack[$i]->$id();
|
||||||
} elseif (isset($stack[$i]->$id)) {
|
} elseif (isset($stack[$i]->$id)) {
|
||||||
return $stack[$i]->$id;
|
return $stack[$i]->$id;
|
||||||
|
} elseif ($stack[$i] instanceof ArrayAccess && isset($stack[$i][$id])) {
|
||||||
|
return $stack[$i][$id];
|
||||||
}
|
}
|
||||||
} elseif (is_array($stack[$i]) && array_key_exists($id, $stack[$i])) {
|
} elseif (is_array($stack[$i]) && array_key_exists($id, $stack[$i])) {
|
||||||
return $stack[$i][$id];
|
return $stack[$i][$id];
|
||||||
|
|||||||
+89
-95
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
class Mustache_Engine
|
class Mustache_Engine
|
||||||
{
|
{
|
||||||
const VERSION = '2.4.1';
|
const VERSION = '2.5.0';
|
||||||
const SPEC_VERSION = '1.1.2';
|
const SPEC_VERSION = '1.1.2';
|
||||||
|
|
||||||
const PRAGMA_FILTERS = 'FILTERS';
|
const PRAGMA_FILTERS = 'FILTERS';
|
||||||
@@ -33,8 +33,9 @@ class Mustache_Engine
|
|||||||
|
|
||||||
// Environment
|
// Environment
|
||||||
private $templateClassPrefix = '__Mustache_';
|
private $templateClassPrefix = '__Mustache_';
|
||||||
private $cache = null;
|
private $cache;
|
||||||
private $cacheFileMode = null;
|
private $lambdaCache;
|
||||||
|
private $cacheLambdaTemplates = false;
|
||||||
private $loader;
|
private $loader;
|
||||||
private $partialsLoader;
|
private $partialsLoader;
|
||||||
private $helpers;
|
private $helpers;
|
||||||
@@ -53,13 +54,18 @@ class Mustache_Engine
|
|||||||
* // The class prefix for compiled templates. Defaults to '__Mustache_'.
|
* // The class prefix for compiled templates. Defaults to '__Mustache_'.
|
||||||
* 'template_class_prefix' => '__MyTemplates_',
|
* 'template_class_prefix' => '__MyTemplates_',
|
||||||
*
|
*
|
||||||
* // A cache directory for compiled templates. Mustache will not cache templates unless this is set
|
* // A Mustache cache instance or a cache directory string for compiled templates.
|
||||||
|
* // Mustache will not cache templates unless this is set.
|
||||||
* 'cache' => dirname(__FILE__).'/tmp/cache/mustache',
|
* 'cache' => dirname(__FILE__).'/tmp/cache/mustache',
|
||||||
*
|
*
|
||||||
* // Override default permissions for cache files. Defaults to using the system-defined umask. It is
|
* // Override default permissions for cache files. Defaults to using the system-defined umask. It is
|
||||||
* // *strongly* recommended that you configure your umask properly rather than overriding permissions here.
|
* // *strongly* recommended that you configure your umask properly rather than overriding permissions here.
|
||||||
* 'cache_file_mode' => 0666,
|
* 'cache_file_mode' => 0666,
|
||||||
*
|
*
|
||||||
|
* // Optionally, enable caching for lambda section templates. This is generally not recommended, as lambda
|
||||||
|
* // sections are often too dynamic to benefit from caching.
|
||||||
|
* 'cache_lambda_templates' => true,
|
||||||
|
*
|
||||||
* // A Mustache template loader instance. Uses a StringLoader if not specified.
|
* // A Mustache template loader instance. Uses a StringLoader if not specified.
|
||||||
* 'loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/views'),
|
* 'loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/views'),
|
||||||
*
|
*
|
||||||
@@ -112,11 +118,18 @@ class Mustache_Engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['cache'])) {
|
if (isset($options['cache'])) {
|
||||||
$this->cache = $options['cache'];
|
$cache = $options['cache'];
|
||||||
|
|
||||||
|
if (is_string($cache)) {
|
||||||
|
$mode = isset($options['cache_file_mode']) ? $options['cache_file_mode'] : null;
|
||||||
|
$cache = new Mustache_Cache_FilesystemCache($cache, $mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['cache_file_mode'])) {
|
$this->setCache($cache);
|
||||||
$this->cacheFileMode = $options['cache_file_mode'];
|
}
|
||||||
|
|
||||||
|
if (isset($options['cache_lambda_templates'])) {
|
||||||
|
$this->cacheLambdaTemplates = (bool) $options['cache_lambda_templates'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['loader'])) {
|
if (isset($options['loader'])) {
|
||||||
@@ -388,6 +401,10 @@ class Mustache_Engine
|
|||||||
throw new Mustache_Exception_InvalidArgumentException('Expected an instance of Mustache_Logger or Psr\\Log\\LoggerInterface.');
|
throw new Mustache_Exception_InvalidArgumentException('Expected an instance of Mustache_Logger or Psr\\Log\\LoggerInterface.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->getCache()->getLogger() === null) {
|
||||||
|
$this->getCache()->setLogger($logger);
|
||||||
|
}
|
||||||
|
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,6 +496,58 @@ class Mustache_Engine
|
|||||||
return $this->compiler;
|
return $this->compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Mustache Cache instance.
|
||||||
|
*
|
||||||
|
* @param Mustache_Cache $cache
|
||||||
|
*/
|
||||||
|
public function setCache(Mustache_Cache $cache)
|
||||||
|
{
|
||||||
|
if (isset($this->logger) && $cache->getLogger() === null) {
|
||||||
|
$cache->setLogger($this->getLogger());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cache = $cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current Mustache Cache instance.
|
||||||
|
*
|
||||||
|
* If no Cache instance has been explicitly specified, this method will instantiate and return a new one.
|
||||||
|
*
|
||||||
|
* @return Mustache_Cache
|
||||||
|
*/
|
||||||
|
public function getCache()
|
||||||
|
{
|
||||||
|
if (!isset($this->cache)) {
|
||||||
|
$this->setCache(new Mustache_Cache_NoopCache());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current Lambda Cache instance.
|
||||||
|
*
|
||||||
|
* If 'cache_lambda_templates' is enabled, this is the default cache instance. Otherwise, it is a NoopCache.
|
||||||
|
*
|
||||||
|
* @see Mustache_Engine::getCache
|
||||||
|
*
|
||||||
|
* @return Mustache_Cache
|
||||||
|
*/
|
||||||
|
protected function getLambdaCache()
|
||||||
|
{
|
||||||
|
if ($this->cacheLambdaTemplates) {
|
||||||
|
return $this->getCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($this->lambdaCache)) {
|
||||||
|
$this->lambdaCache = new Mustache_Cache_NoopCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->lambdaCache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to generate a Mustache template class.
|
* Helper method to generate a Mustache template class.
|
||||||
*
|
*
|
||||||
@@ -560,46 +629,37 @@ class Mustache_Engine
|
|||||||
$source = $delims . "\n" . $source;
|
$source = $delims . "\n" . $source;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->loadSource($source);
|
return $this->loadSource($source, $this->getLambdaCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate and return a Mustache Template instance by source.
|
* Instantiate and return a Mustache Template instance by source.
|
||||||
*
|
*
|
||||||
|
* Optionally provide a Mustache_Cache instance. This is used internally by Mustache_Engine::loadLambda to respect
|
||||||
|
* the 'cache_lambda_templates' configuration option.
|
||||||
|
*
|
||||||
* @see Mustache_Engine::loadTemplate
|
* @see Mustache_Engine::loadTemplate
|
||||||
* @see Mustache_Engine::loadPartial
|
* @see Mustache_Engine::loadPartial
|
||||||
* @see Mustache_Engine::loadLambda
|
* @see Mustache_Engine::loadLambda
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
|
* @param Mustache_Cache $cache (default: null)
|
||||||
*
|
*
|
||||||
* @return Mustache_Template
|
* @return Mustache_Template
|
||||||
*/
|
*/
|
||||||
private function loadSource($source)
|
private function loadSource($source, Mustache_Cache $cache = null)
|
||||||
{
|
{
|
||||||
$className = $this->getTemplateClassName($source);
|
$className = $this->getTemplateClassName($source);
|
||||||
|
|
||||||
if (!isset($this->templates[$className])) {
|
if (!isset($this->templates[$className])) {
|
||||||
if (!class_exists($className, false)) {
|
if ($cache === null) {
|
||||||
if ($fileName = $this->getCacheFilename($source)) {
|
$cache = $this->getCache();
|
||||||
if (!is_file($fileName)) {
|
|
||||||
$this->log(
|
|
||||||
Mustache_Logger::DEBUG,
|
|
||||||
'Writing "{className}" class to template cache: "{fileName}"',
|
|
||||||
array('className' => $className, 'fileName' => $fileName)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->writeCacheFile($fileName, $this->compile($source));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once $fileName;
|
if (!class_exists($className, false)) {
|
||||||
} else {
|
if (!$this->getCache()->load($className)) {
|
||||||
$this->log(
|
$compiled = $this->compile($source);
|
||||||
Mustache_Logger::WARNING,
|
$this->getCache()->cache($className, $compiled);
|
||||||
'Template cache disabled, evaluating "{className}" class at runtime',
|
|
||||||
array('className' => $className)
|
|
||||||
);
|
|
||||||
|
|
||||||
eval('?>'.$this->compile($source));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -666,72 +726,6 @@ class Mustache_Engine
|
|||||||
return $this->getCompiler()->compile($source, $tree, $name, isset($this->escape), $this->charset, $this->strictCallables, $this->entityFlags);
|
return $this->getCompiler()->compile($source, $tree, $name, isset($this->escape), $this->charset, $this->strictCallables, $this->entityFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to generate a Mustache Template class cache filename.
|
|
||||||
*
|
|
||||||
* @param string $source
|
|
||||||
*
|
|
||||||
* @return string Mustache Template class cache filename
|
|
||||||
*/
|
|
||||||
private function getCacheFilename($source)
|
|
||||||
{
|
|
||||||
if ($this->cache) {
|
|
||||||
return sprintf('%s/%s.php', $this->cache, $this->getTemplateClassName($source));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to dump a generated Mustache Template subclass to the file cache.
|
|
||||||
*
|
|
||||||
* @throws Mustache_Exception_RuntimeException if unable to create the cache directory or write to $fileName.
|
|
||||||
*
|
|
||||||
* @param string $fileName
|
|
||||||
* @param string $source
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
private function writeCacheFile($fileName, $source)
|
|
||||||
{
|
|
||||||
$dirName = dirname($fileName);
|
|
||||||
if (!is_dir($dirName)) {
|
|
||||||
$this->log(
|
|
||||||
Mustache_Logger::INFO,
|
|
||||||
'Creating Mustache template cache directory: "{dirName}"',
|
|
||||||
array('dirName' => $dirName)
|
|
||||||
);
|
|
||||||
|
|
||||||
@mkdir($dirName, 0777, true);
|
|
||||||
if (!is_dir($dirName)) {
|
|
||||||
throw new Mustache_Exception_RuntimeException(sprintf('Failed to create cache directory "%s".', $dirName));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->log(
|
|
||||||
Mustache_Logger::DEBUG,
|
|
||||||
'Caching compiled template to "{fileName}"',
|
|
||||||
array('fileName' => $fileName)
|
|
||||||
);
|
|
||||||
|
|
||||||
$tempFile = tempnam($dirName, basename($fileName));
|
|
||||||
if (false !== @file_put_contents($tempFile, $source)) {
|
|
||||||
if (@rename($tempFile, $fileName)) {
|
|
||||||
$mode = isset($this->cacheFileMode) ? $this->cacheFileMode : (0666 & ~umask());
|
|
||||||
@chmod($fileName, $mode);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->log(
|
|
||||||
Mustache_Logger::ERROR,
|
|
||||||
'Unable to rename Mustache temp cache file: "{tempName}" -> "{fileName}"',
|
|
||||||
array('tempName' => $tempFile, 'fileName' => $fileName)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Mustache_Exception_RuntimeException(sprintf('Failed to write cache file "%s".', $fileName));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a log record if logging is enabled.
|
* Add a log record if logging is enabled.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
+10
-1
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
@@ -45,6 +45,7 @@ interface Mustache_Logger
|
|||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function emergency($message, array $context = array());
|
public function emergency($message, array $context = array());
|
||||||
@@ -57,6 +58,7 @@ interface Mustache_Logger
|
|||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function alert($message, array $context = array());
|
public function alert($message, array $context = array());
|
||||||
@@ -68,6 +70,7 @@ interface Mustache_Logger
|
|||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function critical($message, array $context = array());
|
public function critical($message, array $context = array());
|
||||||
@@ -78,6 +81,7 @@ interface Mustache_Logger
|
|||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function error($message, array $context = array());
|
public function error($message, array $context = array());
|
||||||
@@ -90,6 +94,7 @@ interface Mustache_Logger
|
|||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function warning($message, array $context = array());
|
public function warning($message, array $context = array());
|
||||||
@@ -99,6 +104,7 @@ interface Mustache_Logger
|
|||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function notice($message, array $context = array());
|
public function notice($message, array $context = array());
|
||||||
@@ -110,6 +116,7 @@ interface Mustache_Logger
|
|||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function info($message, array $context = array());
|
public function info($message, array $context = array());
|
||||||
@@ -119,6 +126,7 @@ interface Mustache_Logger
|
|||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function debug($message, array $context = array());
|
public function debug($message, array $context = array());
|
||||||
@@ -129,6 +137,7 @@ interface Mustache_Logger
|
|||||||
* @param mixed $level
|
* @param mixed $level
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function log($level, $message, array $context = array());
|
public function log($level, $message, array $context = array());
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Mustache.php.
|
||||||
|
*
|
||||||
|
* (c) 2013 Justin Hileman
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Mustache_Test_Cache_AbstractCacheTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testGetSetLogger()
|
||||||
|
{
|
||||||
|
$cache = new CacheStub();
|
||||||
|
$logger = new Mustache_Logger_StreamLogger('php://stdout');
|
||||||
|
$cache->setLogger($logger);
|
||||||
|
$this->assertSame($logger, $cache->getLogger());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Mustache_Exception_InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testSetLoggerThrowsExceptions()
|
||||||
|
{
|
||||||
|
$cache = new CacheStub();
|
||||||
|
$logger = new StdClass();
|
||||||
|
$cache->setLogger($logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CacheStub extends Mustache_Cache_AbstractCache
|
||||||
|
{
|
||||||
|
public function load($key)
|
||||||
|
{
|
||||||
|
// nada
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cache($key, $value)
|
||||||
|
{
|
||||||
|
// nada
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Mustache.php.
|
||||||
|
*
|
||||||
|
* (c) 2013 Justin Hileman
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group functional
|
||||||
|
*/
|
||||||
|
class Mustache_Test_Cache_FilesystemCacheTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
private static $tempDir;
|
||||||
|
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
self::$tempDir = sys_get_temp_dir() . '/mustache_test';
|
||||||
|
if (file_exists(self::$tempDir)) {
|
||||||
|
self::rmdir(self::$tempDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCacheGetNone()
|
||||||
|
{
|
||||||
|
$key = 'some key';
|
||||||
|
$cache = new Mustache_Cache_FilesystemCache(self::$tempDir);;
|
||||||
|
$loaded = $cache->load($key);
|
||||||
|
|
||||||
|
$this->assertFalse($loaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCachePut()
|
||||||
|
{
|
||||||
|
$key = 'some key';
|
||||||
|
$value = '<?php /* some value */';
|
||||||
|
$cache = new Mustache_Cache_FilesystemCache(self::$tempDir);;
|
||||||
|
$cache->cache($key, $value);
|
||||||
|
$loaded = $cache->load($key);
|
||||||
|
|
||||||
|
$this->assertTrue($loaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function rmdir($path)
|
||||||
|
{
|
||||||
|
$path = rtrim($path, '/').'/';
|
||||||
|
$handle = opendir($path);
|
||||||
|
while (($file = readdir($handle)) !== false) {
|
||||||
|
if ($file == '.' || $file == '..') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fullpath = $path.$file;
|
||||||
|
if (is_dir($fullpath)) {
|
||||||
|
self::rmdir($fullpath);
|
||||||
|
} else {
|
||||||
|
unlink($fullpath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir($handle);
|
||||||
|
rmdir($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
@@ -96,6 +96,29 @@ class Mustache_Test_ContextTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('<foo>', $context->find('foo'));
|
$this->assertEquals('<foo>', $context->find('foo'));
|
||||||
$this->assertEquals('<bar>', $context->findDot('bar'));
|
$this->assertEquals('<bar>', $context->findDot('bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testArrayAccessFind()
|
||||||
|
{
|
||||||
|
$access = new Mustache_Test_TestArrayAccess(array(
|
||||||
|
'a' => array('b' => array('c' => 'see')),
|
||||||
|
'b' => 'bee',
|
||||||
|
));
|
||||||
|
|
||||||
|
$context = new Mustache_Context($access);
|
||||||
|
$this->assertEquals('bee', $context->find('b'));
|
||||||
|
$this->assertEquals('see', $context->findDot('a.b.c'));
|
||||||
|
$this->assertEquals(null, $context->findDot('a.b.c.d'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAccessorPriority()
|
||||||
|
{
|
||||||
|
$context = new Mustache_Context(new Mustache_Test_AllTheThings);
|
||||||
|
|
||||||
|
$this->assertEquals('win', $context->find('foo'), 'method beats property');
|
||||||
|
$this->assertEquals('win', $context->find('bar'), 'property beats ArrayAccess');
|
||||||
|
$this->assertEquals('win', $context->find('baz'), 'ArrayAccess stands alone');
|
||||||
|
$this->assertEquals('win', $context->find('qux'), 'ArrayAccess beats private property');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Mustache_Test_TestDummy
|
class Mustache_Test_TestDummy
|
||||||
@@ -117,3 +140,82 @@ class Mustache_Test_TestDummy
|
|||||||
return '<bar>';
|
return '<bar>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Mustache_Test_TestArrayAccess implements ArrayAccess
|
||||||
|
{
|
||||||
|
private $container = array();
|
||||||
|
|
||||||
|
public function __construct($array)
|
||||||
|
{
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
|
$this->container[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetSet($offset, $value)
|
||||||
|
{
|
||||||
|
if (is_null($offset)) {
|
||||||
|
$this->container[] = $value;
|
||||||
|
} else {
|
||||||
|
$this->container[$offset] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetExists($offset)
|
||||||
|
{
|
||||||
|
return isset($this->container[$offset]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetUnset($offset)
|
||||||
|
{
|
||||||
|
unset($this->container[$offset]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetGet($offset)
|
||||||
|
{
|
||||||
|
return isset($this->container[$offset]) ? $this->container[$offset] : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Mustache_Test_AllTheThings implements ArrayAccess
|
||||||
|
{
|
||||||
|
public $foo = 'fail';
|
||||||
|
public $bar = 'win';
|
||||||
|
private $qux = 'fail';
|
||||||
|
|
||||||
|
public function foo()
|
||||||
|
{
|
||||||
|
return 'win';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetExists($offset)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetGet($offset)
|
||||||
|
{
|
||||||
|
switch ($offset) {
|
||||||
|
case 'foo':
|
||||||
|
case 'bar':
|
||||||
|
return 'fail';
|
||||||
|
|
||||||
|
case 'baz':
|
||||||
|
case 'qux':
|
||||||
|
return 'win';
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 'lolwhut';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetSet($offset, $value)
|
||||||
|
{
|
||||||
|
// nada
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetUnset($offset)
|
||||||
|
{
|
||||||
|
// nada
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
@@ -45,6 +45,7 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase
|
|||||||
'bar' => 'BAR',
|
'bar' => 'BAR',
|
||||||
),
|
),
|
||||||
'escape' => 'strtoupper',
|
'escape' => 'strtoupper',
|
||||||
|
'entity_flags' => ENT_QUOTES,
|
||||||
'charset' => 'ISO-8859-1',
|
'charset' => 'ISO-8859-1',
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -54,10 +55,12 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('{{ foo }}', $partialsLoader->load('foo'));
|
$this->assertEquals('{{ foo }}', $partialsLoader->load('foo'));
|
||||||
$this->assertContains('__whot__', $mustache->getTemplateClassName('{{ foo }}'));
|
$this->assertContains('__whot__', $mustache->getTemplateClassName('{{ foo }}'));
|
||||||
$this->assertEquals('strtoupper', $mustache->getEscape());
|
$this->assertEquals('strtoupper', $mustache->getEscape());
|
||||||
|
$this->assertEquals(ENT_QUOTES, $mustache->getEntityFlags());
|
||||||
$this->assertEquals('ISO-8859-1', $mustache->getCharset());
|
$this->assertEquals('ISO-8859-1', $mustache->getCharset());
|
||||||
$this->assertTrue($mustache->hasHelper('foo'));
|
$this->assertTrue($mustache->hasHelper('foo'));
|
||||||
$this->assertTrue($mustache->hasHelper('bar'));
|
$this->assertTrue($mustache->hasHelper('bar'));
|
||||||
$this->assertFalse($mustache->hasHelper('baz'));
|
$this->assertFalse($mustache->hasHelper('baz'));
|
||||||
|
$this->assertInstanceOf('Mustache_Cache_FilesystemCache', $mustache->getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFoo()
|
public static function getFoo()
|
||||||
@@ -95,6 +98,7 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase
|
|||||||
$parser = new Mustache_Parser;
|
$parser = new Mustache_Parser;
|
||||||
$compiler = new Mustache_Compiler;
|
$compiler = new Mustache_Compiler;
|
||||||
$mustache = new Mustache_Engine;
|
$mustache = new Mustache_Engine;
|
||||||
|
$cache = new Mustache_Cache_FilesystemCache(self::$tempDir);
|
||||||
|
|
||||||
$this->assertNotSame($logger, $mustache->getLogger());
|
$this->assertNotSame($logger, $mustache->getLogger());
|
||||||
$mustache->setLogger($logger);
|
$mustache->setLogger($logger);
|
||||||
@@ -119,6 +123,10 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertNotSame($compiler, $mustache->getCompiler());
|
$this->assertNotSame($compiler, $mustache->getCompiler());
|
||||||
$mustache->setCompiler($compiler);
|
$mustache->setCompiler($compiler);
|
||||||
$this->assertSame($compiler, $mustache->getCompiler());
|
$this->assertSame($compiler, $mustache->getCompiler());
|
||||||
|
|
||||||
|
$this->assertNotSame($cache, $mustache->getCache());
|
||||||
|
$mustache->setCache($cache);
|
||||||
|
$this->assertSame($cache, $mustache->getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,10 +142,29 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase
|
|||||||
$source = '{{ foo }}';
|
$source = '{{ foo }}';
|
||||||
$template = $mustache->loadTemplate($source);
|
$template = $mustache->loadTemplate($source);
|
||||||
$className = $mustache->getTemplateClassName($source);
|
$className = $mustache->getTemplateClassName($source);
|
||||||
$fileName = self::$tempDir . '/' . $className . '.php';
|
|
||||||
$this->assertInstanceOf($className, $template);
|
$this->assertInstanceOf($className, $template);
|
||||||
$this->assertFileExists($fileName);
|
}
|
||||||
$this->assertContains("\nclass $className extends Mustache_Template", file_get_contents($fileName));
|
|
||||||
|
public function testLambdaCache()
|
||||||
|
{
|
||||||
|
$mustache = new MustacheStub(array(
|
||||||
|
'cache' => self::$tempDir,
|
||||||
|
'cache_lambda_templates' => true,
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertNotInstanceOf('Mustache_Cache_NoopCache', $mustache->getProtectedLambdaCache());
|
||||||
|
$this->assertSame($mustache->getCache(), $mustache->getProtectedLambdaCache());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWithoutLambdaCache()
|
||||||
|
{
|
||||||
|
$mustache = new MustacheStub(array(
|
||||||
|
'cache' => self::$tempDir
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Mustache_Cache_NoopCache', $mustache->getProtectedLambdaCache());
|
||||||
|
$this->assertNotSame($mustache->getCache(), $mustache->getProtectedLambdaCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -348,10 +375,16 @@ class MustacheStub extends Mustache_Engine
|
|||||||
{
|
{
|
||||||
public $source;
|
public $source;
|
||||||
public $template;
|
public $template;
|
||||||
|
|
||||||
public function loadTemplate($source)
|
public function loadTemplate($source)
|
||||||
{
|
{
|
||||||
$this->source = $source;
|
$this->source = $source;
|
||||||
|
|
||||||
return $this->template;
|
return $this->template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getProtectedLambdaCache()
|
||||||
|
{
|
||||||
|
return $this->getLambdaCache();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ EOS;
|
|||||||
|
|
||||||
$tpl = $m->loadTemplate($src);
|
$tpl = $m->loadTemplate($src);
|
||||||
|
|
||||||
|
|
||||||
$data = new Mustache_Test_Functional_ClassWithLambda();
|
$data = new Mustache_Test_Functional_ClassWithLambda();
|
||||||
$this->assertEquals($expected, $tpl->render($data));
|
$this->assertEquals($expected, $tpl->render($data));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Mustache.php.
|
||||||
|
*
|
||||||
|
* (c) 2013 Justin Hileman
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group filters
|
||||||
|
* @group functional
|
||||||
|
*/
|
||||||
|
class Mustache_Test_FiveThree_Functional_SectionFiltersTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
private $mustache;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->mustache = new Mustache_Engine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSingleFilter()
|
||||||
|
{
|
||||||
|
$tpl = $this->mustache->loadTemplate('{{% FILTERS }}{{# word | echo }}{{ . }}!{{/ word | echo }}');
|
||||||
|
|
||||||
|
$this->mustache->addHelper('echo', function($value) {
|
||||||
|
return array($value, $value, $value);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->assertEquals('bacon!bacon!bacon!', $tpl->render(array('word' => 'bacon')));
|
||||||
|
}
|
||||||
|
|
||||||
|
const CHAINED_FILTERS_TPL = <<<EOS
|
||||||
|
{{% FILTERS }}
|
||||||
|
{{# word | echo | with_index }}
|
||||||
|
{{ key }}: {{ value }}
|
||||||
|
{{/ word | echo | with_index }}
|
||||||
|
EOS;
|
||||||
|
|
||||||
|
public function testChainedFilters()
|
||||||
|
{
|
||||||
|
$tpl = $this->mustache->loadTemplate(self::CHAINED_FILTERS_TPL);
|
||||||
|
|
||||||
|
$this->mustache->addHelper('echo', function($value) {
|
||||||
|
return array($value, $value, $value);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->mustache->addHelper('with_index', function($value) {
|
||||||
|
return array_map(function($k, $v) {
|
||||||
|
return array(
|
||||||
|
'key' => $k,
|
||||||
|
'value' => $v,
|
||||||
|
);
|
||||||
|
}, array_keys($value), $value);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->assertEquals("0: bacon\n1: bacon\n2: bacon\n", $tpl->render(array('word' => 'bacon')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInterpolateFirst()
|
||||||
|
{
|
||||||
|
$tpl = $this->mustache->loadTemplate('{{% FILTERS }}{{# foo | bar }}{{ . }}{{/ foo | bar }}');
|
||||||
|
$this->assertEquals('win!', $tpl->render(array(
|
||||||
|
'foo' => 'FOO',
|
||||||
|
'bar' => function($value) {
|
||||||
|
return ($value === 'FOO') ? 'win!' : 'fail :(';
|
||||||
|
},
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Mustache_Exception_UnknownFilterException
|
||||||
|
* @dataProvider getBrokenPipes
|
||||||
|
*/
|
||||||
|
public function testThrowsExceptionForBrokenPipes($tpl, $data)
|
||||||
|
{
|
||||||
|
$this->mustache
|
||||||
|
->loadTemplate(sprintf('{{%% FILTERS }}{{# %s }}{{ . }}{{/ %s }}', $tpl, $tpl))
|
||||||
|
->render($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBrokenPipes()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('foo | bar', array()),
|
||||||
|
array('foo | bar', array('foo' => 'FOO')),
|
||||||
|
array('foo | bar', array('foo' => 'FOO', 'bar' => 'BAR')),
|
||||||
|
array('foo | bar', array('foo' => 'FOO', 'bar' => array(1, 2))),
|
||||||
|
array('foo | bar | baz', array('foo' => 'FOO', 'bar' => function() { return 'BAR'; })),
|
||||||
|
array('foo | bar | baz', array('foo' => 'FOO', 'baz' => function() { return 'BAZ'; })),
|
||||||
|
array('foo | bar | baz', array('bar' => function() { return 'BAR'; })),
|
||||||
|
array('foo | bar | baz', array('baz' => function() { return 'BAZ'; })),
|
||||||
|
array('foo | bar.baz', array('foo' => 'FOO', 'bar' => function() { return 'BAR'; }, 'baz' => function() { return 'BAZ'; })),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -73,7 +73,6 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group wip
|
* @group wip
|
||||||
* @dataProvider strictCallables
|
* @dataProvider strictCallables
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
@@ -71,6 +71,35 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework
|
|||||||
$dracula->name = 'Dracula';
|
$dracula->name = 'Dracula';
|
||||||
$this->assertEquals('Count Dracula', $tpl->render($dracula));
|
$this->assertEquals('Count Dracula', $tpl->render($dracula));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPassthroughOptimization()
|
||||||
|
{
|
||||||
|
$mustache = $this->getMock('Mustache_Engine', array('loadLambda'));
|
||||||
|
$mustache->expects($this->never())
|
||||||
|
->method('loadLambda');
|
||||||
|
|
||||||
|
$tpl = $mustache->loadTemplate('{{#wrap}}NAME{{/wrap}}');
|
||||||
|
|
||||||
|
$foo = new Mustache_Test_Functional_Foo;
|
||||||
|
$foo->wrap = array($foo, 'wrapWithEm');
|
||||||
|
|
||||||
|
$this->assertEquals('<em>NAME</em>', $tpl->render($foo));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWithoutPassthroughOptimization()
|
||||||
|
{
|
||||||
|
$mustache = $this->getMock('Mustache_Engine', array('loadLambda'));
|
||||||
|
$mustache->expects($this->once())
|
||||||
|
->method('loadLambda')
|
||||||
|
->will($this->returnValue($mustache->loadTemplate('<em>{{ name }}</em>')));
|
||||||
|
|
||||||
|
$tpl = $mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}');
|
||||||
|
|
||||||
|
$foo = new Mustache_Test_Functional_Foo;
|
||||||
|
$foo->wrap = array($foo, 'wrapWithEm');
|
||||||
|
|
||||||
|
$this->assertEquals('<em>' . $foo->name . '</em>', $tpl->render($foo));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Mustache_Test_Functional_Foo
|
class Mustache_Test_Functional_Foo
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Mustache.php.
|
* This file is part of Mustache.php.
|
||||||
*
|
*
|
||||||
* (c) 2012 Justin Hileman
|
* (c) 2013 Justin Hileman
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class NestedPartials
|
||||||
|
{
|
||||||
|
public $val = 'FOURTH!';
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<first>
|
||||||
|
{{> second }}
|
||||||
|
</first>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<first>
|
||||||
|
<second>
|
||||||
|
<third>
|
||||||
|
FOURTH!
|
||||||
|
</third>
|
||||||
|
</second>
|
||||||
|
</first>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{{ val }}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<second>
|
||||||
|
{{> third }}
|
||||||
|
</second>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<third>
|
||||||
|
{{> fourth }}
|
||||||
|
</third>
|
||||||
Reference in New Issue
Block a user