Merge branch 'release/2.12.0'

This commit is contained in:
Justin Hileman
2017-07-11 05:54:05 -07:00
111 changed files with 712 additions and 160 deletions
+16 -10
View File
@@ -1,15 +1,21 @@
language: php language: php
php: sudo: false
- 5.2
- 5.3 matrix:
- 5.4 include:
- 5.5 - php: 5.2
- 5.6 - php: 5.3
- 7.0 - php: 5.4
- hhvm - php: 5.5
- php: 5.6
- php: 7.0
- php: 7.1
- php: hhvm
dist: trusty
script: script:
- phpunit - '[[ "$TRAVIS_PHP_VERSION" = 5.2* ]] && phpunit || vendor/bin/phpunit --verbose'
sudo: false install:
- '[[ "$TRAVIS_PHP_VERSION" = 5.2* ]] || composer install'
+16 -2
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
@@ -16,6 +16,14 @@ class Mustache_Autoloader
{ {
private $baseDir; private $baseDir;
/**
* An array where the key is the baseDir and the key is an instance of this
* class.
*
* @var array
*/
private static $instances;
/** /**
* Autoloader constructor. * Autoloader constructor.
* *
@@ -45,7 +53,13 @@ class Mustache_Autoloader
*/ */
public static function register($baseDir = null) public static function register($baseDir = null)
{ {
$loader = new self($baseDir); $key = $baseDir ? $baseDir : 0;
if (!isset(self::$instances[$key])) {
self::$instances[$key] = new self($baseDir);
}
$loader = self::$instances[$key];
spl_autoload_register(array($loader, 'autoload')); spl_autoload_register(array($loader, 'autoload'));
return $loader; return $loader;
+1 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
+7 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
@@ -108,9 +108,11 @@ class Mustache_Cache_FilesystemCache extends Mustache_Cache_AbstractCache
); );
@mkdir($dirName, 0777, true); @mkdir($dirName, 0777, true);
// @codeCoverageIgnoreStart
if (!is_dir($dirName)) { if (!is_dir($dirName)) {
throw new Mustache_Exception_RuntimeException(sprintf('Failed to create cache directory "%s".', $dirName)); throw new Mustache_Exception_RuntimeException(sprintf('Failed to create cache directory "%s".', $dirName));
} }
// @codeCoverageIgnoreEnd
} }
return $dirName; return $dirName;
@@ -143,13 +145,17 @@ class Mustache_Cache_FilesystemCache extends Mustache_Cache_AbstractCache
return; return;
} }
// @codeCoverageIgnoreStart
$this->log( $this->log(
Mustache_Logger::ERROR, Mustache_Logger::ERROR,
'Unable to rename Mustache temp cache file: "{tempName}" -> "{fileName}"', 'Unable to rename Mustache temp cache file: "{tempName}" -> "{fileName}"',
array('tempName' => $tempFile, 'fileName' => $fileName) array('tempName' => $tempFile, 'fileName' => $fileName)
); );
// @codeCoverageIgnoreEnd
} }
// @codeCoverageIgnoreStart
throw new Mustache_Exception_RuntimeException(sprintf('Failed to write cache file "%s".', $fileName)); throw new Mustache_Exception_RuntimeException(sprintf('Failed to write cache file "%s".', $fileName));
// @codeCoverageIgnoreEnd
} }
} }
+1 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
+32 -27
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
@@ -191,7 +191,6 @@ class Mustache_Compiler
{ {
$this->lambdaHelper = new Mustache_LambdaHelper($this->mustache, $context); $this->lambdaHelper = new Mustache_LambdaHelper($this->mustache, $context);
$buffer = \'\'; $buffer = \'\';
$blocksContext = array();
%s %s
return $buffer; return $buffer;
@@ -207,7 +206,6 @@ class Mustache_Compiler
public function renderInternal(Mustache_Context $context, $indent = \'\') public function renderInternal(Mustache_Context $context, $indent = \'\')
{ {
$buffer = \'\'; $buffer = \'\';
$blocksContext = array();
%s %s
return $buffer; return $buffer;
@@ -240,10 +238,11 @@ class Mustache_Compiler
$blockFunction = $context->findInBlock(%s); $blockFunction = $context->findInBlock(%s);
if (is_callable($blockFunction)) { if (is_callable($blockFunction)) {
$buffer .= call_user_func($blockFunction, $context); $buffer .= call_user_func($blockFunction, $context);
} else {%s %s}
}
'; ';
const BLOCK_VAR_ELSE = '} else {%s';
/** /**
* Generate Mustache Template inheritance block variable PHP source. * Generate Mustache Template inheritance block variable PHP source.
* *
@@ -261,10 +260,15 @@ class Mustache_Compiler
{ {
$id = var_export($id, true); $id = var_export($id, true);
return sprintf($this->prepare(self::BLOCK_VAR, $level), $id, $this->walk($nodes, $level)); $else = $this->walk($nodes, $level);
if ($else !== '') {
$else = sprintf($this->prepare(self::BLOCK_VAR_ELSE, $level + 1, false, true), $else);
}
return sprintf($this->prepare(self::BLOCK_VAR, $level), $id, $else);
} }
const BLOCK_ARG = '$blocksContext[%s] = array($this, \'block%s\');'; const BLOCK_ARG = '%s => array($this, \'block%s\'),';
/** /**
* Generate Mustache Template inheritance block argument PHP source. * Generate Mustache Template inheritance block argument PHP source.
@@ -285,14 +289,13 @@ class Mustache_Compiler
$keystr = var_export($key, true); $keystr = var_export($key, true);
$id = var_export($id, true); $id = var_export($id, true);
return sprintf($this->prepare(self::BLOCK_ARG, 1), $id, $key); return sprintf($this->prepare(self::BLOCK_ARG, $level), $id, $key);
} }
const BLOCK_FUNCTION = ' const BLOCK_FUNCTION = '
public function block%s($context) public function block%s($context)
{ {
$indent = $buffer = \'\'; $indent = $buffer = \'\';%s
$blocksContext = array();%s
return $buffer; return $buffer;
} }
@@ -327,7 +330,6 @@ class Mustache_Compiler
private function section%s(Mustache_Context $context, $indent, $value) private function section%s(Mustache_Context $context, $indent, $value)
{ {
$buffer = \'\'; $buffer = \'\';
$blocksContext = array();
if (%s) { if (%s) {
$source = %s; $source = %s;
@@ -363,11 +365,10 @@ class Mustache_Compiler
* @param string $otag Current Mustache opening tag * @param string $otag Current Mustache opening tag
* @param string $ctag Current Mustache closing tag * @param string $ctag Current Mustache closing tag
* @param int $level * @param int $level
* @param bool $arg (default: false)
* *
* @return string Generated section PHP source code * @return string Generated section PHP source code
*/ */
private function section($nodes, $id, $filters, $start, $end, $otag, $ctag, $level, $arg = false) private function section($nodes, $id, $filters, $start, $end, $otag, $ctag, $level)
{ {
$source = var_export(substr($this->source, $start, $end - $start), true); $source = var_export(substr($this->source, $start, $end - $start), true);
$callable = $this->getCallable(); $callable = $this->getCallable();
@@ -387,15 +388,11 @@ class Mustache_Compiler
$this->sections[$key] = sprintf($this->prepare(self::SECTION), $key, $callable, $source, $helper, $delims, $this->walk($nodes, 2)); $this->sections[$key] = sprintf($this->prepare(self::SECTION), $key, $callable, $source, $helper, $delims, $this->walk($nodes, 2));
} }
if ($arg === true) { $method = $this->getFindMethod($id);
return $key; $id = var_export($id, true);
} else { $filters = $this->getFilters($filters, $level);
$method = $this->getFindMethod($id);
$id = var_export($id, true);
$filters = $this->getFilters($filters, $level);
return sprintf($this->prepare(self::SECTION_CALL, $level), $id, $method, $id, $filters, $key); return sprintf($this->prepare(self::SECTION_CALL, $level), $id, $method, $id, $filters, $key);
}
} }
const INVERTED_SECTION = ' const INVERTED_SECTION = '
@@ -457,15 +454,20 @@ class Mustache_Compiler
} }
const PARENT = ' const PARENT = '
%s
if ($parent = $this->mustache->loadPartial(%s)) { if ($parent = $this->mustache->loadPartial(%s)) {
$context->pushBlockContext($blocksContext); $context->pushBlockContext(array(%s
));
$buffer .= $parent->renderInternal($context, $indent); $buffer .= $parent->renderInternal($context, $indent);
$context->popBlockContext(); $context->popBlockContext();
} }
'; ';
const PARENT_NO_CONTEXT = '
if ($parent = $this->mustache->loadPartial(%s)) {
$buffer .= $parent->renderInternal($context, $indent);
}
';
/** /**
* Generate Mustache Template inheritance parent call PHP source. * Generate Mustache Template inheritance parent call PHP source.
* *
@@ -480,11 +482,14 @@ class Mustache_Compiler
{ {
$realChildren = array_filter($children, array(__CLASS__, 'onlyBlockArgs')); $realChildren = array_filter($children, array(__CLASS__, 'onlyBlockArgs'));
if (empty($realChildren)) {
return sprintf($this->prepare(self::PARENT_NO_CONTEXT, $level), var_export($id, true));
}
return sprintf( return sprintf(
$this->prepare(self::PARENT, $level), $this->prepare(self::PARENT, $level),
$this->walk($realChildren, $level),
var_export($id, true), var_export($id, true),
var_export($indent, true) $this->walk($realChildren, $level + 1)
); );
} }
@@ -621,7 +626,7 @@ class Mustache_Compiler
/** /**
* Select the appropriate Context `find` method for a given $id. * Select the appropriate Context `find` method for a given $id.
* *
* The return value will be one of `find`, `findDot` or `last`. * The return value will be one of `find`, `findDot`, `findAnchoredDot` or `last`.
* *
* @see Mustache_Context::find * @see Mustache_Context::find
* @see Mustache_Context::findDot * @see Mustache_Context::findDot
+1 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
+60 -18
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.11.1'; const VERSION = '2.12.0';
const SPEC_VERSION = '1.1.2'; const SPEC_VERSION = '1.1.2';
const PRAGMA_FILTERS = 'FILTERS'; const PRAGMA_FILTERS = 'FILTERS';
@@ -54,6 +54,7 @@ class Mustache_Engine
private $logger; private $logger;
private $strictCallables = false; private $strictCallables = false;
private $pragmas = array(); private $pragmas = array();
private $delimiters;
// Services // Services
private $tokenizer; private $tokenizer;
@@ -81,6 +82,14 @@ class Mustache_Engine
* // sections are often too dynamic to benefit from caching. * // sections are often too dynamic to benefit from caching.
* 'cache_lambda_templates' => true, * 'cache_lambda_templates' => true,
* *
* // Customize the tag delimiters used by this engine instance. Note that overriding here changes the
* // delimiters used to parse all templates and partials loaded by this instance. To override just for a
* // single template, use an inline "change delimiters" tag at the start of the template file:
* //
* // {{=<% %>=}}
* //
* 'delimiters' => '<% %>',
*
* // 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'),
* *
@@ -133,6 +142,10 @@ class Mustache_Engine
public function __construct(array $options = array()) public function __construct(array $options = array())
{ {
if (isset($options['template_class_prefix'])) { if (isset($options['template_class_prefix'])) {
if ((string) $options['template_class_prefix'] === '') {
throw new Mustache_Exception_InvalidArgumentException('Mustache Constructor "template_class_prefix" must not be empty');
}
$this->templateClassPrefix = $options['template_class_prefix']; $this->templateClassPrefix = $options['template_class_prefix'];
} }
@@ -191,6 +204,10 @@ class Mustache_Engine
$this->strictCallables = $options['strict_callables']; $this->strictCallables = $options['strict_callables'];
} }
if (isset($options['delimiters'])) {
$this->delimiters = $options['delimiters'];
}
if (isset($options['pragmas'])) { if (isset($options['pragmas'])) {
foreach ($options['pragmas'] as $pragma) { foreach ($options['pragmas'] as $pragma) {
if (!isset(self::$knownPragmas[$pragma])) { if (!isset(self::$knownPragmas[$pragma])) {
@@ -589,22 +606,43 @@ class Mustache_Engine
/** /**
* Helper method to generate a Mustache template class. * Helper method to generate a Mustache template class.
* *
* @param string $source * This method must be updated any time options are added which make it so
* the same template could be parsed and compiled multiple different ways.
*
* @param string|Mustache_Source $source
* *
* @return string Mustache Template class name * @return string Mustache Template class name
*/ */
public function getTemplateClassName($source) public function getTemplateClassName($source)
{ {
return $this->templateClassPrefix . md5(sprintf( // For the most part, adding a new option here should do the trick.
'version:%s,escape:%s,entity_flags:%i,charset:%s,strict_callables:%s,pragmas:%s,source:%s', //
self::VERSION, // Pick a value here which is unique for each possible way the template
isset($this->escape) ? 'custom' : 'default', // could be compiled... but not necessarily unique per option value. See
$this->entityFlags, // escape below, which only needs to differentiate between 'custom' and
$this->charset, // 'default' escapes.
$this->strictCallables ? 'true' : 'false', //
implode(' ', $this->getPragmas()), // Keep this list in alphabetical order :)
$source $chunks = array(
)); 'charset' => $this->charset,
'delimiters' => $this->delimiters ? $this->delimiters : '{{ }}',
'entityFlags' => $this->entityFlags,
'escape' => isset($this->escape) ? 'custom' : 'default',
'key' => ($source instanceof Mustache_Source) ? $source->getKey() : 'source',
'pragmas' => $this->getPragmas(),
'strictCallables' => $this->strictCallables,
'version' => self::VERSION,
);
$key = json_encode($chunks);
// Template Source instances have already provided their own source key. For strings, just include the whole
// source string in the md5 hash.
if (!$source instanceof Mustache_Source) {
$key .= "\n" . $source;
}
return $this->templateClassPrefix . md5($key);
} }
/** /**
@@ -681,8 +719,8 @@ class Mustache_Engine
* @see Mustache_Engine::loadPartial * @see Mustache_Engine::loadPartial
* @see Mustache_Engine::loadLambda * @see Mustache_Engine::loadLambda
* *
* @param string $source * @param string|Mustache_Source $source
* @param Mustache_Cache $cache (default: null) * @param Mustache_Cache $cache (default: null)
* *
* @return Mustache_Template * @return Mustache_Template
*/ */
@@ -725,7 +763,7 @@ class Mustache_Engine
*/ */
private function tokenize($source) private function tokenize($source)
{ {
return $this->getTokenizer()->scan($source); return $this->getTokenizer()->scan($source, $this->delimiters);
} }
/** /**
@@ -750,13 +788,12 @@ class Mustache_Engine
* *
* @see Mustache_Compiler::compile * @see Mustache_Compiler::compile
* *
* @param string $source * @param string|Mustache_Source $source
* *
* @return string generated Mustache template class code * @return string generated Mustache template class code
*/ */
private function compile($source) private function compile($source)
{ {
$tree = $this->parse($source);
$name = $this->getTemplateClassName($source); $name = $this->getTemplateClassName($source);
$this->log( $this->log(
@@ -765,6 +802,11 @@ class Mustache_Engine
array('className' => $name) array('className' => $name)
); );
if ($source instanceof Mustache_Source) {
$source = $source->getSource();
}
$tree = $this->parse($source);
$compiler = $this->getCompiler(); $compiler = $this->getCompiler();
$compiler->setPragmas($this->getPragmas()); $compiler->setPragmas($this->getPragmas());
+1 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
+2 -2
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
@@ -27,7 +27,7 @@ class Mustache_Exception_SyntaxException extends LogicException implements Musta
if (version_compare(PHP_VERSION, '5.3.0', '>=')) { if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
parent::__construct($msg, 0, $previous); parent::__construct($msg, 0, $previous);
} else { } else {
parent::__construct($msg); parent::__construct($msg); // @codeCoverageIgnore
} }
} }
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
@@ -27,7 +27,7 @@ class Mustache_Exception_UnknownFilterException extends UnexpectedValueException
if (version_compare(PHP_VERSION, '5.3.0', '>=')) { if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
parent::__construct($message, 0, $previous); parent::__construct($message, 0, $previous);
} else { } else {
parent::__construct($message); parent::__construct($message); // @codeCoverageIgnore
} }
} }
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
@@ -27,7 +27,7 @@ class Mustache_Exception_UnknownHelperException extends InvalidArgumentException
if (version_compare(PHP_VERSION, '5.3.0', '>=')) { if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
parent::__construct($message, 0, $previous); parent::__construct($message, 0, $previous);
} else { } else {
parent::__construct($message); parent::__construct($message); // @codeCoverageIgnore
} }
} }
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
@@ -27,7 +27,7 @@ class Mustache_Exception_UnknownTemplateException extends InvalidArgumentExcepti
if (version_compare(PHP_VERSION, '5.3.0', '>=')) { if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
parent::__construct($message, 0, $previous); parent::__construct($message, 0, $previous);
} else { } else {
parent::__construct($message); parent::__construct($message); // @codeCoverageIgnore
} }
} }
+1 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
+2 -2
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
@@ -21,7 +21,7 @@ interface Mustache_Loader
* *
* @param string $name * @param string $name
* *
* @return string Mustache Template source * @return string|Mustache_Source Mustache Template source
*/ */
public function load($name); public function load($name);
} }
+1 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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,86 @@
<?php
/*
* This file is part of Mustache.php.
*
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Mustache Template production filesystem Loader implementation.
*
* A production-ready FilesystemLoader, which doesn't require reading a file if it already exists in the template cache.
*
* {@inheritdoc}
*/
class Mustache_Loader_ProductionFilesystemLoader extends Mustache_Loader_FilesystemLoader
{
private $statProps;
/**
* Mustache production filesystem Loader constructor.
*
* Passing an $options array allows overriding certain Loader options during instantiation:
*
* $options = array(
* // The filename extension used for Mustache templates. Defaults to '.mustache'
* 'extension' => '.ms',
* 'stat_props' => array('size', 'mtime'),
* );
*
* Specifying 'stat_props' overrides the stat properties used to invalidate the template cache. By default, this
* uses 'mtime' and 'size', but this can be set to any of the properties supported by stat():
*
* http://php.net/manual/en/function.stat.php
*
* You can also disable filesystem stat entirely:
*
* $options = array('stat_props' => null);
*
* But with great power comes great responsibility. Namely, if you disable stat-based cache invalidation,
* YOU MUST CLEAR THE TEMPLATE CACHE YOURSELF when your templates change. Make it part of your build or deploy
* process so you don't forget!
*
* @throws Mustache_Exception_RuntimeException if $baseDir does not exist.
*
* @param string $baseDir Base directory containing Mustache template files.
* @param array $options Array of Loader options (default: array())
*/
public function __construct($baseDir, array $options = array())
{
parent::__construct($baseDir, $options);
if (array_key_exists('stat_props', $options)) {
if (empty($options['stat_props'])) {
$this->statProps = array();
} else {
$this->statProps = $options['stat_props'];
}
} else {
$this->statProps = array('size', 'mtime');
}
}
/**
* Helper function for loading a Mustache file by name.
*
* @throws Mustache_Exception_UnknownTemplateException If a template file is not found.
*
* @param string $name
*
* @return Mustache_Source Mustache Template source
*/
protected function loadFile($name)
{
$fileName = $this->getFileName($name);
if (!file_exists($fileName)) {
throw new Mustache_Exception_UnknownTemplateException($name);
}
return new Mustache_Source_FilesystemSource($fileName, $this->statProps);
}
}
+1 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
+40
View File
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of Mustache.php.
*
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Mustache template Source interface.
*/
interface Mustache_Source
{
/**
* Get the Source key (used to generate the compiled class name).
*
* This must return a distinct key for each template source. For example, an
* MD5 hash of the template contents would probably do the trick. The
* ProductionFilesystemLoader uses mtime and file path. If your production
* source directory is under version control, you could use the current Git
* rev and the file path...
*
* @throws RuntimeException when a source file cannot be read
*
* @return string
*/
public function getKey();
/**
* Get the template Source.
*
* @throws RuntimeException when a source file cannot be read
*
* @return string
*/
public function getSource();
}
+77
View File
@@ -0,0 +1,77 @@
<?php
/*
* This file is part of Mustache.php.
*
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Mustache template Filesystem Source.
*
* This template Source uses stat() to generate the Source key, so that using
* pre-compiled templates doesn't require hitting the disk to read the source.
* It is more suitable for production use, and is used by default in the
* ProductionFilesystemLoader.
*/
class Mustache_Source_FilesystemSource implements Mustache_Source
{
private $fileName;
private $statProps;
private $stat;
/**
* Filesystem Source constructor.
*
* @param string $fileName
* @param array $statProps
*/
public function __construct($fileName, array $statProps)
{
$this->fileName = $fileName;
$this->statProps = $statProps;
}
/**
* Get the Source key (used to generate the compiled class name).
*
* @throws RuntimeException when a source file cannot be read
*
* @return string
*/
public function getKey()
{
$chunks = array(
'fileName' => $this->fileName,
);
if (!empty($this->statProps)) {
if (!isset($this->stat)) {
$this->stat = @stat($this->fileName);
}
if ($this->stat === false) {
throw new RuntimeException(sprintf('Failed to read source file "%s".', $this->fileName));
}
foreach ($this->statProps as $prop) {
$chunks[$prop] = $this->stat[$prop];
}
}
return json_encode($chunks);
}
/**
* Get the template Source.
*
* @return string
*/
public function getSource()
{
return file_get_contents($this->fileName);
}
}
+1 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
+6 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
@@ -91,11 +91,14 @@ class Mustache_Tokenizer
{ {
// Setting mbstring.func_overload makes things *really* slow. // Setting mbstring.func_overload makes things *really* slow.
// Let's do everyone a favor and scan this string as ASCII instead. // Let's do everyone a favor and scan this string as ASCII instead.
//
// @codeCoverageIgnoreStart
$encoding = null; $encoding = null;
if (function_exists('mb_internal_encoding') && ini_get('mbstring.func_overload') & 2) { if (function_exists('mb_internal_encoding') && ini_get('mbstring.func_overload') & 2) {
$encoding = mb_internal_encoding(); $encoding = mb_internal_encoding();
mb_internal_encoding('ASCII'); mb_internal_encoding('ASCII');
} }
// @codeCoverageIgnoreEnd
$this->reset(); $this->reset();
@@ -202,9 +205,11 @@ class Mustache_Tokenizer
$this->flushBuffer(); $this->flushBuffer();
// Restore the user's encoding... // Restore the user's encoding...
// @codeCoverageIgnoreStart
if ($encoding) { if ($encoding) {
mb_internal_encoding($encoding); mb_internal_encoding($encoding);
} }
// @codeCoverageIgnoreEnd
return $this->tokens; return $this->tokens;
} }
+16 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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,4 +33,19 @@ class Mustache_Test_AutoloaderTest extends PHPUnit_Framework_TestCase
$loader->autoload('\Mustache_Bar'); $loader->autoload('\Mustache_Bar');
$this->assertTrue(class_exists('Mustache_Bar')); $this->assertTrue(class_exists('Mustache_Bar'));
} }
/**
* Test that the autoloader won't register multiple times.
*/
public function testRegisterMultiple()
{
$numLoaders = count(spl_autoload_functions());
Mustache_Autoloader::register();
Mustache_Autoloader::register();
$expectedNumLoaders = $numLoaders + 1;
$this->assertCount($expectedNumLoaders, spl_autoload_functions());
}
} }
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
+37 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.
@@ -158,6 +158,16 @@ class Mustache_Test_EngineTest extends Mustache_Test_FunctionalTestCase
$this->assertNotSame($mustache->getCache(), $mustache->getProtectedLambdaCache()); $this->assertNotSame($mustache->getCache(), $mustache->getProtectedLambdaCache());
} }
/**
* @expectedException Mustache_Exception_InvalidArgumentException
*/
public function testEmptyTemplatePrefixThrowsException()
{
new Mustache_Engine(array(
'template_class_prefix' => '',
));
}
/** /**
* @expectedException Mustache_Exception_InvalidArgumentException * @expectedException Mustache_Exception_InvalidArgumentException
* @dataProvider getBadEscapers * @dataProvider getBadEscapers
@@ -331,6 +341,15 @@ class Mustache_Test_EngineTest extends Mustache_Test_FunctionalTestCase
)); ));
} }
public function testCompileFromMustacheSourceInstance()
{
$baseDir = realpath(dirname(__FILE__) . '/../../fixtures/templates');
$mustache = new Mustache_Engine(array(
'loader' => new Mustache_Loader_ProductionFilesystemLoader($baseDir),
));
$this->assertEquals('one contents', $mustache->render('one'));
}
private function getLoggedMustache($level = Mustache_Logger::ERROR) private function getLoggedMustache($level = Mustache_Logger::ERROR)
{ {
$name = tempnam(sys_get_temp_dir(), 'mustache-test'); $name = tempnam(sys_get_temp_dir(), 'mustache-test');
@@ -340,6 +359,23 @@ class Mustache_Test_EngineTest extends Mustache_Test_FunctionalTestCase
return array($name, $mustache); return array($name, $mustache);
} }
public function testCustomDelimiters()
{
$mustache = new Mustache_Engine(array(
'delimiters' => '[[ ]]',
'partials' => array(
'one' => '[[> two ]]',
'two' => '[[ a ]]',
),
));
$tpl = $mustache->loadTemplate('[[# a ]][[ b ]][[/a ]]');
$this->assertEquals('c', $tpl->render(array('a' => true, 'b' => 'c')));
$tpl = $mustache->loadTemplate('[[> one ]]');
$this->assertEquals('b', $tpl->render(array('a' => 'b')));
}
} }
class MustacheStub extends Mustache_Engine class MustacheStub extends Mustache_Engine
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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.
@@ -227,6 +227,23 @@ class Mustache_Test_Functional_InheritanceTest extends PHPUnit_Framework_TestCas
$this->assertEquals('test |override1 default| |override2 default|', $tpl->render($data)); $this->assertEquals('test |override1 default| |override2 default|', $tpl->render($data));
} }
public function testBlocksDoNotLeakBetweenPartials()
{
$partials = array(
'partial' => '|{{$a}}A{{/a}} {{$b}}B{{/b}}|',
);
$this->mustache->setPartials($partials);
$tpl = $this->mustache->loadTemplate(
'test {{<partial}}{{$a}}C{{/a}}{{/partial}} {{<partial}}{{$b}}D{{/b}}{{/partial}}'
);
$data = array();
$this->assertEquals('test |C B| |A D|', $tpl->render($data));
}
public function testDataDoesNotOverrideBlock() public function testDataDoesNotOverrideBlock()
{ {
$partials = array( $partials = array(
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2015 Justin Hileman * (c) 2010-2017 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,103 @@
<?php
/*
* This file is part of Mustache.php.
*
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @group unit
*/
class Mustache_Test_Loader_ProductionFilesystemLoaderTest extends PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir, array('extension' => '.ms'));
$this->assertInstanceOf('Mustache_Source', $loader->load('alpha'));
$this->assertEquals('alpha contents', $loader->load('alpha')->getSource());
$this->assertInstanceOf('Mustache_Source', $loader->load('beta.ms'));
$this->assertEquals('beta contents', $loader->load('beta.ms')->getSource());
}
public function testTrailingSlashes()
{
$baseDir = dirname(__FILE__) . '/../../../fixtures/templates/';
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir);
$this->assertEquals('one contents', $loader->load('one')->getSource());
}
public function testConstructorWithProtocol()
{
$baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
$loader = new Mustache_Loader_ProductionFilesystemLoader('file://' . $baseDir, array('extension' => '.ms'));
$this->assertEquals('alpha contents', $loader->load('alpha')->getSource());
$this->assertEquals('beta contents', $loader->load('beta.ms')->getSource());
}
public function testLoadTemplates()
{
$baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir);
$this->assertEquals('one contents', $loader->load('one')->getSource());
$this->assertEquals('two contents', $loader->load('two.mustache')->getSource());
}
public function testEmptyExtensionString()
{
$baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir, array('extension' => ''));
$this->assertEquals('one contents', $loader->load('one.mustache')->getSource());
$this->assertEquals('alpha contents', $loader->load('alpha.ms')->getSource());
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir, array('extension' => null));
$this->assertEquals('two contents', $loader->load('two.mustache')->getSource());
$this->assertEquals('beta contents', $loader->load('beta.ms')->getSource());
}
/**
* @expectedException Mustache_Exception_RuntimeException
*/
public function testMissingBaseDirThrowsException()
{
new Mustache_Loader_ProductionFilesystemLoader(dirname(__FILE__) . '/not_a_directory');
}
/**
* @expectedException Mustache_Exception_UnknownTemplateException
*/
public function testMissingTemplateThrowsException()
{
$baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
$loader = new Mustache_Loader_ProductionFilesystemLoader($baseDir);
$loader->load('fake');
}
public function testLoadWithDifferentStatProps()
{
$baseDir = realpath(dirname(__FILE__) . '/../../../fixtures/templates');
$noStatLoader = new Mustache_Loader_ProductionFilesystemLoader($baseDir, array('stat_props' => null));
$mtimeLoader = new Mustache_Loader_ProductionFilesystemLoader($baseDir, array('stat_props' => array('mtime')));
$sizeLoader = new Mustache_Loader_ProductionFilesystemLoader($baseDir, array('stat_props' => array('size')));
$bothLoader = new Mustache_Loader_ProductionFilesystemLoader($baseDir, array('stat_props' => array('mtime', 'size')));
$noStatKey = $noStatLoader->load('one.mustache')->getKey();
$mtimeKey = $mtimeLoader->load('one.mustache')->getKey();
$sizeKey = $sizeLoader->load('one.mustache')->getKey();
$bothKey = $bothLoader->load('one.mustache')->getKey();
$this->assertNotEquals($noStatKey, $mtimeKey);
$this->assertNotEquals($noStatKey, $sizeKey);
$this->assertNotEquals($noStatKey, $bothKey);
$this->assertNotEquals($mtimeKey, $sizeKey);
$this->assertNotEquals($mtimeKey, $bothKey);
$this->assertNotEquals($sizeKey, $bothKey);
}
}
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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,25 @@
<?php
/*
* This file is part of Mustache.php.
*
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @group unit
*/
class Mustache_Test_Source_FilesystemSourceTest extends PHPUnit_Framework_TestCase
{
/**
* @expectedException RuntimeException
*/
public function testMissingTemplateThrowsException()
{
$source = new Mustache_Source_FilesystemSource(dirname(__FILE__) . '/not_a_file.mustache', array('mtime'));
$source->getKey();
}
}
+1 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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,55 @@
<?php
/*
* This file is part of Mustache.php.
*
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class AnchoredDotNotation
{
public $genres = array(
array(
'name' => 'Punk',
'subgenres' => array(
array(
'name' => 'Hardcore',
'subgenres' => array(
array(
'name' => 'First wave of black metal',
'subgenres' => array(
array('name' => 'Norwegian black metal'),
array(
'name' => 'Death metal',
'subgenres' => array(
array(
'name' => 'Swedish death metal',
'subgenres' => array(
array('name' => 'New wave of American metal'),
),
),
),
),
),
),
array(
'name' => 'Thrash metal',
'subgenres' => array(
array('name' => 'Grindcore'),
array(
'name' => 'Metalcore',
'subgenres' => array(
array('name' => 'Nu metal'),
),
),
),
),
),
),
),
),
);
}
@@ -0,0 +1,4 @@
{{% ANCHORED-DOT }}
{{# genres }}
{{> genre }}
{{/ genres }}
@@ -0,0 +1,11 @@
- Punk
- Hardcore
- First wave of black metal
- Norwegian black metal
- Death metal
- Swedish death metal
- New wave of American metal
- Thrash metal
- Grindcore
- Metalcore
- Nu metal
@@ -0,0 +1,5 @@
{{% ANCHORED-DOT }}
- {{ name }}
{{# .subgenres }}
{{> genre }}
{{/ .subgenres }}
+1 -1
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Mustache.php. * This file is part of Mustache.php.
* *
* (c) 2010-2016 Justin Hileman * (c) 2010-2017 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.

Some files were not shown because too many files have changed in this diff Show More