Permalink
Browse files

Merge pull request #85 from bobthecow/feature/5.2-support

Make this hotness work with PHP 5.2
  • Loading branch information...
2 parents 99ff731 + 21d2b9b commit b7a6ff243392a43be7d206cfa9a72b42eae211d0 @bobthecow committed Mar 18, 2012
Showing with 353 additions and 492 deletions.
  1. +2 −2 README.markdown
  2. +1 −1 composer.json
  3. +10 −8 src/Mustache/Autoloader.php
  4. +30 −32 src/Mustache/Compiler.php
  5. +2 −4 src/Mustache/Context.php
  6. +12 −14 src/Mustache/HelperCollection.php
  7. +1 −3 src/Mustache/Loader.php
  8. +3 −8 src/Mustache/Loader/ArrayLoader.php
  9. +10 −14 src/Mustache/Loader/FilesystemLoader.php
  10. +1 −3 src/Mustache/Loader/MutableLoader.php
  11. +1 −5 src/Mustache/Loader/StringLoader.php
  12. +53 −59 src/Mustache/Mustache.php
  13. +15 −17 src/Mustache/Parser.php
  14. +11 −13 src/Mustache/Template.php
  15. +1 −3 src/Mustache/Tokenizer.php
  16. +7 −11 test/Mustache/Test/AutoloaderTest.php
  17. +12 −17 test/Mustache/Test/CompilerTest.php
  18. +12 −16 test/Mustache/Test/ContextTest.php
  19. +4 −8 test/Mustache/Test/Functional/CallTest.php
  20. +3 −7 test/Mustache/Test/Functional/ExamplesTest.php
  21. +11 −15 test/Mustache/Test/Functional/HigherOrderSectionsTest.php
  22. +2 −6 test/Mustache/Test/Functional/MustacheInjectionTest.php
  23. +5 −10 test/Mustache/Test/Functional/MustacheSpecTest.php
  24. +14 −18 test/Mustache/Test/Functional/ObjectSectionTest.php
  25. +5 −9 test/Mustache/Test/HelperCollectionTest.php
  26. +4 −8 test/Mustache/Test/Loader/ArrayLoaderTest.php
  27. +8 −12 test/Mustache/Test/Loader/FilesystemLoaderTest.php
  28. +2 −6 test/Mustache/Test/Loader/StringLoaderTest.php
  29. +18 −51 test/Mustache/Test/MustacheTest.php
  30. +43 −48 test/Mustache/Test/ParserTest.php
  31. +8 −14 test/Mustache/Test/TemplateTest.php
  32. +37 −41 test/Mustache/Test/TokenizerTest.php
  33. +3 −3 test/bootstrap.php
  34. +1 −3 test/fixtures/autoloader/Mustache/Bar.php
  35. +1 −3 test/fixtures/autoloader/Mustache/Foo.php
