From 536c0edac72a2b76d67ca2f9bc9fc2f4608bd0e6 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Mon, 13 Jan 2014 11:19:04 -0500 Subject: [PATCH 01/35] Include line number with syntax errors Contains changes suggested in #184 --- src/Mustache/Parser.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Mustache/Parser.php b/src/Mustache/Parser.php index 227e00b..f44153c 100644 --- a/src/Mustache/Parser.php +++ b/src/Mustache/Parser.php @@ -71,12 +71,22 @@ class Mustache_Parser case Mustache_Tokenizer::T_END_SECTION: if (!isset($parent)) { - $msg = sprintf('Unexpected closing tag: /%s', $token[Mustache_Tokenizer::NAME]); + $msg = sprintf( + 'Unexpected closing tag: /%s on line %d', + $token[Mustache_Tokenizer::NAME], + $token[Mustache_Tokenizer::LINE] + ); throw new Mustache_Exception_SyntaxException($msg, $token); } if ($token[Mustache_Tokenizer::NAME] !== $parent[Mustache_Tokenizer::NAME]) { - $msg = sprintf('Nesting error: %s vs. %s', $parent[Mustache_Tokenizer::NAME], $token[Mustache_Tokenizer::NAME]); + $msg = sprintf( + 'Nesting error: %s (on line %d) vs. %s (on line %d)', + $parent[Mustache_Tokenizer::NAME], + $parent[Mustache_Tokenizer::LINE], + $token[Mustache_Tokenizer::NAME], + $token[Mustache_Tokenizer::LINE] + ); throw new Mustache_Exception_SyntaxException($msg, $token); } @@ -109,7 +119,11 @@ class Mustache_Parser } if (isset($parent)) { - $msg = sprintf('Missing closing tag: %s', $parent[Mustache_Tokenizer::NAME]); + $msg = sprintf( + 'Missing closing tag: %s opened on line %s', + $parent[Mustache_Tokenizer::NAME], + $parent[Mustache_Tokenizer::LINE] + ); throw new Mustache_Exception_SyntaxException($msg, $parent); } From d534b168a0cade4be63cef9eb72704b94693c130 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Thu, 20 Feb 2014 08:21:52 -0800 Subject: [PATCH 02/35] Clean up comment code block style. --- src/Mustache/Engine.php | 4 ++-- src/Mustache/Loader/InlineLoader.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index 0bfc9cc..8f9ab00 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -79,12 +79,12 @@ class Mustache_Engine * // An array of 'helpers'. Helpers can be global variables or objects, closures (e.g. for higher order * // sections), or any other valid Mustache context value. They will be prepended to the context stack, * // so they will be available in any template loaded by this Mustache instance. - * 'helpers' => array('i18n' => function($text) { + * 'helpers' => array('i18n' => function ($text) { * // do something translatey here... * }), * * // An 'escape' callback, responsible for escaping double-mustache variables. - * 'escape' => function($value) { + * 'escape' => function ($value) { * return htmlspecialchars($buffer, ENT_COMPAT, 'UTF-8'); * }, * diff --git a/src/Mustache/Loader/InlineLoader.php b/src/Mustache/Loader/InlineLoader.php index e08852e..6ebbb6d 100644 --- a/src/Mustache/Loader/InlineLoader.php +++ b/src/Mustache/Loader/InlineLoader.php @@ -35,7 +35,7 @@ * 'mustache.loader' => new Mustache_Loader_InlineLoader(__FILE__, __COMPILER_HALT_OFFSET__) * )); * - * $app->get('/{name}', function($name) use ($app) { + * $app->get('/{name}', function ($name) use ($app) { * return $app['mustache']->render('hello', compact('name')); * }) * ->value('name', 'world'); From 6215e6b1b12477dd3686444ce081dbdfa20e3748 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Thu, 20 Feb 2014 06:44:36 -0800 Subject: [PATCH 03/35] Store otag/ctag lengths rather than recomputing. ~15% tokenizing performance boost. 99% reduction in strlen calls :) --- src/Mustache/Tokenizer.php | 67 +++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/src/Mustache/Tokenizer.php b/src/Mustache/Tokenizer.php index c701b25..1a765da 100644 --- a/src/Mustache/Tokenizer.php +++ b/src/Mustache/Tokenizer.php @@ -79,6 +79,8 @@ class Mustache_Tokenizer private $line; private $otag; private $ctag; + private $otagLen; + private $ctagLen; /** * Scan and tokenize template source. @@ -93,16 +95,14 @@ class Mustache_Tokenizer $this->reset(); if ($delimiters = trim($delimiters)) { - list($otag, $ctag) = explode(' ', $delimiters); - $this->otag = $otag; - $this->ctag = $ctag; + $this->setDelimiters($delimiters); } $len = strlen($text); for ($i = 0; $i < $len; $i++) { switch ($this->state) { case self::IN_TEXT: - if ($this->tagChange($this->otag, $text, $i)) { + if ($this->tagChange($this->otag, $this->otagLen, $text, $i)) { $i--; $this->flushBuffer(); $this->state = self::IN_TAG_TYPE; @@ -117,7 +117,7 @@ class Mustache_Tokenizer break; case self::IN_TAG_TYPE: - $i += strlen($this->otag) - 1; + $i += $this->otagLen - 1; $char = substr($text, $i + 1, 1); if (isset(self::$tagTypes[$char])) { $tag = $char; @@ -143,18 +143,18 @@ class Mustache_Tokenizer break; default: - if ($this->tagChange($this->ctag, $text, $i)) { + if ($this->tagChange($this->ctag, $this->ctagLen, $text, $i)) { $this->tokens[] = array( self::TYPE => $this->tagType, self::NAME => trim($this->buffer), self::OTAG => $this->otag, self::CTAG => $this->ctag, self::LINE => $this->line, - self::INDEX => ($this->tagType == self::T_END_SECTION) ? $this->seenTag - strlen($this->otag) : $i + strlen($this->ctag) + self::INDEX => ($this->tagType == self::T_END_SECTION) ? $this->seenTag - $this->otagLen : $i + $this->ctagLen ); $this->buffer = ''; - $i += strlen($this->ctag) - 1; + $i += $this->ctagLen - 1; $this->state = self::IN_TEXT; if ($this->tagType == self::T_UNESCAPED) { if ($this->ctag == '}}') { @@ -184,15 +184,17 @@ class Mustache_Tokenizer */ private function reset() { - $this->state = self::IN_TEXT; - $this->tagType = null; - $this->tag = null; - $this->buffer = ''; - $this->tokens = array(); - $this->seenTag = false; - $this->line = 0; - $this->otag = '{{'; - $this->ctag = '}}'; + $this->state = self::IN_TEXT; + $this->tagType = null; + $this->tag = null; + $this->buffer = ''; + $this->tokens = array(); + $this->seenTag = false; + $this->line = 0; + $this->otag = '{{'; + $this->ctag = '}}'; + $this->otagLen = 2; + $this->ctagLen = 2; } /** @@ -224,9 +226,7 @@ class Mustache_Tokenizer $close = '='.$this->ctag; $closeIndex = strpos($text, $close, $index); - list($otag, $ctag) = explode(' ', trim(substr($text, $startIndex, $closeIndex - $startIndex))); - $this->otag = $otag; - $this->ctag = $ctag; + $this->setDelimiters(trim(substr($text, $startIndex, $closeIndex - $startIndex))); $this->tokens[] = array( self::TYPE => self::T_DELIM_CHANGE, @@ -236,6 +236,20 @@ class Mustache_Tokenizer return $closeIndex + strlen($close) - 1; } + /** + * Set the current Mustache `otag` and `ctag` delimiters. + * + * @param string $delimiters + */ + private function setDelimiters($delimiters) + { + list($otag, $ctag) = explode(' ', $delimiters); + $this->otag = $otag; + $this->ctag = $ctag; + $this->otagLen = strlen($otag); + $this->ctagLen = strlen($ctag); + } + /** * Add pragma token. * @@ -259,20 +273,21 @@ class Mustache_Tokenizer self::LINE => 0, )); - return $end + strlen($this->ctag) - 1; + return $end + $this->ctagLen - 1; } /** * Test whether it's time to change tags. * - * @param string $tag Current tag name - * @param string $text Mustache template source - * @param int $index Current tokenizer index + * @param string $tag Current tag name + * @param int $tagLen Current tag name length + * @param string $text Mustache template source + * @param int $index Current tokenizer index * * @return boolean True if this is a closing section tag */ - private function tagChange($tag, $text, $index) + private function tagChange($tag, $tagLen, $text, $index) { - return substr($text, $index, strlen($tag)) === $tag; + return substr($text, $index, $tagLen) === $tag; } } From e00bebd1414f0ce911016331e8496cf65f6ffaa4 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Thu, 20 Feb 2014 09:07:43 -0800 Subject: [PATCH 04/35] Override encoding to improve tokenizer performance Speeds up tokenizing by ~15% for most users, and by 50% for users with mbstring.func_overload set! See #144 --- src/Mustache/Tokenizer.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Mustache/Tokenizer.php b/src/Mustache/Tokenizer.php index 1a765da..de33605 100644 --- a/src/Mustache/Tokenizer.php +++ b/src/Mustache/Tokenizer.php @@ -92,6 +92,14 @@ class Mustache_Tokenizer */ public function scan($text, $delimiters = null) { + // Setting mbstring.func_overload makes things *really* slow. + // Let's do everyone a favor and scan this string as ASCII instead. + $encoding = null; + if (function_exists('mb_internal_encoding') && ini_get('mbstring.func_overload') & 2) { + $encoding = mb_internal_encoding(); + mb_internal_encoding('ASCII'); + } + $this->reset(); if ($delimiters = trim($delimiters)) { @@ -107,7 +115,7 @@ class Mustache_Tokenizer $this->flushBuffer(); $this->state = self::IN_TAG_TYPE; } else { - $char = substr($text, $i, 1); + $char = $text[$i]; $this->buffer .= $char; if ($char == "\n") { $this->flushBuffer(); @@ -118,7 +126,7 @@ class Mustache_Tokenizer case self::IN_TAG_TYPE: $i += $this->otagLen - 1; - $char = substr($text, $i + 1, 1); + $char = $text[$i + 1]; if (isset(self::$tagTypes[$char])) { $tag = $char; $this->tagType = $tag; @@ -168,7 +176,7 @@ class Mustache_Tokenizer } } } else { - $this->buffer .= substr($text, $i, 1); + $this->buffer .= $text[$i]; } break; } @@ -176,6 +184,11 @@ class Mustache_Tokenizer $this->flushBuffer(); + // Restore the user's encoding... + if ($encoding) { + mb_internal_encoding($encoding); + } + return $this->tokens; } From 1d8db69fb639e560c016f1369516ecc01aa93863 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Thu, 20 Feb 2014 10:31:41 -0800 Subject: [PATCH 05/35] line numbers are numbers, not strings. --- src/Mustache/Parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mustache/Parser.php b/src/Mustache/Parser.php index f44153c..81e5149 100644 --- a/src/Mustache/Parser.php +++ b/src/Mustache/Parser.php @@ -120,7 +120,7 @@ class Mustache_Parser if (isset($parent)) { $msg = sprintf( - 'Missing closing tag: %s opened on line %s', + 'Missing closing tag: %s opened on line %d', $parent[Mustache_Tokenizer::NAME], $parent[Mustache_Tokenizer::LINE] ); From 22a47452da934e61021603f60e309972a212ffb8 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Thu, 13 Mar 2014 22:34:44 -0700 Subject: [PATCH 06/35] How embarrassing. I keep writing 2013 on my copyright notices. --- LICENSE | 3 ++- bin/build_bootstrap.php | 4 ++-- src/Mustache/Autoloader.php | 2 +- src/Mustache/Cache.php | 2 +- src/Mustache/Cache/AbstractCache.php | 2 +- src/Mustache/Cache/FilesystemCache.php | 2 +- src/Mustache/Cache/NoopCache.php | 2 +- src/Mustache/Compiler.php | 2 +- src/Mustache/Context.php | 2 +- src/Mustache/Engine.php | 2 +- src/Mustache/Exception.php | 2 +- src/Mustache/Exception/InvalidArgumentException.php | 2 +- src/Mustache/Exception/LogicException.php | 2 +- src/Mustache/Exception/RuntimeException.php | 2 +- src/Mustache/Exception/SyntaxException.php | 2 +- src/Mustache/Exception/UnknownFilterException.php | 2 +- src/Mustache/Exception/UnknownHelperException.php | 2 +- src/Mustache/Exception/UnknownTemplateException.php | 2 +- src/Mustache/HelperCollection.php | 2 +- src/Mustache/LambdaHelper.php | 2 +- src/Mustache/Loader.php | 2 +- src/Mustache/Loader/ArrayLoader.php | 2 +- src/Mustache/Loader/CascadingLoader.php | 2 +- src/Mustache/Loader/FilesystemLoader.php | 2 +- src/Mustache/Loader/InlineLoader.php | 2 +- src/Mustache/Loader/MutableLoader.php | 2 +- src/Mustache/Loader/StringLoader.php | 2 +- src/Mustache/Logger.php | 2 +- src/Mustache/Logger/AbstractLogger.php | 2 +- src/Mustache/Logger/StreamLogger.php | 2 +- src/Mustache/Parser.php | 2 +- src/Mustache/Template.php | 2 +- src/Mustache/Tokenizer.php | 2 +- test/Mustache/Test/AutoloaderTest.php | 2 +- test/Mustache/Test/Cache/AbstractCacheTest.php | 2 +- test/Mustache/Test/Cache/FilesystemCacheTest.php | 2 +- test/Mustache/Test/CompilerTest.php | 2 +- test/Mustache/Test/ContextTest.php | 2 +- test/Mustache/Test/EngineTest.php | 2 +- test/Mustache/Test/Exception/SyntaxExceptionTest.php | 2 +- test/Mustache/Test/Exception/UnknownFilterExceptionTest.php | 2 +- test/Mustache/Test/Exception/UnknownHelperExceptionTest.php | 2 +- test/Mustache/Test/Exception/UnknownTemplateExceptionTest.php | 2 +- test/Mustache/Test/FiveThree/Functional/ClosureQuirksTest.php | 2 +- test/Mustache/Test/FiveThree/Functional/FiltersTest.php | 2 +- .../Test/FiveThree/Functional/HigherOrderSectionsTest.php | 2 +- test/Mustache/Test/FiveThree/Functional/LambdaHelperTest.php | 2 +- test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php | 2 +- .../Test/FiveThree/Functional/PartialLambdaIndentTest.php | 2 +- .../Mustache/Test/FiveThree/Functional/SectionFiltersTest.php | 2 +- .../Test/FiveThree/Functional/StrictCallablesTest.php | 2 +- test/Mustache/Test/Functional/CallTest.php | 2 +- test/Mustache/Test/Functional/ExamplesTest.php | 2 +- test/Mustache/Test/Functional/HigherOrderSectionsTest.php | 2 +- test/Mustache/Test/Functional/MustacheInjectionTest.php | 2 +- test/Mustache/Test/Functional/MustacheSpecTest.php | 2 +- test/Mustache/Test/Functional/ObjectSectionTest.php | 2 +- test/Mustache/Test/HelperCollectionTest.php | 2 +- test/Mustache/Test/Loader/ArrayLoaderTest.php | 2 +- test/Mustache/Test/Loader/CascadingLoaderTest.php | 2 +- test/Mustache/Test/Loader/FilesystemLoaderTest.php | 2 +- test/Mustache/Test/Loader/InlineLoaderTest.php | 2 +- test/Mustache/Test/Loader/StringLoaderTest.php | 2 +- test/Mustache/Test/Logger/AbstractLoggerTest.php | 2 +- test/Mustache/Test/Logger/StreamLoggerTest.php | 2 +- test/Mustache/Test/ParserTest.php | 2 +- test/Mustache/Test/TemplateTest.php | 2 +- test/Mustache/Test/TokenizerTest.php | 2 +- test/bootstrap.php | 2 +- test/fixtures/autoloader/Mustache/Bar.php | 2 +- test/fixtures/autoloader/Mustache/Foo.php | 2 +- test/fixtures/autoloader/NonMustacheClass.php | 2 +- 72 files changed, 74 insertions(+), 73 deletions(-) diff --git a/LICENSE b/LICENSE index 6db5300..0bdbc04 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,6 @@ The MIT License (MIT) -Copyright (c) 2010 Justin Hileman + +Copyright (c) 2010-2014 Justin Hileman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/bin/build_bootstrap.php b/bin/build_bootstrap.php index 061532b..f9fa2af 100755 --- a/bin/build_bootstrap.php +++ b/bin/build_bootstrap.php @@ -4,7 +4,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -85,7 +85,7 @@ class SymfonyClassCollectionLoader /* * This file is part of Mustache.php. * - * (c) %d Justin Hileman + * (c) 2010-%d Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Autoloader.php b/src/Mustache/Autoloader.php index 6936b06..04b9e6f 100644 --- a/src/Mustache/Autoloader.php +++ b/src/Mustache/Autoloader.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Cache.php b/src/Mustache/Cache.php index 6387872..c8fc5d5 100644 --- a/src/Mustache/Cache.php +++ b/src/Mustache/Cache.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Cache/AbstractCache.php b/src/Mustache/Cache/AbstractCache.php index 9ee7157..98b6451 100644 --- a/src/Mustache/Cache/AbstractCache.php +++ b/src/Mustache/Cache/AbstractCache.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Cache/FilesystemCache.php b/src/Mustache/Cache/FilesystemCache.php index e4926bc..120ad2d 100644 --- a/src/Mustache/Cache/FilesystemCache.php +++ b/src/Mustache/Cache/FilesystemCache.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Cache/NoopCache.php b/src/Mustache/Cache/NoopCache.php index a5b9ad9..d3a7e1f 100644 --- a/src/Mustache/Cache/NoopCache.php +++ b/src/Mustache/Cache/NoopCache.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Compiler.php b/src/Mustache/Compiler.php index c13e60f..06af266 100644 --- a/src/Mustache/Compiler.php +++ b/src/Mustache/Compiler.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Context.php b/src/Mustache/Context.php index c6900d7..1966d25 100644 --- a/src/Mustache/Context.php +++ b/src/Mustache/Context.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index 8f9ab00..bf234c9 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Exception.php b/src/Mustache/Exception.php index b4f8300..8a2b01c 100644 --- a/src/Mustache/Exception.php +++ b/src/Mustache/Exception.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Exception/InvalidArgumentException.php b/src/Mustache/Exception/InvalidArgumentException.php index 34a6fd6..9bd1107 100644 --- a/src/Mustache/Exception/InvalidArgumentException.php +++ b/src/Mustache/Exception/InvalidArgumentException.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Exception/LogicException.php b/src/Mustache/Exception/LogicException.php index a2063cd..255ce54 100644 --- a/src/Mustache/Exception/LogicException.php +++ b/src/Mustache/Exception/LogicException.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Exception/RuntimeException.php b/src/Mustache/Exception/RuntimeException.php index f637ceb..a3c48f7 100644 --- a/src/Mustache/Exception/RuntimeException.php +++ b/src/Mustache/Exception/RuntimeException.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Exception/SyntaxException.php b/src/Mustache/Exception/SyntaxException.php index fad60fc..e666111 100644 --- a/src/Mustache/Exception/SyntaxException.php +++ b/src/Mustache/Exception/SyntaxException.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Exception/UnknownFilterException.php b/src/Mustache/Exception/UnknownFilterException.php index f5c0884..1a1f637 100644 --- a/src/Mustache/Exception/UnknownFilterException.php +++ b/src/Mustache/Exception/UnknownFilterException.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Exception/UnknownHelperException.php b/src/Mustache/Exception/UnknownHelperException.php index 98af13e..8fc530e 100644 --- a/src/Mustache/Exception/UnknownHelperException.php +++ b/src/Mustache/Exception/UnknownHelperException.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Exception/UnknownTemplateException.php b/src/Mustache/Exception/UnknownTemplateException.php index 141d372..47ff4fa 100644 --- a/src/Mustache/Exception/UnknownTemplateException.php +++ b/src/Mustache/Exception/UnknownTemplateException.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/HelperCollection.php b/src/Mustache/HelperCollection.php index 4fee762..bbeb277 100644 --- a/src/Mustache/HelperCollection.php +++ b/src/Mustache/HelperCollection.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/LambdaHelper.php b/src/Mustache/LambdaHelper.php index 0ae0b64..f80c0fb 100644 --- a/src/Mustache/LambdaHelper.php +++ b/src/Mustache/LambdaHelper.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Loader.php b/src/Mustache/Loader.php index 9fa82db..9378c2c 100644 --- a/src/Mustache/Loader.php +++ b/src/Mustache/Loader.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Loader/ArrayLoader.php b/src/Mustache/Loader/ArrayLoader.php index dfd9e02..1667bfd 100644 --- a/src/Mustache/Loader/ArrayLoader.php +++ b/src/Mustache/Loader/ArrayLoader.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Loader/CascadingLoader.php b/src/Mustache/Loader/CascadingLoader.php index 192edb9..204a38f 100644 --- a/src/Mustache/Loader/CascadingLoader.php +++ b/src/Mustache/Loader/CascadingLoader.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Loader/FilesystemLoader.php b/src/Mustache/Loader/FilesystemLoader.php index 8abe6c6..8a27b01 100644 --- a/src/Mustache/Loader/FilesystemLoader.php +++ b/src/Mustache/Loader/FilesystemLoader.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Loader/InlineLoader.php b/src/Mustache/Loader/InlineLoader.php index 6ebbb6d..9e4ab42 100644 --- a/src/Mustache/Loader/InlineLoader.php +++ b/src/Mustache/Loader/InlineLoader.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Loader/MutableLoader.php b/src/Mustache/Loader/MutableLoader.php index f606edb..110aa31 100644 --- a/src/Mustache/Loader/MutableLoader.php +++ b/src/Mustache/Loader/MutableLoader.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Loader/StringLoader.php b/src/Mustache/Loader/StringLoader.php index 295ace4..5570cda 100644 --- a/src/Mustache/Loader/StringLoader.php +++ b/src/Mustache/Loader/StringLoader.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Logger.php b/src/Mustache/Logger.php index 3874bba..2e5d674 100644 --- a/src/Mustache/Logger.php +++ b/src/Mustache/Logger.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Logger/AbstractLogger.php b/src/Mustache/Logger/AbstractLogger.php index 44f99d3..3dd96e7 100644 --- a/src/Mustache/Logger/AbstractLogger.php +++ b/src/Mustache/Logger/AbstractLogger.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Logger/StreamLogger.php b/src/Mustache/Logger/StreamLogger.php index c79e6cb..470cf7c 100644 --- a/src/Mustache/Logger/StreamLogger.php +++ b/src/Mustache/Logger/StreamLogger.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Parser.php b/src/Mustache/Parser.php index 81e5149..a6e965f 100644 --- a/src/Mustache/Parser.php +++ b/src/Mustache/Parser.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Template.php b/src/Mustache/Template.php index 8c76916..c9621c8 100644 --- a/src/Mustache/Template.php +++ b/src/Mustache/Template.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Mustache/Tokenizer.php b/src/Mustache/Tokenizer.php index de33605..4b5a33c 100644 --- a/src/Mustache/Tokenizer.php +++ b/src/Mustache/Tokenizer.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/AutoloaderTest.php b/test/Mustache/Test/AutoloaderTest.php index 7ab45ca..32fb0dc 100644 --- a/test/Mustache/Test/AutoloaderTest.php +++ b/test/Mustache/Test/AutoloaderTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Cache/AbstractCacheTest.php b/test/Mustache/Test/Cache/AbstractCacheTest.php index 142c12e..1a9c629 100644 --- a/test/Mustache/Test/Cache/AbstractCacheTest.php +++ b/test/Mustache/Test/Cache/AbstractCacheTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Cache/FilesystemCacheTest.php b/test/Mustache/Test/Cache/FilesystemCacheTest.php index 87b33f3..09dff65 100644 --- a/test/Mustache/Test/Cache/FilesystemCacheTest.php +++ b/test/Mustache/Test/Cache/FilesystemCacheTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/CompilerTest.php b/test/Mustache/Test/CompilerTest.php index 8f8ec4c..137811a 100644 --- a/test/Mustache/Test/CompilerTest.php +++ b/test/Mustache/Test/CompilerTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/ContextTest.php b/test/Mustache/Test/ContextTest.php index b4f36a7..1e74754 100644 --- a/test/Mustache/Test/ContextTest.php +++ b/test/Mustache/Test/ContextTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/EngineTest.php b/test/Mustache/Test/EngineTest.php index 1ab3078..b5679a3 100644 --- a/test/Mustache/Test/EngineTest.php +++ b/test/Mustache/Test/EngineTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Exception/SyntaxExceptionTest.php b/test/Mustache/Test/Exception/SyntaxExceptionTest.php index 8914fbd..8b176c5 100644 --- a/test/Mustache/Test/Exception/SyntaxExceptionTest.php +++ b/test/Mustache/Test/Exception/SyntaxExceptionTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Exception/UnknownFilterExceptionTest.php b/test/Mustache/Test/Exception/UnknownFilterExceptionTest.php index 8ba2e4d..9daf643 100644 --- a/test/Mustache/Test/Exception/UnknownFilterExceptionTest.php +++ b/test/Mustache/Test/Exception/UnknownFilterExceptionTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Exception/UnknownHelperExceptionTest.php b/test/Mustache/Test/Exception/UnknownHelperExceptionTest.php index 60567f9..b5da3ed 100644 --- a/test/Mustache/Test/Exception/UnknownHelperExceptionTest.php +++ b/test/Mustache/Test/Exception/UnknownHelperExceptionTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Exception/UnknownTemplateExceptionTest.php b/test/Mustache/Test/Exception/UnknownTemplateExceptionTest.php index 001bc63..501181b 100644 --- a/test/Mustache/Test/Exception/UnknownTemplateExceptionTest.php +++ b/test/Mustache/Test/Exception/UnknownTemplateExceptionTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/FiveThree/Functional/ClosureQuirksTest.php b/test/Mustache/Test/FiveThree/Functional/ClosureQuirksTest.php index 64651b6..52f3974 100644 --- a/test/Mustache/Test/FiveThree/Functional/ClosureQuirksTest.php +++ b/test/Mustache/Test/FiveThree/Functional/ClosureQuirksTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/FiveThree/Functional/FiltersTest.php b/test/Mustache/Test/FiveThree/Functional/FiltersTest.php index 9b8b815..323881e 100644 --- a/test/Mustache/Test/FiveThree/Functional/FiltersTest.php +++ b/test/Mustache/Test/FiveThree/Functional/FiltersTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/FiveThree/Functional/HigherOrderSectionsTest.php b/test/Mustache/Test/FiveThree/Functional/HigherOrderSectionsTest.php index 5e3ac7c..87cc1c4 100644 --- a/test/Mustache/Test/FiveThree/Functional/HigherOrderSectionsTest.php +++ b/test/Mustache/Test/FiveThree/Functional/HigherOrderSectionsTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/FiveThree/Functional/LambdaHelperTest.php b/test/Mustache/Test/FiveThree/Functional/LambdaHelperTest.php index a73473e..0b7c371 100644 --- a/test/Mustache/Test/FiveThree/Functional/LambdaHelperTest.php +++ b/test/Mustache/Test/FiveThree/Functional/LambdaHelperTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php index dcea68f..d174a14 100644 --- a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php +++ b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php b/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php index 5d9e4d1..8555735 100644 --- a/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php +++ b/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php b/test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php index cbd6823..c319ff5 100644 --- a/test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php +++ b/test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php b/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php index 39b5dd9..96e6147 100644 --- a/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php +++ b/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Functional/CallTest.php b/test/Mustache/Test/Functional/CallTest.php index 4841ba9..8fafd9a 100644 --- a/test/Mustache/Test/Functional/CallTest.php +++ b/test/Mustache/Test/Functional/CallTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Functional/ExamplesTest.php b/test/Mustache/Test/Functional/ExamplesTest.php index 3c7a5a5..43eab61 100644 --- a/test/Mustache/Test/Functional/ExamplesTest.php +++ b/test/Mustache/Test/Functional/ExamplesTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php index 078988b..1e70423 100644 --- a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php +++ b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Functional/MustacheInjectionTest.php b/test/Mustache/Test/Functional/MustacheInjectionTest.php index 8c95494..2bc1b85 100644 --- a/test/Mustache/Test/Functional/MustacheInjectionTest.php +++ b/test/Mustache/Test/Functional/MustacheInjectionTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Functional/MustacheSpecTest.php b/test/Mustache/Test/Functional/MustacheSpecTest.php index 312a4c9..fb6c156 100644 --- a/test/Mustache/Test/Functional/MustacheSpecTest.php +++ b/test/Mustache/Test/Functional/MustacheSpecTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Functional/ObjectSectionTest.php b/test/Mustache/Test/Functional/ObjectSectionTest.php index 126a683..c611ab2 100644 --- a/test/Mustache/Test/Functional/ObjectSectionTest.php +++ b/test/Mustache/Test/Functional/ObjectSectionTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/HelperCollectionTest.php b/test/Mustache/Test/HelperCollectionTest.php index ab9200f..419bb82 100644 --- a/test/Mustache/Test/HelperCollectionTest.php +++ b/test/Mustache/Test/HelperCollectionTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Loader/ArrayLoaderTest.php b/test/Mustache/Test/Loader/ArrayLoaderTest.php index 1c59df9..baa932b 100644 --- a/test/Mustache/Test/Loader/ArrayLoaderTest.php +++ b/test/Mustache/Test/Loader/ArrayLoaderTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Loader/CascadingLoaderTest.php b/test/Mustache/Test/Loader/CascadingLoaderTest.php index 41ff4b4..1342740 100644 --- a/test/Mustache/Test/Loader/CascadingLoaderTest.php +++ b/test/Mustache/Test/Loader/CascadingLoaderTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Loader/FilesystemLoaderTest.php b/test/Mustache/Test/Loader/FilesystemLoaderTest.php index 0c09593..a8f2d07 100644 --- a/test/Mustache/Test/Loader/FilesystemLoaderTest.php +++ b/test/Mustache/Test/Loader/FilesystemLoaderTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Loader/InlineLoaderTest.php b/test/Mustache/Test/Loader/InlineLoaderTest.php index 0545ad9..058ccec 100644 --- a/test/Mustache/Test/Loader/InlineLoaderTest.php +++ b/test/Mustache/Test/Loader/InlineLoaderTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Loader/StringLoaderTest.php b/test/Mustache/Test/Loader/StringLoaderTest.php index 79dfe51..1dd66d0 100644 --- a/test/Mustache/Test/Loader/StringLoaderTest.php +++ b/test/Mustache/Test/Loader/StringLoaderTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Logger/AbstractLoggerTest.php b/test/Mustache/Test/Logger/AbstractLoggerTest.php index 2b66948..9e6dda5 100644 --- a/test/Mustache/Test/Logger/AbstractLoggerTest.php +++ b/test/Mustache/Test/Logger/AbstractLoggerTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/Logger/StreamLoggerTest.php b/test/Mustache/Test/Logger/StreamLoggerTest.php index 68cc05d..236deb6 100644 --- a/test/Mustache/Test/Logger/StreamLoggerTest.php +++ b/test/Mustache/Test/Logger/StreamLoggerTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/ParserTest.php b/test/Mustache/Test/ParserTest.php index 57e418a..d51b0a6 100644 --- a/test/Mustache/Test/ParserTest.php +++ b/test/Mustache/Test/ParserTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/TemplateTest.php b/test/Mustache/Test/TemplateTest.php index bafdefb..6033e53 100644 --- a/test/Mustache/Test/TemplateTest.php +++ b/test/Mustache/Test/TemplateTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/Mustache/Test/TokenizerTest.php b/test/Mustache/Test/TokenizerTest.php index 63a94d4..42df8e1 100644 --- a/test/Mustache/Test/TokenizerTest.php +++ b/test/Mustache/Test/TokenizerTest.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/bootstrap.php b/test/bootstrap.php index cf84d28..28da5d0 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/fixtures/autoloader/Mustache/Bar.php b/test/fixtures/autoloader/Mustache/Bar.php index f731f5f..a04da7a 100644 --- a/test/fixtures/autoloader/Mustache/Bar.php +++ b/test/fixtures/autoloader/Mustache/Bar.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/fixtures/autoloader/Mustache/Foo.php b/test/fixtures/autoloader/Mustache/Foo.php index 5f16022..3114188 100644 --- a/test/fixtures/autoloader/Mustache/Foo.php +++ b/test/fixtures/autoloader/Mustache/Foo.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/test/fixtures/autoloader/NonMustacheClass.php b/test/fixtures/autoloader/NonMustacheClass.php index 82febb9..dbe844d 100644 --- a/test/fixtures/autoloader/NonMustacheClass.php +++ b/test/fixtures/autoloader/NonMustacheClass.php @@ -3,7 +3,7 @@ /* * This file is part of Mustache.php. * - * (c) 2013 Justin Hileman + * (c) 2010-2014 Justin Hileman * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. From f696e7afa6929101e214db2ae221cd7895695075 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 07:21:02 -0700 Subject: [PATCH 07/35] Fix incorrect or missing type annotations. --- src/Mustache/Engine.php | 2 +- src/Mustache/Exception/SyntaxException.php | 7 +++++++ src/Mustache/Exception/UnknownFilterException.php | 3 +++ src/Mustache/Exception/UnknownHelperException.php | 3 +++ src/Mustache/Exception/UnknownTemplateException.php | 3 +++ src/Mustache/LambdaHelper.php | 2 +- src/Mustache/Loader/CascadingLoader.php | 2 +- src/Mustache/Loader/MutableLoader.php | 4 ++++ src/Mustache/Logger/StreamLogger.php | 4 ++-- test/Mustache/Test/Cache/FilesystemCacheTest.php | 3 +++ test/Mustache/Test/CompilerTest.php | 3 +++ test/Mustache/Test/EngineTest.php | 3 +++ .../Test/FiveThree/Functional/MustacheSpecTest.php | 3 ++- test/Mustache/Test/Functional/HigherOrderSectionsTest.php | 3 +++ test/Mustache/Test/Functional/MustacheSpecTest.php | 3 ++- 15 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index bf234c9..c9bc847 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -194,7 +194,7 @@ class Mustache_Engine /** * Get the current Mustache escape callback. * - * @return mixed Callable or null + * @return callable|null */ public function getEscape() { diff --git a/src/Mustache/Exception/SyntaxException.php b/src/Mustache/Exception/SyntaxException.php index e666111..7a16f7e 100644 --- a/src/Mustache/Exception/SyntaxException.php +++ b/src/Mustache/Exception/SyntaxException.php @@ -16,12 +16,19 @@ class Mustache_Exception_SyntaxException extends LogicException implements Musta { protected $token; + /** + * @param string $msg + * @param array $token + */ public function __construct($msg, array $token) { $this->token = $token; parent::__construct($msg); } + /** + * @return array + */ public function getToken() { return $this->token; diff --git a/src/Mustache/Exception/UnknownFilterException.php b/src/Mustache/Exception/UnknownFilterException.php index 1a1f637..b9a315a 100644 --- a/src/Mustache/Exception/UnknownFilterException.php +++ b/src/Mustache/Exception/UnknownFilterException.php @@ -16,6 +16,9 @@ class Mustache_Exception_UnknownFilterException extends UnexpectedValueException { protected $filterName; + /** + * @param string $filterName + */ public function __construct($filterName) { $this->filterName = $filterName; diff --git a/src/Mustache/Exception/UnknownHelperException.php b/src/Mustache/Exception/UnknownHelperException.php index 8fc530e..226d774 100644 --- a/src/Mustache/Exception/UnknownHelperException.php +++ b/src/Mustache/Exception/UnknownHelperException.php @@ -16,6 +16,9 @@ class Mustache_Exception_UnknownHelperException extends InvalidArgumentException { protected $helperName; + /** + * @param string $helperName + */ public function __construct($helperName) { $this->helperName = $helperName; diff --git a/src/Mustache/Exception/UnknownTemplateException.php b/src/Mustache/Exception/UnknownTemplateException.php index 47ff4fa..5dafe89 100644 --- a/src/Mustache/Exception/UnknownTemplateException.php +++ b/src/Mustache/Exception/UnknownTemplateException.php @@ -16,6 +16,9 @@ class Mustache_Exception_UnknownTemplateException extends InvalidArgumentExcepti { protected $templateName; + /** + * @param string $templateName + */ public function __construct($templateName) { $this->templateName = $templateName; diff --git a/src/Mustache/LambdaHelper.php b/src/Mustache/LambdaHelper.php index f80c0fb..7cd8092 100644 --- a/src/Mustache/LambdaHelper.php +++ b/src/Mustache/LambdaHelper.php @@ -38,7 +38,7 @@ class Mustache_LambdaHelper * * @param string $string * - * @return Rendered template. + * @return string Rendered template. */ public function render($string) { diff --git a/src/Mustache/Loader/CascadingLoader.php b/src/Mustache/Loader/CascadingLoader.php index 204a38f..cfd74b3 100644 --- a/src/Mustache/Loader/CascadingLoader.php +++ b/src/Mustache/Loader/CascadingLoader.php @@ -25,7 +25,7 @@ class Mustache_Loader_CascadingLoader implements Mustache_Loader * new Mustache_Loader_FilesystemLoader(__DIR__.'/templates') * )); * - * @param array $loaders An array of Mustache Loader instances + * @param Mustache_Loader[] $loaders An array of Mustache Loader instances */ public function __construct(array $loaders = array()) { diff --git a/src/Mustache/Loader/MutableLoader.php b/src/Mustache/Loader/MutableLoader.php index 110aa31..f59f95d 100644 --- a/src/Mustache/Loader/MutableLoader.php +++ b/src/Mustache/Loader/MutableLoader.php @@ -19,6 +19,8 @@ interface Mustache_Loader_MutableLoader * Set an associative array of Template sources for this loader. * * @param array $templates + * + * @return void */ public function setTemplates(array $templates); @@ -27,6 +29,8 @@ interface Mustache_Loader_MutableLoader * * @param string $name * @param string $template Mustache Template source + * + * @return void */ public function setTemplate($name, $template); } diff --git a/src/Mustache/Logger/StreamLogger.php b/src/Mustache/Logger/StreamLogger.php index 470cf7c..aa47319 100644 --- a/src/Mustache/Logger/StreamLogger.php +++ b/src/Mustache/Logger/StreamLogger.php @@ -37,8 +37,8 @@ class Mustache_Logger_StreamLogger extends Mustache_Logger_AbstractLogger /** * @throws InvalidArgumentException if the logging level is unknown. * - * @param string $stream Resource instance or URL - * @param integer $level The minimum logging level at which this handler will be triggered + * @param resource|string $stream Resource instance or URL + * @param integer $level The minimum logging level at which this handler will be triggered */ public function __construct($stream, $level = Mustache_Logger::ERROR) { diff --git a/test/Mustache/Test/Cache/FilesystemCacheTest.php b/test/Mustache/Test/Cache/FilesystemCacheTest.php index 09dff65..e19c33b 100644 --- a/test/Mustache/Test/Cache/FilesystemCacheTest.php +++ b/test/Mustache/Test/Cache/FilesystemCacheTest.php @@ -44,6 +44,9 @@ class Mustache_Test_Cache_FilesystemCacheTest extends PHPUnit_Framework_TestCase $this->assertTrue($loaded); } + /** + * @param string $path + */ private static function rmdir($path) { $path = rtrim($path, '/').'/'; diff --git a/test/Mustache/Test/CompilerTest.php b/test/Mustache/Test/CompilerTest.php index 137811a..a9c7b3a 100644 --- a/test/Mustache/Test/CompilerTest.php +++ b/test/Mustache/Test/CompilerTest.php @@ -142,6 +142,9 @@ class Mustache_Test_CompilerTest extends PHPUnit_Framework_TestCase $compiler->compile('', array(array(Mustache_Tokenizer::TYPE => 'invalid')), 'SomeClass'); } + /** + * @param string $value + */ private function createTextToken($value) { return array( diff --git a/test/Mustache/Test/EngineTest.php b/test/Mustache/Test/EngineTest.php index b5679a3..af3fe1e 100644 --- a/test/Mustache/Test/EngineTest.php +++ b/test/Mustache/Test/EngineTest.php @@ -349,6 +349,9 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase $this->assertContains("WARNING: Partial not found: \"bar\"", $log); } + /** + * @param string $path + */ private static function rmdir($path) { $path = rtrim($path, '/').'/'; diff --git a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php index d174a14..004ec21 100644 --- a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php +++ b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php @@ -78,7 +78,8 @@ class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framew * * Loads YAML files from the spec and converts them to PHPisms. * - * @access public + * @param string $name + * * @return array */ private function loadSpec($name) diff --git a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php index 1e70423..5883e98 100644 --- a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php +++ b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php @@ -112,6 +112,9 @@ class Mustache_Test_Functional_Foo return sprintf('%s', $text); } + /** + * @param string $text + */ public function wrapWithStrong($text) { return sprintf('%s', $text); diff --git a/test/Mustache/Test/Functional/MustacheSpecTest.php b/test/Mustache/Test/Functional/MustacheSpecTest.php index fb6c156..e21efba 100644 --- a/test/Mustache/Test/Functional/MustacheSpecTest.php +++ b/test/Mustache/Test/Functional/MustacheSpecTest.php @@ -132,7 +132,8 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa * * Loads YAML files from the spec and converts them to PHPisms. * - * @access public + * @param string $name + * * @return array */ private function loadSpec($name) From a2ca330cba5e4900fed84670a11254cfd987a010 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 07:30:41 -0700 Subject: [PATCH 08/35] Fix missing properties. --- src/Mustache/Engine.php | 5 +++++ src/Mustache/Loader/ArrayLoader.php | 1 + src/Mustache/Logger/StreamLogger.php | 1 + 3 files changed, 7 insertions(+) diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index c9bc847..9eb03d1 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -45,6 +45,11 @@ class Mustache_Engine private $logger; private $strictCallables = false; + // Services + private $tokenizer; + private $parser; + private $compiler; + /** * Mustache class constructor. * diff --git a/src/Mustache/Loader/ArrayLoader.php b/src/Mustache/Loader/ArrayLoader.php index 1667bfd..e7ece91 100644 --- a/src/Mustache/Loader/ArrayLoader.php +++ b/src/Mustache/Loader/ArrayLoader.php @@ -26,6 +26,7 @@ */ class Mustache_Loader_ArrayLoader implements Mustache_Loader, Mustache_Loader_MutableLoader { + private $templates; /** * ArrayLoader constructor. diff --git a/src/Mustache/Logger/StreamLogger.php b/src/Mustache/Logger/StreamLogger.php index aa47319..d422340 100644 --- a/src/Mustache/Logger/StreamLogger.php +++ b/src/Mustache/Logger/StreamLogger.php @@ -31,6 +31,7 @@ class Mustache_Logger_StreamLogger extends Mustache_Logger_AbstractLogger self::EMERGENCY => 600, ); + protected $level; protected $stream = null; protected $url = null; From 8debbd58bb9020bc0490bd870bd541b02725d00e Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 07:31:22 -0700 Subject: [PATCH 09/35] Remove some dead code. --- src/Mustache/Parser.php | 2 -- test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php | 2 +- test/Mustache/Test/Loader/FilesystemLoaderTest.php | 2 +- test/Mustache/Test/Loader/InlineLoaderTest.php | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Mustache/Parser.php b/src/Mustache/Parser.php index a6e965f..54f52fc 100644 --- a/src/Mustache/Parser.php +++ b/src/Mustache/Parser.php @@ -95,7 +95,6 @@ class Mustache_Parser $parent[Mustache_Tokenizer::NODES] = $nodes; return $parent; - break; case Mustache_Tokenizer::T_PARTIAL: case Mustache_Tokenizer::T_PARTIAL_2: @@ -158,7 +157,6 @@ class Mustache_Parser } } - $next = null; if ($next = reset($tokens)) { // If we're on a new line, bail. if ($next[Mustache_Tokenizer::LINE] !== $this->lineNum) { diff --git a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php index 004ec21..2dccb73 100644 --- a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php +++ b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php @@ -62,7 +62,7 @@ class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framew } $func = $val['php']; - $data[$key] = function($text = null) use ($func) { + $data[$key] = function() use ($func) { return eval($func); }; } elseif (is_array($val)) { diff --git a/test/Mustache/Test/Loader/FilesystemLoaderTest.php b/test/Mustache/Test/Loader/FilesystemLoaderTest.php index a8f2d07..17c15fa 100644 --- a/test/Mustache/Test/Loader/FilesystemLoaderTest.php +++ b/test/Mustache/Test/Loader/FilesystemLoaderTest.php @@ -64,7 +64,7 @@ class Mustache_Test_Loader_FilesystemLoaderTest extends PHPUnit_Framework_TestCa */ public function testMissingBaseDirThrowsException() { - $loader = new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/not_a_directory'); + new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/not_a_directory'); } /** diff --git a/test/Mustache/Test/Loader/InlineLoaderTest.php b/test/Mustache/Test/Loader/InlineLoaderTest.php index 058ccec..be52733 100644 --- a/test/Mustache/Test/Loader/InlineLoaderTest.php +++ b/test/Mustache/Test/Loader/InlineLoaderTest.php @@ -35,7 +35,7 @@ class Mustache_Test_Loader_InlineLoaderTest extends PHPUnit_Framework_TestCase */ public function testInvalidOffsetThrowsException() { - $loader = new Mustache_Loader_InlineLoader(__FILE__, 'notanumber'); + new Mustache_Loader_InlineLoader(__FILE__, 'notanumber'); } /** @@ -43,7 +43,7 @@ class Mustache_Test_Loader_InlineLoaderTest extends PHPUnit_Framework_TestCase */ public function testInvalidFileThrowsException() { - $loader = new Mustache_Loader_InlineLoader('notarealfile', __COMPILER_HALT_OFFSET__); + new Mustache_Loader_InlineLoader('notarealfile', __COMPILER_HALT_OFFSET__); } } From b3e3e0a27a523c56da16dbeb47f75cb792587bfd Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 07:49:02 -0700 Subject: [PATCH 10/35] Gah. Fix broken lambda tests. This is what I get for blindly following code sniff recommendations. --- test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php index 2dccb73..004ec21 100644 --- a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php +++ b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php @@ -62,7 +62,7 @@ class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framew } $func = $val['php']; - $data[$key] = function() use ($func) { + $data[$key] = function($text = null) use ($func) { return eval($func); }; } elseif (is_array($val)) { From e9d4af3bbefa0088a5125085f49a9fcc02dcd01c Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 07:51:55 -0700 Subject: [PATCH 11/35] Reduce Engine constructor complexity. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I’m not sure I love this. I might prefer the more “complex” version :-/ --- src/Mustache/Engine.php | 63 ++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index 9eb03d1..f78f375 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -50,6 +50,23 @@ class Mustache_Engine private $parser; private $compiler; + private static $optionProperties = array( + 'template_class_prefix' => 'templateClassPrefix', + 'cache_lambda_templates' => 'cacheLambdaTemplates', + 'escape' => 'escape', + 'entity_flags' => 'entityFlags', + 'charset' => 'charset', + 'strict_callables' => 'strictCallables', + ); + + private static $optionSetters = array( + 'loader' => 'setLoader', + 'partials_loader' => 'setPartialsLoader', + 'partials' => 'setPartials', + 'helpers' => 'setHelpers', + 'logger' => 'setLogger', + ); + /** * Mustache class constructor. * @@ -118,10 +135,6 @@ class Mustache_Engine */ public function __construct(array $options = array()) { - if (isset($options['template_class_prefix'])) { - $this->templateClassPrefix = $options['template_class_prefix']; - } - if (isset($options['cache'])) { $cache = $options['cache']; @@ -133,48 +146,22 @@ class Mustache_Engine $this->setCache($cache); } - if (isset($options['cache_lambda_templates'])) { - $this->cacheLambdaTemplates = (bool) $options['cache_lambda_templates']; - } - - if (isset($options['loader'])) { - $this->setLoader($options['loader']); - } - - if (isset($options['partials_loader'])) { - $this->setPartialsLoader($options['partials_loader']); - } - - if (isset($options['partials'])) { - $this->setPartials($options['partials']); - } - - if (isset($options['helpers'])) { - $this->setHelpers($options['helpers']); - } - if (isset($options['escape'])) { if (!is_callable($options['escape'])) { throw new Mustache_Exception_InvalidArgumentException('Mustache Constructor "escape" option must be callable'); } - - $this->escape = $options['escape']; } - if (isset($options['entity_flags'])) { - $this->entityFlags = $options['entity_flags']; + foreach (self::$optionProperties as $name => $property) { + if (isset($options[$name])) { + $this->$property = $options[$name]; + } } - if (isset($options['charset'])) { - $this->charset = $options['charset']; - } - - if (isset($options['logger'])) { - $this->setLogger($options['logger']); - } - - if (isset($options['strict_callables'])) { - $this->strictCallables = $options['strict_callables']; + foreach (self::$optionSetters as $name => $setter) { + if (isset($options[$name])) { + $this->$setter($options[$name]); + } } } From 84a4ff5b16b0be42c969e7da50c7da7ce22fbe55 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 08:19:46 -0700 Subject: [PATCH 12/35] Use Composer autoload for unit tests. --- test/bootstrap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/bootstrap.php b/test/bootstrap.php index 28da5d0..deda69e 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -require dirname(__FILE__).'/../src/Mustache/Autoloader.php'; -Mustache_Autoloader::register(); +$loader = require dirname(__FILE__).'/../vendor/autoload.php'; +$loader->add('Mustache_Test', dirname(__FILE__)); require dirname(__FILE__).'/../vendor/yaml/lib/sfYamlParser.php'; From 3d9288dc8e966ff425651f775f35913fe809cec8 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 08:23:04 -0700 Subject: [PATCH 13/35] Extract duplicated tmpdir code into base test case --- .../Test/Cache/FilesystemCacheTest.php | 36 +------------- test/Mustache/Test/EngineTest.php | 37 +-------------- test/Mustache/Test/FunctionalTestCase.php | 47 +++++++++++++++++++ 3 files changed, 49 insertions(+), 71 deletions(-) create mode 100644 test/Mustache/Test/FunctionalTestCase.php diff --git a/test/Mustache/Test/Cache/FilesystemCacheTest.php b/test/Mustache/Test/Cache/FilesystemCacheTest.php index e19c33b..5bfb18c 100644 --- a/test/Mustache/Test/Cache/FilesystemCacheTest.php +++ b/test/Mustache/Test/Cache/FilesystemCacheTest.php @@ -12,18 +12,8 @@ /** * @group functional */ -class Mustache_Test_Cache_FilesystemCacheTest extends PHPUnit_Framework_TestCase +class Mustache_Test_Cache_FilesystemCacheTest extends Mustache_Test_FunctionalTestCase { - 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'; @@ -43,28 +33,4 @@ class Mustache_Test_Cache_FilesystemCacheTest extends PHPUnit_Framework_TestCase $this->assertTrue($loaded); } - - /** - * @param string $path - */ - 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); - } } diff --git a/test/Mustache/Test/EngineTest.php b/test/Mustache/Test/EngineTest.php index af3fe1e..faeed29 100644 --- a/test/Mustache/Test/EngineTest.php +++ b/test/Mustache/Test/EngineTest.php @@ -12,19 +12,8 @@ /** * @group unit */ -class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase +class Mustache_Test_EngineTest extends Mustache_Test_FunctionalTestCase { - - 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 testConstructor() { $logger = new Mustache_Logger_StreamLogger(tmpfile()); @@ -348,30 +337,6 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase $this->assertContains("DEBUG: Instantiating template: ", $log); $this->assertContains("WARNING: Partial not found: \"bar\"", $log); } - - /** - * @param string $path - */ - 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); - } } class MustacheStub extends Mustache_Engine diff --git a/test/Mustache/Test/FunctionalTestCase.php b/test/Mustache/Test/FunctionalTestCase.php new file mode 100644 index 0000000..73cfa9c --- /dev/null +++ b/test/Mustache/Test/FunctionalTestCase.php @@ -0,0 +1,47 @@ + Date: Tue, 25 Mar 2014 09:19:28 -0700 Subject: [PATCH 14/35] Extract spec loading code into base test case --- .../FiveThree/Functional/MustacheSpecTest.php | 56 +--------------- .../Test/Functional/MustacheSpecTest.php | 57 +--------------- test/Mustache/Test/SpecTestCase.php | 67 +++++++++++++++++++ 3 files changed, 69 insertions(+), 111 deletions(-) create mode 100644 test/Mustache/Test/SpecTestCase.php diff --git a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php index 004ec21..446aa49 100644 --- a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php +++ b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php @@ -15,15 +15,8 @@ * @group mustache-spec * @group functional */ -class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase +class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends Mustache_Test_SpecTestCase { - private static $mustache; - - public static function setUpBeforeClass() - { - self::$mustache = new Mustache_Engine; - } - /** * For some reason data providers can't mark tests skipped, so this test exists * simply to provide a 'skipped' test if the `spec` submodule isn't initialized. @@ -72,51 +65,4 @@ class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framew return $data; } - - /** - * Data provider for the mustache spec test. - * - * Loads YAML files from the spec and converts them to PHPisms. - * - * @param string $name - * - * @return array - */ - private function loadSpec($name) - { - $filename = dirname(__FILE__) . '/../../../../../vendor/spec/specs/' . $name . '.yml'; - if (!file_exists($filename)) { - return array(); - } - - $data = array(); - $yaml = new sfYamlParser; - $file = file_get_contents($filename); - - // @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain. - if ($name === '~lambdas') { - $file = str_replace(" !code\n", "\n", $file); - } - - $spec = $yaml->parse($file); - - foreach ($spec['tests'] as $test) { - $data[] = array( - $test['name'] . ': ' . $test['desc'], - $test['template'], - isset($test['partials']) ? $test['partials'] : array(), - $test['data'], - $test['expected'], - ); - } - - return $data; - } - - private static function loadTemplate($source, $partials) - { - self::$mustache->setPartials($partials); - - return self::$mustache->loadTemplate($source); - } } diff --git a/test/Mustache/Test/Functional/MustacheSpecTest.php b/test/Mustache/Test/Functional/MustacheSpecTest.php index e21efba..96fcf40 100644 --- a/test/Mustache/Test/Functional/MustacheSpecTest.php +++ b/test/Mustache/Test/Functional/MustacheSpecTest.php @@ -15,16 +15,8 @@ * @group mustache-spec * @group functional */ -class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase +class Mustache_Test_Functional_MustacheSpecTest extends Mustache_Test_SpecTestCase { - - private static $mustache; - - public static function setUpBeforeClass() - { - self::$mustache = new Mustache_Engine; - } - /** * For some reason data providers can't mark tests skipped, so this test exists * simply to provide a 'skipped' test if the `spec` submodule isn't initialized. @@ -126,51 +118,4 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa { return $this->loadSpec('sections'); } - - /** - * Data provider for the mustache spec test. - * - * Loads YAML files from the spec and converts them to PHPisms. - * - * @param string $name - * - * @return array - */ - private function loadSpec($name) - { - $filename = dirname(__FILE__) . '/../../../../vendor/spec/specs/' . $name . '.yml'; - if (!file_exists($filename)) { - return array(); - } - - $data = array(); - $yaml = new sfYamlParser; - $file = file_get_contents($filename); - - // @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain. - if ($name === '~lambdas') { - $file = str_replace(" !code\n", "\n", $file); - } - - $spec = $yaml->parse($file); - - foreach ($spec['tests'] as $test) { - $data[] = array( - $test['name'] . ': ' . $test['desc'], - $test['template'], - isset($test['partials']) ? $test['partials'] : array(), - $test['data'], - $test['expected'], - ); - } - - return $data; - } - - private static function loadTemplate($source, $partials) - { - self::$mustache->setPartials($partials); - - return self::$mustache->loadTemplate($source); - } } diff --git a/test/Mustache/Test/SpecTestCase.php b/test/Mustache/Test/SpecTestCase.php new file mode 100644 index 0000000..d4dc2c9 --- /dev/null +++ b/test/Mustache/Test/SpecTestCase.php @@ -0,0 +1,67 @@ +setPartials($partials); + + return self::$mustache->loadTemplate($source); + } + + /** + * Data provider for the mustache spec test. + * + * Loads YAML files from the spec and converts them to PHPisms. + * + * @param string $name + * + * @return array + */ + protected function loadSpec($name) + { + $filename = dirname(__FILE__) . '/../../../vendor/spec/specs/' . $name . '.yml'; + if (!file_exists($filename)) { + return array(); + } + + $data = array(); + $yaml = new sfYamlParser; + $file = file_get_contents($filename); + + // @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain. + if ($name === '~lambdas') { + $file = str_replace(" !code\n", "\n", $file); + } + + $spec = $yaml->parse($file); + + foreach ($spec['tests'] as $test) { + $data[] = array( + $test['name'] . ': ' . $test['desc'], + $test['template'], + isset($test['partials']) ? $test['partials'] : array(), + $test['data'], + $test['expected'], + ); + } + + return $data; + } +} From 2bb13b37a46144f8247fb6b807ad0fdd4e1c590a Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 09:21:16 -0700 Subject: [PATCH 15/35] Minor CS changes. --- .../Functional/ClosureQuirksTest.php | 4 ++-- .../Test/FiveThree/Functional/FiltersTest.php | 18 ++++++++--------- .../Functional/HigherOrderSectionsTest.php | 6 +++--- .../FiveThree/Functional/LambdaHelperTest.php | 2 +- .../FiveThree/Functional/MustacheSpecTest.php | 2 +- .../Functional/PartialLambdaIndentTest.php | 2 +- .../Functional/SectionFiltersTest.php | 20 +++++++++---------- .../Functional/StrictCallablesTest.php | 10 +++++----- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/test/Mustache/Test/FiveThree/Functional/ClosureQuirksTest.php b/test/Mustache/Test/FiveThree/Functional/ClosureQuirksTest.php index 52f3974..23ac43b 100644 --- a/test/Mustache/Test/FiveThree/Functional/ClosureQuirksTest.php +++ b/test/Mustache/Test/FiveThree/Functional/ClosureQuirksTest.php @@ -13,7 +13,7 @@ * @group lambdas * @group functional */ -class Mustache_Test_FiveThree_Functional_ClosuresQuirksTest extends PHPUnit_Framework_TestCase +class Mustache_Test_FiveThree_Functional_ClosureQuirksTest extends PHPUnit_Framework_TestCase { private $mustache; @@ -25,6 +25,6 @@ class Mustache_Test_FiveThree_Functional_ClosuresQuirksTest extends PHPUnit_Fram public function testClosuresDontLikeItWhenYouTouchTheirProperties() { $tpl = $this->mustache->loadTemplate('{{ foo.bar }}'); - $this->assertEquals('', $tpl->render(array('foo' => function() { return 'FOO'; }))); + $this->assertEquals('', $tpl->render(array('foo' => function () { return 'FOO'; }))); } } diff --git a/test/Mustache/Test/FiveThree/Functional/FiltersTest.php b/test/Mustache/Test/FiveThree/Functional/FiltersTest.php index 323881e..96e590a 100644 --- a/test/Mustache/Test/FiveThree/Functional/FiltersTest.php +++ b/test/Mustache/Test/FiveThree/Functional/FiltersTest.php @@ -27,7 +27,7 @@ class Mustache_Test_FiveThree_Functional_FiltersTest extends PHPUnit_Framework_T { $tpl = $this->mustache->loadTemplate('{{% FILTERS }}{{ date | longdate }}'); - $this->mustache->addHelper('longdate', function(\DateTime $value) { + $this->mustache->addHelper('longdate', function (\DateTime $value) { return $value->format('Y-m-d h:m:s'); }); @@ -41,11 +41,11 @@ class Mustache_Test_FiveThree_Functional_FiltersTest extends PHPUnit_Framework_T { $tpl = $this->mustache->loadTemplate('{{% FILTERS }}{{ date | longdate | withbrackets }}'); - $this->mustache->addHelper('longdate', function(\DateTime $value) { + $this->mustache->addHelper('longdate', function (\DateTime $value) { return $value->format('Y-m-d h:m:s'); }); - $this->mustache->addHelper('withbrackets', function($value) { + $this->mustache->addHelper('withbrackets', function ($value) { return sprintf('[[%s]]', $value); }); @@ -60,7 +60,7 @@ class Mustache_Test_FiveThree_Functional_FiltersTest extends PHPUnit_Framework_T $tpl = $this->mustache->loadTemplate('{{% FILTERS }}{{ foo | bar }}'); $this->assertEquals('win!', $tpl->render(array( 'foo' => 'FOO', - 'bar' => function($value) { + 'bar' => function ($value) { return ($value === 'FOO') ? 'win!' : 'fail :('; }, ))); @@ -84,11 +84,11 @@ class Mustache_Test_FiveThree_Functional_FiltersTest extends PHPUnit_Framework_T 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'; })), + 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'; })), ); } } diff --git a/test/Mustache/Test/FiveThree/Functional/HigherOrderSectionsTest.php b/test/Mustache/Test/FiveThree/Functional/HigherOrderSectionsTest.php index 87cc1c4..597c93a 100644 --- a/test/Mustache/Test/FiveThree/Functional/HigherOrderSectionsTest.php +++ b/test/Mustache/Test/FiveThree/Functional/HigherOrderSectionsTest.php @@ -28,7 +28,7 @@ class Mustache_Test_FiveThree_Functional_HigherOrderSectionsTest extends PHPUnit $foo = new Mustache_Test_FiveThree_Functional_Foo; $foo->name = 'Mario'; - $foo->wrapper = function($text) { + $foo->wrapper = function ($text) { return sprintf('
%s
', $text); }; @@ -53,7 +53,7 @@ class Mustache_Test_FiveThree_Functional_HigherOrderSectionsTest extends PHPUnit $data = array( 'name' => 'Bob', - 'wrap' => function($text) { + 'wrap' => function ($text) { return sprintf('[[%s]]', $text); } ); @@ -70,7 +70,7 @@ class Mustache_Test_FiveThree_Functional_Foo public function __construct() { - $this->wrap = function($text) { + $this->wrap = function ($text) { return sprintf('%s', $text); }; } diff --git a/test/Mustache/Test/FiveThree/Functional/LambdaHelperTest.php b/test/Mustache/Test/FiveThree/Functional/LambdaHelperTest.php index 0b7c371..cf24804 100644 --- a/test/Mustache/Test/FiveThree/Functional/LambdaHelperTest.php +++ b/test/Mustache/Test/FiveThree/Functional/LambdaHelperTest.php @@ -29,7 +29,7 @@ class Mustache_Test_FiveThree_Functional_LambdaHelperTest extends PHPUnit_Framew $foo = new StdClass; $foo->name = 'Mario'; - $foo->lambda = function($text, $mustache) { + $foo->lambda = function ($text, $mustache) { return strtoupper($mustache->render($text)); }; diff --git a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php index 446aa49..88094fb 100644 --- a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php +++ b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php @@ -55,7 +55,7 @@ class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends Mustache_Test_ } $func = $val['php']; - $data[$key] = function($text = null) use ($func) { + $data[$key] = function ($text = null) use ($func) { return eval($func); }; } elseif (is_array($val)) { diff --git a/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php b/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php index 8555735..ecc5e23 100644 --- a/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php +++ b/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php @@ -51,7 +51,7 @@ class Mustache_Test_Functional_ClassWithLambda { public function _t() { - return function($val) { + return function ($val) { return strtoupper($val); }; } diff --git a/test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php b/test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php index c319ff5..0c437f6 100644 --- a/test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php +++ b/test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php @@ -27,7 +27,7 @@ class Mustache_Test_FiveThree_Functional_SectionFiltersTest extends PHPUnit_Fram { $tpl = $this->mustache->loadTemplate('{{% FILTERS }}{{# word | echo }}{{ . }}!{{/ word | echo }}'); - $this->mustache->addHelper('echo', function($value) { + $this->mustache->addHelper('echo', function ($value) { return array($value, $value, $value); }); @@ -45,12 +45,12 @@ EOS; { $tpl = $this->mustache->loadTemplate(self::CHAINED_FILTERS_TPL); - $this->mustache->addHelper('echo', function($value) { + $this->mustache->addHelper('echo', function ($value) { return array($value, $value, $value); }); - $this->mustache->addHelper('with_index', function($value) { - return array_map(function($k, $v) { + $this->mustache->addHelper('with_index', function ($value) { + return array_map(function ($k, $v) { return array( 'key' => $k, 'value' => $v, @@ -66,7 +66,7 @@ EOS; $tpl = $this->mustache->loadTemplate('{{% FILTERS }}{{# foo | bar }}{{ . }}{{/ foo | bar }}'); $this->assertEquals('win!', $tpl->render(array( 'foo' => 'FOO', - 'bar' => function($value) { + 'bar' => function ($value) { return ($value === 'FOO') ? 'win!' : 'fail :('; }, ))); @@ -90,11 +90,11 @@ EOS; 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'; })), + 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'; })), ); } diff --git a/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php b/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php index 96e6147..9f68639 100644 --- a/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php +++ b/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php @@ -32,7 +32,7 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra public function callables() { - $lambda = function($tpl, $mustache) { + $lambda = function ($tpl, $mustache) { return strtoupper($mustache->render($tpl)); }; @@ -49,7 +49,7 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra 'YOSHI', ), array( - function() { return 'Yoshi'; }, + function () { return 'Yoshi'; }, $lambda, 'YOSHI', ), @@ -91,14 +91,14 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra public function strictCallables() { - $lambda = function($tpl, $mustache) { + $lambda = function ($tpl, $mustache) { return strtoupper($mustache->render($tpl)); }; return array( // Interpolation lambdas array( - function() { return 'Yoshi'; }, + function () { return 'Yoshi'; }, $lambda, 'YOSHI', ), @@ -116,7 +116,7 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra ), array( 'Yoshi', - function($tpl, $mustache) { + function ($tpl, $mustache) { return strtoupper($mustache->render($tpl)); }, 'YOSHI', From 69c1ff9daab06a5c9f9816c31abf7c21e7f28bf1 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 09:36:25 -0700 Subject: [PATCH 16/35] Revert "Reduce Engine constructor complexity." This reverts commit e9d4af3bbefa0088a5125085f49a9fcc02dcd01c. --- src/Mustache/Engine.php | 63 +++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index f78f375..9eb03d1 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -50,23 +50,6 @@ class Mustache_Engine private $parser; private $compiler; - private static $optionProperties = array( - 'template_class_prefix' => 'templateClassPrefix', - 'cache_lambda_templates' => 'cacheLambdaTemplates', - 'escape' => 'escape', - 'entity_flags' => 'entityFlags', - 'charset' => 'charset', - 'strict_callables' => 'strictCallables', - ); - - private static $optionSetters = array( - 'loader' => 'setLoader', - 'partials_loader' => 'setPartialsLoader', - 'partials' => 'setPartials', - 'helpers' => 'setHelpers', - 'logger' => 'setLogger', - ); - /** * Mustache class constructor. * @@ -135,6 +118,10 @@ class Mustache_Engine */ public function __construct(array $options = array()) { + if (isset($options['template_class_prefix'])) { + $this->templateClassPrefix = $options['template_class_prefix']; + } + if (isset($options['cache'])) { $cache = $options['cache']; @@ -146,22 +133,48 @@ class Mustache_Engine $this->setCache($cache); } + if (isset($options['cache_lambda_templates'])) { + $this->cacheLambdaTemplates = (bool) $options['cache_lambda_templates']; + } + + if (isset($options['loader'])) { + $this->setLoader($options['loader']); + } + + if (isset($options['partials_loader'])) { + $this->setPartialsLoader($options['partials_loader']); + } + + if (isset($options['partials'])) { + $this->setPartials($options['partials']); + } + + if (isset($options['helpers'])) { + $this->setHelpers($options['helpers']); + } + if (isset($options['escape'])) { if (!is_callable($options['escape'])) { throw new Mustache_Exception_InvalidArgumentException('Mustache Constructor "escape" option must be callable'); } + + $this->escape = $options['escape']; } - foreach (self::$optionProperties as $name => $property) { - if (isset($options[$name])) { - $this->$property = $options[$name]; - } + if (isset($options['entity_flags'])) { + $this->entityFlags = $options['entity_flags']; } - foreach (self::$optionSetters as $name => $setter) { - if (isset($options[$name])) { - $this->$setter($options[$name]); - } + if (isset($options['charset'])) { + $this->charset = $options['charset']; + } + + if (isset($options['logger'])) { + $this->setLogger($options['logger']); + } + + if (isset($options['strict_callables'])) { + $this->strictCallables = $options['strict_callables']; } } From de2466864b971ee059e1daf564580428d481aeb9 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 09:42:10 -0700 Subject: [PATCH 17/35] Remove redundant documentation. --- src/Mustache/Loader/CascadingLoader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mustache/Loader/CascadingLoader.php b/src/Mustache/Loader/CascadingLoader.php index cfd74b3..d02a273 100644 --- a/src/Mustache/Loader/CascadingLoader.php +++ b/src/Mustache/Loader/CascadingLoader.php @@ -25,7 +25,7 @@ class Mustache_Loader_CascadingLoader implements Mustache_Loader * new Mustache_Loader_FilesystemLoader(__DIR__.'/templates') * )); * - * @param Mustache_Loader[] $loaders An array of Mustache Loader instances + * @param Mustache_Loader[] $loaders */ public function __construct(array $loaders = array()) { @@ -38,7 +38,7 @@ class Mustache_Loader_CascadingLoader implements Mustache_Loader /** * Add a Loader instance. * - * @param Mustache_Loader $loader A Mustache Loader instance + * @param Mustache_Loader $loader */ public function addLoader(Mustache_Loader $loader) { From af737f4cc72e1463e87f5bf946dab8d126d87a49 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 10:19:55 -0700 Subject: [PATCH 18/35] Fix autoload for Travis --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 47022c5..67e5e84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,6 @@ php: - 5.3 - 5.4 - 5.5 + +before_script: + - composer install \ No newline at end of file From fdff8a4d1524cbb039bdb691cf83341a64f2129b Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 10:48:21 -0700 Subject: [PATCH 19/35] =?UTF-8?q?Let=E2=80=99s=20not=20use=20Composer?= =?UTF-8?q?=E2=80=99s=20autoload,=20since=20it=20fails=20in=205.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit af737f4cc72e1463e87f5bf946dab8d126d87a49. This reverts commit 84a4ff5b16b0be42c969e7da50c7da7ce22fbe55. --- .travis.yml | 3 --- test/bootstrap.php | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 67e5e84..47022c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,3 @@ php: - 5.3 - 5.4 - 5.5 - -before_script: - - composer install \ No newline at end of file diff --git a/test/bootstrap.php b/test/bootstrap.php index deda69e..03a119f 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -9,7 +9,8 @@ * file that was distributed with this source code. */ -$loader = require dirname(__FILE__).'/../vendor/autoload.php'; -$loader->add('Mustache_Test', dirname(__FILE__)); +require dirname(__FILE__).'/../src/Mustache/Autoloader.php'; +Mustache_Autoloader::register(); +Mustache_Autoloader::register(dirname(__FILE__).'/../test'); require dirname(__FILE__).'/../vendor/yaml/lib/sfYamlParser.php'; From 085729aa27f2f4cba073fae2a34b6d16a23d436c Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 18:15:31 -0700 Subject: [PATCH 20/35] remove old test annotation. --- test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php b/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php index 9f68639..2925217 100644 --- a/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php +++ b/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php @@ -74,7 +74,6 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra } /** - * @group wip * @dataProvider strictCallables */ public function testStrictCallablesEnabled($name, $section, $expected) From b61af6e4e89484aeaafa6e6ecb33259ee3e27050 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 18:15:52 -0700 Subject: [PATCH 21/35] Add (failing) test case for disabling lambda cache. --- .../Functional/HigherOrderSectionsTest.php | 46 ++++++++++++++++++- test/Mustache/Test/FunctionalTestCase.php | 2 +- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php index 5883e98..43e927e 100644 --- a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php +++ b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php @@ -13,9 +13,8 @@ * @group lambdas * @group functional */ -class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework_TestCase +class Mustache_Test_Functional_HigherOrderSectionsTest extends Mustache_Test_FunctionalTestCase { - private $mustache; public function setUp() @@ -100,6 +99,49 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends PHPUnit_Framework $this->assertEquals('' . $foo->name . '', $tpl->render($foo)); } + + public function testEnablingLambdaCacheActuallyWorks() + { + $cacheDir = $this->setUpCacheDir('test_enabling_lambda_cache'); + $mustache = new Mustache_Engine(array( + 'template_class_prefix' => '_TestEnablingLambdaCache_', + 'cache' => $cacheDir, + 'cache_lambda_templates' => true, + )); + + $tpl = $mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}'); + $foo = new Mustache_Test_Functional_Foo; + $foo->wrap = array($foo, 'wrapWithEm'); + $this->assertEquals('' . $foo->name . '', $tpl->render($foo)); + $this->assertCount(2, glob($cacheDir . '/*.php')); + } + + public function testDisablingLambdaCacheActuallyWorks() + { + $cacheDir = $this->setUpCacheDir('test_disabling_lambda_cache'); + $mustache = new Mustache_Engine(array( + 'template_class_prefix' => '_TestDisablingLambdaCache_', + 'cache' => $cacheDir, + 'cache_lambda_templates' => false, + )); + + $tpl = $mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}'); + $foo = new Mustache_Test_Functional_Foo; + $foo->wrap = array($foo, 'wrapWithEm'); + $this->assertEquals('' . $foo->name . '', $tpl->render($foo)); + $this->assertCount(1, glob($cacheDir . '/*.php')); + } + + protected function setUpCacheDir($name) + { + $cacheDir = self::$tempDir . '/' . $name; + if (file_exists($cacheDir)) { + self::rmdir($cacheDir); + } + mkdir($cacheDir, 0777, true); + + return $cacheDir; + } } class Mustache_Test_Functional_Foo diff --git a/test/Mustache/Test/FunctionalTestCase.php b/test/Mustache/Test/FunctionalTestCase.php index 73cfa9c..4d243e0 100644 --- a/test/Mustache/Test/FunctionalTestCase.php +++ b/test/Mustache/Test/FunctionalTestCase.php @@ -24,7 +24,7 @@ abstract class Mustache_Test_FunctionalTestCase extends PHPUnit_Framework_TestCa /** * @param string $path */ - private static function rmdir($path) + protected static function rmdir($path) { $path = rtrim($path, '/').'/'; $handle = opendir($path); From 77d99d2bd3aebc73e58544ac016959831bb7354f Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 18:16:35 -0700 Subject: [PATCH 22/35] Fix disabling lambda template cache. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because it’s so much awesomer when config options actually do what they say they do. --- src/Mustache/Engine.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index 9eb03d1..87008b6 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -662,9 +662,9 @@ class Mustache_Engine } if (!class_exists($className, false)) { - if (!$this->getCache()->load($className)) { + if (!$cache->load($className)) { $compiled = $this->compile($source); - $this->getCache()->cache($className, $compiled); + $cache->cache($className, $compiled); } } From ada9876c18680cd61a6942bac492fc0d1d670b79 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 18:33:26 -0700 Subject: [PATCH 23/35] Refactor out test code duplication (enable/disable lambda template cache test) --- .../Functional/HigherOrderSectionsTest.php | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php index 43e927e..ecbc808 100644 --- a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php +++ b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php @@ -100,36 +100,31 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends Mustache_Test_Fun $this->assertEquals('' . $foo->name . '', $tpl->render($foo)); } - public function testEnablingLambdaCacheActuallyWorks() + /** + * @dataProvider cacheLambdaTemplatesData + */ + public function testCacheLambdaTemplatesOptionWorks($dirName, $tplPrefix, $enable, $expect) { - $cacheDir = $this->setUpCacheDir('test_enabling_lambda_cache'); + $cacheDir = $this->setUpCacheDir($dirName); $mustache = new Mustache_Engine(array( - 'template_class_prefix' => '_TestEnablingLambdaCache_', + 'template_class_prefix' => $tplPrefix, 'cache' => $cacheDir, - 'cache_lambda_templates' => true, + 'cache_lambda_templates' => $enable, )); $tpl = $mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}'); $foo = new Mustache_Test_Functional_Foo; $foo->wrap = array($foo, 'wrapWithEm'); $this->assertEquals('' . $foo->name . '', $tpl->render($foo)); - $this->assertCount(2, glob($cacheDir . '/*.php')); + $this->assertCount($expect, glob($cacheDir . '/*.php')); } - public function testDisablingLambdaCacheActuallyWorks() + public function cacheLambdaTemplatesData() { - $cacheDir = $this->setUpCacheDir('test_disabling_lambda_cache'); - $mustache = new Mustache_Engine(array( - 'template_class_prefix' => '_TestDisablingLambdaCache_', - 'cache' => $cacheDir, - 'cache_lambda_templates' => false, - )); - - $tpl = $mustache->loadTemplate('{{#wrap}}{{name}}{{/wrap}}'); - $foo = new Mustache_Test_Functional_Foo; - $foo->wrap = array($foo, 'wrapWithEm'); - $this->assertEquals('' . $foo->name . '', $tpl->render($foo)); - $this->assertCount(1, glob($cacheDir . '/*.php')); + return array( + array('test_enabling_lambda_cache', '_TestEnablingLambdaCache_', true, 2), + array('test_disabling_lambda_cache', '_TestDisablingLambdaCache_', false, 1), + ); } protected function setUpCacheDir($name) From 0b85c9daff75d770955ea3ffbdf270f529060e20 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 18:38:21 -0700 Subject: [PATCH 24/35] Refactor out section callback test duplication. --- .../Functional/HigherOrderSectionsTest.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php index ecbc808..b042455 100644 --- a/test/Mustache/Test/Functional/HigherOrderSectionsTest.php +++ b/test/Mustache/Test/Functional/HigherOrderSectionsTest.php @@ -22,24 +22,26 @@ class Mustache_Test_Functional_HigherOrderSectionsTest extends Mustache_Test_Fun $this->mustache = new Mustache_Engine; } - public function testRuntimeSectionCallback() + /** + * @dataProvider sectionCallbackData + */ + public function testSectionCallback($data, $tpl, $expect) { - $tpl = $this->mustache->loadTemplate('{{#doublewrap}}{{name}}{{/doublewrap}}'); + $this->assertEquals($expect, $this->mustache->render($tpl, $data)); + } + public function sectionCallbackData() + { $foo = new Mustache_Test_Functional_Foo; $foo->doublewrap = array($foo, 'wrapWithBoth'); - $this->assertEquals(sprintf('%s', $foo->name), $tpl->render($foo)); - } + $bar = new Mustache_Test_Functional_Foo; + $bar->trimmer = array(get_class($bar), 'staticTrim'); - public function testStaticSectionCallback() - { - $tpl = $this->mustache->loadTemplate('{{#trimmer}} {{name}} {{/trimmer}}'); - - $foo = new Mustache_Test_Functional_Foo; - $foo->trimmer = array(get_class($foo), 'staticTrim'); - - $this->assertEquals($foo->name, $tpl->render($foo)); + return array( + array($foo, '{{#doublewrap}}{{name}}{{/doublewrap}}', sprintf('%s', $foo->name)), + array($bar, '{{#trimmer}} {{name}} {{/trimmer}}', $bar->name), + ); } public function testViewArraySectionCallback() From 2abbc4b35cb8f20d5108cc54f83e06b9574df927 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 18:44:39 -0700 Subject: [PATCH 25/35] Refactor away engine logger test duplication. --- test/Mustache/Test/EngineTest.php | 39 ++++++++++++------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/test/Mustache/Test/EngineTest.php b/test/Mustache/Test/EngineTest.php index faeed29..6904d18 100644 --- a/test/Mustache/Test/EngineTest.php +++ b/test/Mustache/Test/EngineTest.php @@ -298,44 +298,35 @@ class Mustache_Test_EngineTest extends Mustache_Test_FunctionalTestCase public function testCacheWarningLogging() { - $name = tempnam(sys_get_temp_dir(), 'mustache-test'); - $mustache = new Mustache_Engine(array( - 'logger' => new Mustache_Logger_StreamLogger($name, Mustache_Logger::WARNING) - )); - - $result = $mustache->render('{{ foo }}', array('foo' => 'FOO')); - $this->assertEquals('FOO', $result); - + list($name, $mustache) = $this->getLoggedMustache(Mustache_Logger::WARNING); + $mustache->render('{{ foo }}', array('foo' => 'FOO')); $this->assertContains('WARNING: Template cache disabled, evaluating', file_get_contents($name)); } public function testLoggingIsNotTooAnnoying() { - $name = tempnam(sys_get_temp_dir(), 'mustache-test'); - $mustache = new Mustache_Engine(array( - 'logger' => new Mustache_Logger_StreamLogger($name) - )); - - $result = $mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO')); - $this->assertEquals('FOO', $result); - + list($name, $mustache) = $this->getLoggedMustache(); + $mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO')); $this->assertEmpty(file_get_contents($name)); } public function testVerboseLoggingIsVerbose() + { + list($name, $mustache) = $this->getLoggedMustache(Mustache_Logger::DEBUG); + $mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO')); + $log = file_get_contents($name); + $this->assertContains("DEBUG: Instantiating template: ", $log); + $this->assertContains("WARNING: Partial not found: \"bar\"", $log); + } + + private function getLoggedMustache($level = Mustache_Logger::ERROR) { $name = tempnam(sys_get_temp_dir(), 'mustache-test'); $mustache = new Mustache_Engine(array( - 'logger' => new Mustache_Logger_StreamLogger($name, Mustache_Logger::DEBUG) + 'logger' => new Mustache_Logger_StreamLogger($name, $level) )); - $result = $mustache->render('{{ foo }}{{> bar }}', array('foo' => 'FOO')); - $this->assertEquals('FOO', $result); - - $log = file_get_contents($name); - - $this->assertContains("DEBUG: Instantiating template: ", $log); - $this->assertContains("WARNING: Partial not found: \"bar\"", $log); + return array($name, $mustache); } } From ad0204c37287a5e6df2b410c12dd947d90613ca1 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 19:04:48 -0700 Subject: [PATCH 26/35] Combine FiltersTest and SectionFiltersTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They’re basically duplicates, so this clears up a bunch of code :) --- .../Test/FiveThree/Functional/FiltersTest.php | 123 ++++++++++++++---- .../Functional/SectionFiltersTest.php | 101 -------------- 2 files changed, 96 insertions(+), 128 deletions(-) delete mode 100644 test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php diff --git a/test/Mustache/Test/FiveThree/Functional/FiltersTest.php b/test/Mustache/Test/FiveThree/Functional/FiltersTest.php index 96e590a..a55a1b6 100644 --- a/test/Mustache/Test/FiveThree/Functional/FiltersTest.php +++ b/test/Mustache/Test/FiveThree/Functional/FiltersTest.php @@ -15,7 +15,6 @@ */ class Mustache_Test_FiveThree_Functional_FiltersTest extends PHPUnit_Framework_TestCase { - private $mustache; public function setUp() @@ -23,18 +22,41 @@ class Mustache_Test_FiveThree_Functional_FiltersTest extends PHPUnit_Framework_T $this->mustache = new Mustache_Engine; } - public function testSingleFilter() + /** + * @dataProvider singleFilterData + */ + public function testSingleFilter($tpl, $helpers, $data, $expect) { - $tpl = $this->mustache->loadTemplate('{{% FILTERS }}{{ date | longdate }}'); + $this->mustache->setHelpers($helpers); + $this->assertEquals($expect, $this->mustache->render($tpl, $data)); + } - $this->mustache->addHelper('longdate', function (\DateTime $value) { - return $value->format('Y-m-d h:m:s'); - }); + public function singleFilterData() + { + $helpers = array( + 'longdate' => function (\DateTime $value) { + return $value->format('Y-m-d h:m:s'); + }, + 'echo' => function ($value) { + return array($value, $value, $value); + }, + ); - $foo = new \StdClass; - $foo->date = new DateTime('1/1/2000'); + return array( + array( + '{{% FILTERS }}{{ date | longdate }}', + $helpers, + (object) array('date' => new DateTime('1/1/2000')), + '2000-01-01 12:01:00' + ), - $this->assertEquals('2000-01-01 12:01:00', $tpl->render($foo)); + array( + '{{% FILTERS }}{{# word | echo }}{{ . }}!{{/ word | echo }}', + $helpers, + array('word' => 'bacon'), + 'bacon!bacon!bacon!' + ), + ); } public function testChainedFilters() @@ -55,40 +77,87 @@ class Mustache_Test_FiveThree_Functional_FiltersTest extends PHPUnit_Framework_T $this->assertEquals('[[2000-01-01 12:01:00]]', $tpl->render($foo)); } - public function testInterpolateFirst() + const CHAINED_SECTION_FILTERS_TPL = <<mustache->loadTemplate('{{% FILTERS }}{{ foo | bar }}'); - $this->assertEquals('win!', $tpl->render(array( + $tpl = $this->mustache->loadTemplate(self::CHAINED_SECTION_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'))); + } + + /** + * @dataProvider interpolateFirstData + */ + public function testInterpolateFirst($tpl, $data, $expect) + { + $this->assertEquals($expect, $this->mustache->render($tpl, $data)); + } + + public function interpolateFirstData() + { + $data = array( 'foo' => 'FOO', 'bar' => function ($value) { return ($value === 'FOO') ? 'win!' : 'fail :('; }, - ))); + ); + + return array( + array('{{% FILTERS }}{{ foo | bar }}', $data, 'win!'), + array('{{% FILTERS }}{{# foo | bar }}{{ . }}{{/ foo | bar }}', $data, 'win!'), + ); } /** * @expectedException Mustache_Exception_UnknownFilterException - * @dataProvider getBrokenPipes + * @dataProvider brokenPipeData */ public function testThrowsExceptionForBrokenPipes($tpl, $data) { - $this->mustache - ->loadTemplate(sprintf('{{%% FILTERS }}{{ %s }}', $tpl)) - ->render($data); + $this->mustache->render($tpl, $data); } - public function getBrokenPipes() + public function brokenPipeData() { 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'; })), + array('{{% FILTERS }}{{ foo | bar }}', array()), + array('{{% FILTERS }}{{ foo | bar }}', array('foo' => 'FOO')), + array('{{% FILTERS }}{{ foo | bar }}', array('foo' => 'FOO', 'bar' => 'BAR')), + array('{{% FILTERS }}{{ foo | bar }}', array('foo' => 'FOO', 'bar' => array(1, 2))), + array('{{% FILTERS }}{{ foo | bar | baz }}', array('foo' => 'FOO', 'bar' => function () { return 'BAR'; })), + array('{{% FILTERS }}{{ foo | bar | baz }}', array('foo' => 'FOO', 'baz' => function () { return 'BAZ'; })), + array('{{% FILTERS }}{{ foo | bar | baz }}', array('bar' => function () { return 'BAR'; })), + array('{{% FILTERS }}{{ foo | bar | baz }}', array('baz' => function () { return 'BAZ'; })), + array('{{% FILTERS }}{{ foo | bar.baz }}', array('foo' => 'FOO', 'bar' => function () { return 'BAR'; }, 'baz' => function () { return 'BAZ'; })), + + array('{{% FILTERS }}{{# foo | bar }}{{ . }}{{/ foo | bar }}', array()), + array('{{% FILTERS }}{{# foo | bar }}{{ . }}{{/ foo | bar }}', array('foo' => 'FOO')), + array('{{% FILTERS }}{{# foo | bar }}{{ . }}{{/ foo | bar }}', array('foo' => 'FOO', 'bar' => 'BAR')), + array('{{% FILTERS }}{{# foo | bar }}{{ . }}{{/ foo | bar }}', array('foo' => 'FOO', 'bar' => array(1, 2))), + array('{{% FILTERS }}{{# foo | bar | baz }}{{ . }}{{/ foo | bar | baz }}', array('foo' => 'FOO', 'bar' => function () { return 'BAR'; })), + array('{{% FILTERS }}{{# foo | bar | baz }}{{ . }}{{/ foo | bar | baz }}', array('foo' => 'FOO', 'baz' => function () { return 'BAZ'; })), + array('{{% FILTERS }}{{# foo | bar | baz }}{{ . }}{{/ foo | bar | baz }}', array('bar' => function () { return 'BAR'; })), + array('{{% FILTERS }}{{# foo | bar | baz }}{{ . }}{{/ foo | bar | baz }}', array('baz' => function () { return 'BAZ'; })), + array('{{% FILTERS }}{{# foo | bar.baz }}{{ . }}{{/ foo | bar.baz }}', array('foo' => 'FOO', 'bar' => function () { return 'BAR'; }, 'baz' => function () { return 'BAZ'; })), ); } } diff --git a/test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php b/test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php deleted file mode 100644 index 0c437f6..0000000 --- a/test/Mustache/Test/FiveThree/Functional/SectionFiltersTest.php +++ /dev/null @@ -1,101 +0,0 @@ -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 = <<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'; })), - ); - } - -} From 402f5013dcf580d6a2792770de8eb276e9a2cb2a Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 19:16:29 -0700 Subject: [PATCH 27/35] Refactor duplication out of Mustache injection test. --- .../Test/Functional/MustacheInjectionTest.php | 124 +++++------------- 1 file changed, 32 insertions(+), 92 deletions(-) diff --git a/test/Mustache/Test/Functional/MustacheInjectionTest.php b/test/Mustache/Test/Functional/MustacheInjectionTest.php index 2bc1b85..5774aa3 100644 --- a/test/Mustache/Test/Functional/MustacheInjectionTest.php +++ b/test/Mustache/Test/Functional/MustacheInjectionTest.php @@ -23,105 +23,58 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T $this->mustache = new Mustache_Engine; } - // interpolation - - public function testInterpolationInjection() + /** + * @dataProvider injectionData + */ + public function testInjection($tpl, $data, $partials, $expect) { - $tpl = $this->mustache->loadTemplate('{{ a }}'); + $this->mustache->setPartials($partials); + $this->assertEquals($expect, $this->mustache->render($tpl, $data)); + } - $data = array( + public function injectionData() + { + $interpolationData = array( 'a' => '{{ b }}', 'b' => 'FAIL' ); - $this->assertEquals('{{ b }}', $tpl->render($data)); - } - - public function testUnescapedInterpolationInjection() - { - $tpl = $this->mustache->loadTemplate('{{{ a }}}'); - - $data = array( - 'a' => '{{ b }}', - 'b' => 'FAIL' - ); - - $this->assertEquals('{{ b }}', $tpl->render($data)); - } - - // sections - - public function testSectionInjection() - { - $tpl = $this->mustache->loadTemplate('{{# a }}{{ b }}{{/ a }}'); - - $data = array( + $sectionData = array( 'a' => true, 'b' => '{{ c }}', 'c' => 'FAIL' ); - $this->assertEquals('{{ c }}', $tpl->render($data)); - } - - public function testUnescapedSectionInjection() - { - $tpl = $this->mustache->loadTemplate('{{# a }}{{{ b }}}{{/ a }}'); - - $data = array( - 'a' => true, - 'b' => '{{ c }}', - 'c' => 'FAIL' - ); - - $this->assertEquals('{{ c }}', $tpl->render($data)); - } - - // partials - - public function testPartialInjection() - { - $tpl = $this->mustache->loadTemplate('{{> partial }}'); - $this->mustache->setPartials(array( - 'partial' => '{{ a }}', - )); - - $data = array( + $partialData = array( 'a' => '{{ b }}', 'b' => 'FAIL' ); - $this->assertEquals('{{ b }}', $tpl->render($data)); - } - - public function testPartialUnescapedInjection() - { - $tpl = $this->mustache->loadTemplate('{{> partial }}'); - $this->mustache->setPartials(array( - 'partial' => '{{{ a }}}', - )); - - $data = array( - 'a' => '{{ b }}', - 'b' => 'FAIL' - ); - - $this->assertEquals('{{ b }}', $tpl->render($data)); - } - - // lambdas - - public function testLambdaInterpolationInjection() - { - $tpl = $this->mustache->loadTemplate('{{ a }}'); - - $data = array( + $lambdaInterpolationData = array( 'a' => array($this, 'lambdaInterpolationCallback'), 'b' => '{{ c }}', 'c' => 'FAIL' ); - $this->assertEquals('{{ c }}', $tpl->render($data)); + $lambdaSectionData = array( + 'a' => array($this, 'lambdaSectionCallback'), + 'b' => '{{ c }}', + 'c' => 'FAIL' + ); + + return array( + array('{{ a }}', $interpolationData, array(), '{{ b }}'), + array('{{{ a }}}', $interpolationData, array(), '{{ b }}'), + + array('{{# a }}{{ b }}{{/ a }}', $sectionData, array(), '{{ c }}'), + array('{{# a }}{{{ b }}}{{/ a }}', $sectionData, array(), '{{ c }}'), + + array('{{> partial }}', $interpolationData, array('partial' => '{{ a }}'), '{{ b }}'), + array('{{> partial }}', $interpolationData, array('partial' => '{{{ a }}}'), '{{ b }}'), + + array('{{ a }}', $lambdaInterpolationData, array(), '{{ c }}'), + array('{{# a }}b{{/ a }}', $lambdaSectionData, array(), '{{ c }}'), + ); } public static function lambdaInterpolationCallback() @@ -129,19 +82,6 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T return '{{ b }}'; } - public function testLambdaSectionInjection() - { - $tpl = $this->mustache->loadTemplate('{{# a }}b{{/ a }}'); - - $data = array( - 'a' => array($this, 'lambdaSectionCallback'), - 'b' => '{{ c }}', - 'c' => 'FAIL' - ); - - $this->assertEquals('{{ c }}', $tpl->render($data)); - } - public static function lambdaSectionCallback($text) { return '{{ ' . $text . ' }}'; From c10c966e604f3d5c5da98b45c955a32acb25169c Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 19:22:34 -0700 Subject: [PATCH 28/35] Refactor to remove duplicate StreamLogger test code --- .../Mustache/Test/Logger/StreamLoggerTest.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/test/Mustache/Test/Logger/StreamLoggerTest.php b/test/Mustache/Test/Logger/StreamLoggerTest.php index 236deb6..e64c481 100644 --- a/test/Mustache/Test/Logger/StreamLoggerTest.php +++ b/test/Mustache/Test/Logger/StreamLoggerTest.php @@ -14,23 +14,26 @@ */ class Mustache_Test_Logger_StreamLoggerTest extends PHPUnit_Framework_TestCase { - public function testAcceptsFilename() + /** + * @dataProvider acceptsStreamData + */ + public function testAcceptsStream($name, $stream) { - $name = tempnam(sys_get_temp_dir(), 'mustache-test'); - $logger = new Mustache_Logger_StreamLogger($name); + $logger = new Mustache_Logger_StreamLogger($stream); $logger->log(Mustache_Logger::CRITICAL, 'message'); $this->assertEquals("CRITICAL: message\n", file_get_contents($name)); } - public function testAcceptsResource() + public function acceptsStreamData() { - $name = tempnam(sys_get_temp_dir(), 'mustache-test'); - $file = fopen($name, 'a'); - $logger = new Mustache_Logger_StreamLogger($file); - $logger->log(Mustache_Logger::CRITICAL, 'message'); + $one = tempnam(sys_get_temp_dir(), 'mustache-test'); + $two = tempnam(sys_get_temp_dir(), 'mustache-test'); - $this->assertEquals("CRITICAL: message\n", file_get_contents($name)); + return array( + array($one, $one), + array($two, fopen($two, 'a')), + ); } /** From 125873a8e0ed9f9f00e4a96be874fc7e97ad9943 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 19:28:36 -0700 Subject: [PATCH 29/35] Remove unused $partialData. --- test/Mustache/Test/Functional/MustacheInjectionTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/Mustache/Test/Functional/MustacheInjectionTest.php b/test/Mustache/Test/Functional/MustacheInjectionTest.php index 5774aa3..a36c469 100644 --- a/test/Mustache/Test/Functional/MustacheInjectionTest.php +++ b/test/Mustache/Test/Functional/MustacheInjectionTest.php @@ -45,11 +45,6 @@ class Mustache_Test_Functional_MustacheInjectionTest extends PHPUnit_Framework_T 'c' => 'FAIL' ); - $partialData = array( - 'a' => '{{ b }}', - 'b' => 'FAIL' - ); - $lambdaInterpolationData = array( 'a' => array($this, 'lambdaInterpolationCallback'), 'b' => '{{ c }}', From b8b156d3cca8e7983b52aafff079822c413fb0ae Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 19:35:56 -0700 Subject: [PATCH 30/35] Refactor to remove strict callables test duplication. --- .../Functional/StrictCallablesTest.php | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php b/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php index 2925217..479e038 100644 --- a/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php +++ b/test/Mustache/Test/FiveThree/Functional/StrictCallablesTest.php @@ -18,9 +18,9 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra /** * @dataProvider callables */ - public function testStrictCallablesDisabled($name, $section, $expected) + public function testStrictCallables($strict, $name, $section, $expected) { - $mustache = new Mustache_Engine(array('strict_callables' => false)); + $mustache = new Mustache_Engine(array('strict_callables' => $strict)); $tpl = $mustache->loadTemplate('{{# section }}{{ name }}{{/ section }}'); $data = new StdClass; @@ -39,16 +39,19 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra return array( // Interpolation lambdas array( + false, array($this, 'instanceName'), $lambda, 'YOSHI', ), array( + false, array(__CLASS__, 'staticName'), $lambda, 'YOSHI', ), array( + false, function () { return 'Yoshi'; }, $lambda, 'YOSHI', @@ -56,64 +59,47 @@ class Mustache_Test_FiveThree_Functional_StrictCallablesTest extends PHPUnit_Fra // Section lambdas array( + false, 'Yoshi', array($this, 'instanceCallable'), 'YOSHI', ), array( + false, 'Yoshi', array(__CLASS__, 'staticCallable'), 'YOSHI', ), array( + false, 'Yoshi', $lambda, 'YOSHI', ), - ); - } - /** - * @dataProvider strictCallables - */ - public function testStrictCallablesEnabled($name, $section, $expected) - { - $mustache = new Mustache_Engine(array('strict_callables' => true)); - $tpl = $mustache->loadTemplate('{{# section }}{{ name }}{{/ section }}'); - - $data = new StdClass; - $data->name = $name; - $data->section = $section; - - $this->assertEquals($expected, $tpl->render($data)); - } - - public function strictCallables() - { - $lambda = function ($tpl, $mustache) { - return strtoupper($mustache->render($tpl)); - }; - - return array( - // Interpolation lambdas + // Strict interpolation lambdas array( + true, function () { return 'Yoshi'; }, $lambda, 'YOSHI', ), - // Section lambdas + // Strict section lambdas array( + true, 'Yoshi', array($this, 'instanceCallable'), 'YoshiYoshi', ), array( + true, 'Yoshi', array(__CLASS__, 'staticCallable'), 'YoshiYoshi', ), array( + true, 'Yoshi', function ($tpl, $mustache) { return strtoupper($mustache->render($tpl)); From d5b1add8244d764fdbd8a2a0e70cb1aa331185e4 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sat, 29 Mar 2014 10:41:09 -0700 Subject: [PATCH 31/35] let's try it with *all* the versions! --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 47022c5..5ea5ad8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,5 @@ php: - 5.3 - 5.4 - 5.5 + - 5.6 + - hhvm From 8f831201bd3ebe61f6e6e075752c052ed8df01b7 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sat, 29 Mar 2014 10:58:16 -0700 Subject: [PATCH 32/35] allow hhvm to fail for now --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 5ea5ad8..d3c7b45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,7 @@ php: - 5.5 - 5.6 - hhvm + +matrix: + allow_failures: + php: hhvm # See https://github.com/facebook/hhvm/pull/1860 \ No newline at end of file From 0315da508b3dc12130df1164655172fa79d48a70 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sat, 29 Mar 2014 12:26:14 -0700 Subject: [PATCH 33/35] Again, but with more following the instructions. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d3c7b45..e73c8b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ php: matrix: allow_failures: - php: hhvm # See https://github.com/facebook/hhvm/pull/1860 \ No newline at end of file + - php: hhvm # See https://github.com/facebook/hhvm/pull/1860 \ No newline at end of file From c96e985dbfe063d8ca7a3e7361ee937c97e9fa68 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sun, 13 Apr 2014 16:47:55 -0700 Subject: [PATCH 34/35] Shiny new shields! --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1c49ae3..b33b355 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ Mustache.php A [Mustache](http://mustache.github.com/) implementation in PHP. -[![Build Status](https://secure.travis-ci.org/bobthecow/mustache.php.png?branch=dev)](http://travis-ci.org/bobthecow/mustache.php) +[![Package version](http://img.shields.io/packagist/v/mustache/mustache.svg)](https://packagist.org/packages/mustache/mustache) +[![Build status](http://img.shields.io/travis/bobthecow/mustache.php/dev.svg)](http://travis-ci.org/bobthecow/mustache.php) +[![Monthly downloads](http://img.shields.io/packagist/dm/mustache/mustache.svg)](https://packagist.org/packages/mustache/mustache) Usage From 003a2ae5e7ee4c579d55cf43847c5bcf584798ed Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sun, 13 Apr 2014 18:23:23 -0700 Subject: [PATCH 35/35] Bump to v2.6.0 --- src/Mustache/Engine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index 87008b6..b395336 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -23,7 +23,7 @@ */ class Mustache_Engine { - const VERSION = '2.5.1'; + const VERSION = '2.6.0'; const SPEC_VERSION = '1.1.2'; const PRAGMA_FILTERS = 'FILTERS';