Permalink
Browse files

Merge branch 'release/2.12.0'

  • Loading branch information...
2 parents a3f6d55 + 994abca commit fe8fe72e9d580591854de404cc59a1b83ca4d19e @bobthecow committed Jul 11, 2017
Showing with 712 additions and 160 deletions.
  1. +16 −10 .travis.yml
  2. +16 −2 src/Mustache/Autoloader.php
  3. +1 −1 src/Mustache/Cache.php
  4. +1 −1 src/Mustache/Cache/AbstractCache.php
  5. +7 −1 src/Mustache/Cache/FilesystemCache.php
  6. +1 −1 src/Mustache/Cache/NoopCache.php
  7. +32 −27 src/Mustache/Compiler.php
  8. +1 −1 src/Mustache/Context.php
  9. +60 −18 src/Mustache/Engine.php
  10. +1 −1 src/Mustache/Exception.php
  11. +1 −1 src/Mustache/Exception/InvalidArgumentException.php
  12. +1 −1 src/Mustache/Exception/LogicException.php
  13. +1 −1 src/Mustache/Exception/RuntimeException.php
  14. +2 −2 src/Mustache/Exception/SyntaxException.php
  15. +2 −2 src/Mustache/Exception/UnknownFilterException.php
  16. +2 −2 src/Mustache/Exception/UnknownHelperException.php
  17. +2 −2 src/Mustache/Exception/UnknownTemplateException.php
  18. +1 −1 src/Mustache/HelperCollection.php
  19. +1 −1 src/Mustache/LambdaHelper.php
  20. +2 −2 src/Mustache/Loader.php
  21. +1 −1 src/Mustache/Loader/ArrayLoader.php
  22. +1 −1 src/Mustache/Loader/CascadingLoader.php
  23. +1 −1 src/Mustache/Loader/FilesystemLoader.php
  24. +1 −1 src/Mustache/Loader/InlineLoader.php
  25. +1 −1 src/Mustache/Loader/MutableLoader.php
  26. +86 −0 src/Mustache/Loader/ProductionFilesystemLoader.php
  27. +1 −1 src/Mustache/Loader/StringLoader.php
  28. +1 −1 src/Mustache/Logger.php
  29. +1 −1 src/Mustache/Logger/AbstractLogger.php
  30. +1 −1 src/Mustache/Logger/StreamLogger.php
  31. +1 −1 src/Mustache/Parser.php
  32. +40 −0 src/Mustache/Source.php
  33. +77 −0 src/Mustache/Source/FilesystemSource.php
  34. +1 −1 src/Mustache/Template.php
  35. +6 −1 src/Mustache/Tokenizer.php
  36. +16 −1 test/Mustache/Test/AutoloaderTest.php
  37. +1 −1 test/Mustache/Test/Cache/AbstractCacheTest.php
  38. +1 −1 test/Mustache/Test/Cache/FilesystemCacheTest.php
  39. +1 −1 test/Mustache/Test/CompilerTest.php
  40. +1 −1 test/Mustache/Test/ContextTest.php
  41. +37 −1 test/Mustache/Test/EngineTest.php
  42. +1 −1 test/Mustache/Test/Exception/SyntaxExceptionTest.php
  43. +1 −1 test/Mustache/Test/Exception/UnknownFilterExceptionTest.php
  44. +1 −1 test/Mustache/Test/Exception/UnknownHelperExceptionTest.php
  45. +1 −1 test/Mustache/Test/Exception/UnknownTemplateExceptionTest.php
  46. +1 −1 test/Mustache/Test/FiveThree/Functional/ClosureQuirksTest.php
  47. +1 −1 test/Mustache/Test/FiveThree/Functional/EngineTest.php
  48. +1 −1 test/Mustache/Test/FiveThree/Functional/FiltersTest.php
  49. +1 −1 test/Mustache/Test/FiveThree/Functional/HigherOrderSectionsTest.php
  50. +1 −1 test/Mustache/Test/FiveThree/Functional/LambdaHelperTest.php
  51. +1 −1 test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php
  52. +1 −1 test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php
  53. +1 −1 test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php
  54. +1 −1 test/Mustache/Test/Functional/CallTest.php
  55. +1 −1 test/Mustache/Test/Functional/ExamplesTest.php
  56. +1 −1 test/Mustache/Test/Functional/HigherOrderSectionsTest.php
  57. +18 −1 test/Mustache/Test/Functional/InheritanceTest.php
  58. +1 −1 test/Mustache/Test/Functional/MustacheInjectionTest.php
  59. +1 −1 test/Mustache/Test/Functional/MustacheSpecTest.php
  60. +1 −1 test/Mustache/Test/Functional/NestedPartialIndentTest.php
  61. +1 −1 test/Mustache/Test/Functional/ObjectSectionTest.php
  62. +1 −1 test/Mustache/Test/FunctionalTestCase.php
  63. +1 −1 test/Mustache/Test/HelperCollectionTest.php
  64. +1 −1 test/Mustache/Test/Loader/ArrayLoaderTest.php
  65. +1 −1 test/Mustache/Test/Loader/CascadingLoaderTest.php
  66. +1 −1 test/Mustache/Test/Loader/FilesystemLoaderTest.php
  67. +1 −1 test/Mustache/Test/Loader/InlineLoaderTest.php
  68. +103 −0 test/Mustache/Test/Loader/ProductionFilesystemLoaderTest.php
  69. +1 −1 test/Mustache/Test/Loader/StringLoaderTest.php
  70. +1 −1 test/Mustache/Test/Logger/AbstractLoggerTest.php
  71. +1 −1 test/Mustache/Test/Logger/StreamLoggerTest.php
  72. +1 −1 test/Mustache/Test/ParserTest.php
  73. +25 −0 test/Mustache/Test/Source/FilesystemSourceTest.php
  74. +1 −1 test/Mustache/Test/SpecTestCase.php
  75. +1 −1 test/Mustache/Test/TemplateTest.php
  76. +1 −1 test/Mustache/Test/TokenizerTest.php
  77. +1 −1 test/bootstrap.php
  78. +1 −1 test/fixtures/autoloader/Mustache/Bar.php
  79. +1 −1 test/fixtures/autoloader/Mustache/Foo.php
  80. +1 −1 test/fixtures/autoloader/NonMustacheClass.php
  81. +55 −0 test/fixtures/examples/anchored_dot_notation/AnchoredDotNotation.php
  82. +4 −0 test/fixtures/examples/anchored_dot_notation/anchored_dot_notation.mustache
  83. +11 −0 test/fixtures/examples/anchored_dot_notation/anchored_dot_notation.txt
  84. +5 −0 test/fixtures/examples/anchored_dot_notation/partials/genre.mustache
  85. +1 −1 test/fixtures/examples/blocks/Blocks.php
  86. +1 −1 test/fixtures/examples/child_context/ChildContext.php
  87. +1 −1 test/fixtures/examples/comments/Comments.php
  88. +1 −1 test/fixtures/examples/complex/complex.php
  89. +1 −1 test/fixtures/examples/delimiters/Delimiters.php
  90. +1 −1 test/fixtures/examples/dot_notation/DotNotation.php
  91. +1 −1 test/fixtures/examples/double_section/DoubleSection.php
  92. +1 −1 test/fixtures/examples/escaped/Escaped.php
  93. +1 −1 test/fixtures/examples/filters/Filters.php
  94. +1 −1 test/fixtures/examples/grand_parent_context/GrandParentContext.php
  95. +1 −1 test/fixtures/examples/i18n/I18n.php
  96. +1 −1 test/fixtures/examples/implicit_iterator/ImplicitIterator.php
  97. +1 −1 test/fixtures/examples/inverted_double_section/InvertedDoubleSection.php
  98. +1 −1 test/fixtures/examples/inverted_section/InvertedSection.php
  99. +1 −1 test/fixtures/examples/nested_partials/NestedPartials.php
  100. +1 −1 test/fixtures/examples/partials/Partials.php
  101. +1 −1 test/fixtures/examples/recursive_partials/RecursivePartials.php
  102. +1 −1 test/fixtures/examples/section_iterator_objects/SectionIteratorObjects.php
  103. +1 −1 test/fixtures/examples/section_magic_objects/SectionMagicObjects.php
  104. +1 −1 test/fixtures/examples/section_objects/SectionObjects.php
  105. +1 −1 test/fixtures/examples/sections/Sections.php
  106. +1 −1 test/fixtures/examples/sections_nested/SectionsNested.php
  107. +1 −1 test/fixtures/examples/simple/Simple.php
  108. +1 −1 test/fixtures/examples/unescaped/Unescaped.php
  109. +1 −1 test/fixtures/examples/utf8/UTF8.php
  110. +1 −1 test/fixtures/examples/utf8_unescaped/UTF8Unescaped.php
  111. +1 −1 test/fixtures/examples/whitespace/Whitespace.php