View
@@ -11,7 +11,7 @@ A quick example:
```php
<?php
-$m = new Mustache;
+$m = new Mustache_Mustache;
echo $m->render('Hello {{planet}}', array('planet' => 'World!')); // "Hello World!"
```
@@ -48,7 +48,7 @@ And render it:
```php
<?php
-$m = new Mustache;
+$m = new Mustache_Mustache;
$chris = new Chris;
echo $m->render($template, $chris);
```
View
@@ -13,7 +13,7 @@
}
],
"require": {
- "php": ">=5.3.0"
+ "php": ">=5.2.4"
},
"autoload": {
"psr-0": { "Mustache": "src/" }
@@ -9,30 +9,32 @@
* file that was distributed with this source code.
*/
-namespace Mustache;
-
/**
* Mustache class autoloader.
*/
-class Autoloader {
+class Mustache_Autoloader {
private $baseDir;
/**
* Autoloader constructor.
*
- * @param string $baseDir Mustache library base directory (default: __DIR__.'/..')
+ * @param string $baseDir Mustache library base directory (default: dirname(__FILE__).'/..')
*/
public function __construct($baseDir = null) {
- $this->baseDir = rtrim($baseDir, '/') ?: __DIR__.'/..';
+ if ($baseDir === null) {
+ $this->baseDir = dirname(__FILE__).'/..';
+ } else {
+ $this->baseDir = rtrim($baseDir, '/');
+ }
}
/**
* Register a new instance as an SPL autoloader.
*
- * @param string $baseDir Mustache library base directory (default: __DIR__.'/..')
+ * @param string $baseDir Mustache library base directory (default: dirname(__FILE__).'/..')
*
- * @return \Mustache\Autoloader Registered Autoloader instance
+ * @return Mustache_Autoloader Registered Autoloader instance
*/
static public function register($baseDir = null) {
$loader = new self($baseDir);
@@ -55,7 +57,7 @@ public function autoload($class) {
return;
}
- $file = sprintf('%s/%s.php', $this->baseDir, str_replace('\\', '/', $class));
+ $file = sprintf('%s/%s.php', $this->baseDir, str_replace('_', '/', $class));
if (is_file($file)) {
require $file;
}
View
@@ -9,14 +9,12 @@
* file that was distributed with this source code.
*/
-namespace Mustache;
-
/**
* Mustache Compiler class.
*
* This class is responsible for turning a Mustache token parse tree into normal PHP source code.
*/
-class Compiler {
+class Mustache_Compiler {
private $sections;
private $source;
@@ -46,7 +44,7 @@ public function compile($source, array $tree, $name, $customEscape = false, $cha
/**
* Helper function for walking the Mustache token parse tree.
*
- * @throws \InvalidArgumentException upon encountering unknown token types.
+ * @throws InvalidArgumentException upon encountering unknown token types.
*
* @param array $tree Parse tree of Mustache tokens
* @param int $level (default: 0)
@@ -57,46 +55,46 @@ private function walk(array $tree, $level = 0) {
$code = '';
$level++;
foreach ($tree as $node) {
- switch (is_string($node) ? 'text' : $node[Tokenizer::TYPE]) {
- case Tokenizer::T_SECTION:
+ switch (is_string($node) ? 'text' : $node[Mustache_Tokenizer::TYPE]) {
+ case Mustache_Tokenizer::T_SECTION:
$code .= $this->section(
- $node[Tokenizer::NODES],
- $node[Tokenizer::NAME],
- $node[Tokenizer::INDEX],
- $node[Tokenizer::END],
- $node[Tokenizer::OTAG],
- $node[Tokenizer::CTAG],
+ $node[Mustache_Tokenizer::NODES],
+ $node[Mustache_Tokenizer::NAME],
+ $node[Mustache_Tokenizer::INDEX],
+ $node[Mustache_Tokenizer::END],
+ $node[Mustache_Tokenizer::OTAG],
+ $node[Mustache_Tokenizer::CTAG],
$level
);
break;
- case Tokenizer::T_INVERTED:
+ case Mustache_Tokenizer::T_INVERTED:
$code .= $this->invertedSection(
- $node[Tokenizer::NODES],
- $node[Tokenizer::NAME],
+ $node[Mustache_Tokenizer::NODES],
+ $node[Mustache_Tokenizer::NAME],
$level
);
break;
- case Tokenizer::T_PARTIAL:
- case Tokenizer::T_PARTIAL_2:
+ case Mustache_Tokenizer::T_PARTIAL:
+ case Mustache_Tokenizer::T_PARTIAL_2:
$code .= $this->partial(
- $node[Tokenizer::NAME],
- isset($node[Tokenizer::INDENT]) ? $node[Tokenizer::INDENT] : '',
+ $node[Mustache_Tokenizer::NAME],
+ isset($node[Mustache_Tokenizer::INDENT]) ? $node[Mustache_Tokenizer::INDENT] : '',
$level
);
break;
- case Tokenizer::T_UNESCAPED:
- case Tokenizer::T_UNESCAPED_2:
- $code .= $this->variable($node[Tokenizer::NAME], false, $level);
+ case Mustache_Tokenizer::T_UNESCAPED:
+ case Mustache_Tokenizer::T_UNESCAPED_2:
+ $code .= $this->variable($node[Mustache_Tokenizer::NAME], false, $level);
break;
- case Tokenizer::T_COMMENT:
+ case Mustache_Tokenizer::T_COMMENT:
break;
- case Tokenizer::T_ESCAPED:
- $code .= $this->variable($node[Tokenizer::NAME], true, $level);
+ case Mustache_Tokenizer::T_ESCAPED:
+ $code .= $this->variable($node[Mustache_Tokenizer::NAME], true, $level);
break;
@@ -105,7 +103,7 @@ private function walk(array $tree, $level = 0) {
break;
default:
- throw new \InvalidArgumentException('Unknown node type: '.json_encode($node));
+ throw new InvalidArgumentException('Unknown node type: '.json_encode($node));
}
}
@@ -114,8 +112,8 @@ private function walk(array $tree, $level = 0) {
const KLASS = '<?php
- class %s extends \Mustache\Template {
- public function renderInternal(\Mustache\Context $context, $indent = \'\', $escape = false) {
+ class %s extends Mustache_Template {
+ public function renderInternal(Mustache_Context $context, $indent = \'\', $escape = false) {
$buffer = \'\';
%s
@@ -149,7 +147,7 @@ private function writeCode($tree, $name) {
';
const SECTION = '
- private function section%s(\Mustache\Context $context, $indent, $value) {
+ private function section%s(Mustache_Context $context, $indent, $value) {
$buffer = \'\';
if (!is_string($value) && is_callable($value)) {
$source = %s;
@@ -329,9 +327,9 @@ private function getEscape($value = '$value') {
*
* The return value will be one of `find`, `findDot` or `last`.
*
- * @see \Mustache\Context::find
- * @see \Mustache\Context::findDot
- * @see \Mustache\Context::last
+ * @see Mustache_Context::find
+ * @see Mustache_Context::findDot
+ * @see Mustache_Context::last
*
* @param string $id Variable name
*
View
@@ -9,12 +9,10 @@
* file that was distributed with this source code.
*/
-namespace Mustache;
-
/**
* Mustache Template rendering Context.
*/
-class Context {
+class Mustache_Context {
private $stack = array();
/**
@@ -118,7 +116,7 @@ public function findDot($id) {
/**
* Helper function to find a variable in the Context stack.
*
- * @see \Mustache\Context::find
+ * @see Mustache_Context::find
*
* @param string $id Variable name
* @param array $stack Context stack
@@ -9,27 +9,25 @@
* file that was distributed with this source code.
*/
-namespace Mustache;
-
/**
* A collection of helpers for a Mustache instance.
*/
-class HelperCollection {
+class Mustache_HelperCollection {
private $helpers = array();
/**
* Helper Collection constructor.
*
- * Optionally accepts an array (or \Traversable) of `$name => $helper` pairs.
+ * Optionally accepts an array (or Traversable) of `$name => $helper` pairs.
*
- * @throws \InvalidArgumentException if the $helpers argument isn't an array or \Traversable
+ * @throws InvalidArgumentException if the $helpers argument isn't an array or Traversable
*
* @param array|Traversable $helpers (default: null)
*/
public function __construct($helpers = null) {
if ($helpers !== null) {
- if (!is_array($helpers) && !$helpers instanceof \Traversable) {
- throw new \InvalidArgumentException('HelperCollection constructor expects an array of helpers');
+ if (!is_array($helpers) && !$helpers instanceof Traversable) {
+ throw new InvalidArgumentException('HelperCollection constructor expects an array of helpers');
}
foreach ($helpers as $name => $helper) {
@@ -41,7 +39,7 @@ public function __construct($helpers = null) {
/**
* Magic mutator.
*
- * @see \Mustache\HelperCollection::add
+ * @see Mustache_HelperCollection::add
*
* @param string $name
* @param mixed $helper
@@ -63,7 +61,7 @@ public function add($name, $helper) {
/**
* Magic accessor.
*
- * @see \Mustache\HelperCollection::get
+ * @see Mustache_HelperCollection::get
*
* @param string $name
*
@@ -82,7 +80,7 @@ public function __get($name) {
*/
public function get($name) {
if (!$this->has($name)) {
- throw new \InvalidArgumentException('Unknown helper: '.$name);
+ throw new InvalidArgumentException('Unknown helper: '.$name);
}
return $this->helpers[$name];
@@ -91,7 +89,7 @@ public function get($name) {
/**
* Magic isset().
*
- * @see \Mustache\HelperCollection::has
+ * @see Mustache_HelperCollection::has
*
* @param string $name
*
@@ -115,7 +113,7 @@ public function has($name) {
/**
* Magic unset().
*
- * @see \Mustache\HelperCollection::remove
+ * @see Mustache_HelperCollection::remove
*
* @param string $name
*/
@@ -126,13 +124,13 @@ public function __unset($name) {
/**
* Check whether a given helper is present in the collection.
*
- * @throws \InvalidArgumentException if the requested helper is not present.
+ * @throws InvalidArgumentException if the requested helper is not present.
*
* @param string $name
*/
public function remove($name) {
if (!$this->has($name)) {
- throw new \InvalidArgumentException('Unknown helper: '.$name);
+ throw new InvalidArgumentException('Unknown helper: '.$name);
}
unset($this->helpers[$name]);
View
@@ -9,12 +9,10 @@
* file that was distributed with this source code.
*/
-namespace Mustache;
-
/**
* Mustache Template Loader interface.
*/
-interface Loader {
+interface Mustache_Loader {
/**
* Load a Template by name.
@@ -9,11 +9,6 @@
* file that was distributed with this source code.
*/
-namespace Mustache\Loader;
-
-use Mustache\Loader;
-use Mustache\Loader\MutableLoader;
-
/**
* Mustache Template array Loader implementation.
*
@@ -26,13 +21,13 @@
*
* $tpl = $loader->load('foo'); // '{{ bar }}'
*
- * The ArrayLoader is used internally as a partials loader by \Mustache\Mustache instance when an array of partials
+ * The ArrayLoader is used internally as a partials loader by Mustache_Mustache instance when an array of partials
* is set. It can also be used as a quick-and-dirty Template loader.
*
* @implements Loader
* @implements MutableLoader
*/
-class ArrayLoader implements Loader, MutableLoader {
+class Mustache_Loader_ArrayLoader implements Mustache_Loader, Mustache_Loader_MutableLoader {
/**
* ArrayLoader constructor.
@@ -52,7 +47,7 @@ public function __construct(array $templates = array()) {
*/
public function load($name) {
if (!isset($this->templates[$name])) {
- throw new \InvalidArgumentException('Template '.$name.' not found.');
+ throw new InvalidArgumentException('Template '.$name.' not found.');
}
return $this->templates[$name];
Oops, something went wrong.

0 comments on commit b7a6ff2

Please sign in to comment.