View
@@ -1,15 +1,21 @@
language: php
-php:
- - 5.2
- - 5.3
- - 5.4
- - 5.5
- - 5.6
- - 7.0
- - hhvm
+sudo: false
+
+matrix:
+ include:
+ - php: 5.2
+ - php: 5.3
+ - php: 5.4
+ - php: 5.5
+ - php: 5.6
+ - php: 7.0
+ - php: 7.1
+ - php: hhvm
+ dist: trusty
script:
- - phpunit
+ - '[[ "$TRAVIS_PHP_VERSION" = 5.2* ]] && phpunit || vendor/bin/phpunit --verbose'
-sudo: false
+install:
+ - '[[ "$TRAVIS_PHP_VERSION" = 5.2* ]] || composer install'
@@ -3,7 +3,7 @@
/*
* 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
* file that was distributed with this source code.
@@ -17,6 +17,14 @@ class Mustache_Autoloader
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.
*
* @param string $baseDir Mustache library base directory (default: dirname(__FILE__).'/..')
@@ -45,7 +53,13 @@ public function __construct($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'));
return $loader;
View
@@ -3,7 +3,7 @@
/*
* 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
* file that was distributed with this source code.
@@ -3,7 +3,7 @@
/*
* 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
* file that was distributed with this source code.
@@ -3,7 +3,7 @@
/*
* 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
* file that was distributed with this source code.
@@ -108,9 +108,11 @@ private function buildDirectoryForFilename($fileName)
);
@mkdir($dirName, 0777, true);
+ // @codeCoverageIgnoreStart
if (!is_dir($dirName)) {
throw new Mustache_Exception_RuntimeException(sprintf('Failed to create cache directory "%s".', $dirName));
}
+ // @codeCoverageIgnoreEnd
}
return $dirName;
@@ -143,13 +145,17 @@ private function writeFile($fileName, $value)
return;
}
+ // @codeCoverageIgnoreStart
$this->log(
Mustache_Logger::ERROR,
'Unable to rename Mustache temp cache file: "{tempName}" -> "{fileName}"',
array('tempName' => $tempFile, 'fileName' => $fileName)
);
+ // @codeCoverageIgnoreEnd
}
+ // @codeCoverageIgnoreStart
throw new Mustache_Exception_RuntimeException(sprintf('Failed to write cache file "%s".', $fileName));
+ // @codeCoverageIgnoreEnd
}
}
@@ -3,7 +3,7 @@
/*
* 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
* file that was distributed with this source code.
View
@@ -3,7 +3,7 @@
/*
* 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
* file that was distributed with this source code.
@@ -191,7 +191,6 @@ public function renderInternal(Mustache_Context $context, $indent = \'\')
{
$this->lambdaHelper = new Mustache_LambdaHelper($this->mustache, $context);
$buffer = \'\';
- $blocksContext = array();
%s
return $buffer;
@@ -207,7 +206,6 @@ class %s extends Mustache_Template
public function renderInternal(Mustache_Context $context, $indent = \'\')
{
$buffer = \'\';
- $blocksContext = array();
%s
return $buffer;
@@ -240,10 +238,11 @@ private function writeCode($tree, $name)
$blockFunction = $context->findInBlock(%s);
if (is_callable($blockFunction)) {
$buffer .= call_user_func($blockFunction, $context);
- } else {%s
- }
+ %s}
';
+ const BLOCK_VAR_ELSE = '} else {%s';
+
/**
* Generate Mustache Template inheritance block variable PHP source.
*
@@ -261,10 +260,15 @@ private function blockVar($nodes, $id, $start, $end, $otag, $ctag, $level)
{
$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.
@@ -285,14 +289,13 @@ private function blockArg($nodes, $id, $start, $end, $otag, $ctag, $level)
$keystr = var_export($key, 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 = '
public function block%s($context)
{
- $indent = $buffer = \'\';
- $blocksContext = array();%s
+ $indent = $buffer = \'\';%s
return $buffer;
}
@@ -327,7 +330,6 @@ private function block($nodes)
private function section%s(Mustache_Context $context, $indent, $value)
{
$buffer = \'\';
- $blocksContext = array();
if (%s) {
$source = %s;
@@ -363,11 +365,10 @@ private function section%s(Mustache_Context $context, $indent, $value)
* @param string $otag Current Mustache opening tag
* @param string $ctag Current Mustache closing tag
* @param int $level
- * @param bool $arg (default: false)
*
* @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);
$callable = $this->getCallable();
@@ -387,15 +388,11 @@ private function section($nodes, $id, $filters, $start, $end, $otag, $ctag, $lev
$this->sections[$key] = sprintf($this->prepare(self::SECTION), $key, $callable, $source, $helper, $delims, $this->walk($nodes, 2));
}
- if ($arg === true) {
- return $key;
- } else {
- $method = $this->getFindMethod($id);
- $id = var_export($id, true);
- $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 = '
@@ -457,15 +454,20 @@ private function partial($id, $indent, $level)
}
const PARENT = '
- %s
-
if ($parent = $this->mustache->loadPartial(%s)) {
- $context->pushBlockContext($blocksContext);
+ $context->pushBlockContext(array(%s
+ ));
$buffer .= $parent->renderInternal($context, $indent);
$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.
*
@@ -480,11 +482,14 @@ private function parent($id, $indent, array $children, $level)
{
$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(
$this->prepare(self::PARENT, $level),
- $this->walk($realChildren, $level),
var_export($id, true),
- var_export($indent, true)
+ $this->walk($realChildren, $level + 1)
);
}
@@ -621,7 +626,7 @@ private function getEscape($value = '$value')
/**
* 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::findDot
View
@@ -3,7 +3,7 @@
/*
* 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
* file that was distributed with this source code.
Oops, something went wrong.

0 comments on commit fe8fe72

Please sign in to comment.