Skip to content

Commit

Permalink
Merge branch 'release/2.12.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Jul 11, 2017
2 parents a3f6d55 + 994abca commit fe8fe72
Show file tree
Hide file tree
Showing 111 changed files with 712 additions and 160 deletions.
26 changes: 16 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
language: php

php:
- 5.2
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
sudo: false

matrix:
include:
- php: 5.2
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: 7.1
- php: hhvm
dist: trusty

script:
- phpunit
- '[[ "$TRAVIS_PHP_VERSION" = 5.2* ]] && phpunit || vendor/bin/phpunit --verbose'

sudo: false
install:
- '[[ "$TRAVIS_PHP_VERSION" = 5.2* ]] || composer install'
18 changes: 16 additions & 2 deletions src/Mustache/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of Mustache.php.
*
* (c) 2010-2016 Justin Hileman
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -16,6 +16,14 @@ class Mustache_Autoloader
{
private $baseDir;

/**
* An array where the key is the baseDir and the key is an instance of this
* class.
*
* @var array
*/
private static $instances;

/**
* Autoloader constructor.
*
Expand Down Expand Up @@ -45,7 +53,13 @@ public function __construct($baseDir = null)
*/
public static function register($baseDir = null)
{
$loader = new self($baseDir);
$key = $baseDir ? $baseDir : 0;

if (!isset(self::$instances[$key])) {
self::$instances[$key] = new self($baseDir);
}

$loader = self::$instances[$key];
spl_autoload_register(array($loader, 'autoload'));

return $loader;
Expand Down
2 changes: 1 addition & 1 deletion src/Mustache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of Mustache.php.
*
* (c) 2010-2016 Justin Hileman
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Mustache/Cache/AbstractCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of Mustache.php.
*
* (c) 2010-2016 Justin Hileman
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
8 changes: 7 additions & 1 deletion src/Mustache/Cache/FilesystemCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of Mustache.php.
*
* (c) 2010-2016 Justin Hileman
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down Expand Up @@ -108,9 +108,11 @@ private function buildDirectoryForFilename($fileName)
);

@mkdir($dirName, 0777, true);
// @codeCoverageIgnoreStart
if (!is_dir($dirName)) {
throw new Mustache_Exception_RuntimeException(sprintf('Failed to create cache directory "%s".', $dirName));
}
// @codeCoverageIgnoreEnd
}

return $dirName;
Expand Down Expand Up @@ -143,13 +145,17 @@ private function writeFile($fileName, $value)
return;
}

// @codeCoverageIgnoreStart
$this->log(
Mustache_Logger::ERROR,
'Unable to rename Mustache temp cache file: "{tempName}" -> "{fileName}"',
array('tempName' => $tempFile, 'fileName' => $fileName)
);
// @codeCoverageIgnoreEnd
}

// @codeCoverageIgnoreStart
throw new Mustache_Exception_RuntimeException(sprintf('Failed to write cache file "%s".', $fileName));
// @codeCoverageIgnoreEnd
}
}
2 changes: 1 addition & 1 deletion src/Mustache/Cache/NoopCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of Mustache.php.
*
* (c) 2010-2016 Justin Hileman
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
59 changes: 32 additions & 27 deletions src/Mustache/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of Mustache.php.
*
* (c) 2010-2016 Justin Hileman
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down Expand Up @@ -191,7 +191,6 @@ public function renderInternal(Mustache_Context $context, $indent = \'\')
{
$this->lambdaHelper = new Mustache_LambdaHelper($this->mustache, $context);
$buffer = \'\';
$blocksContext = array();
%s
return $buffer;
Expand All @@ -207,7 +206,6 @@ class %s extends Mustache_Template
public function renderInternal(Mustache_Context $context, $indent = \'\')
{
$buffer = \'\';
$blocksContext = array();
%s
return $buffer;
Expand Down Expand Up @@ -240,10 +238,11 @@ private function writeCode($tree, $name)
$blockFunction = $context->findInBlock(%s);
if (is_callable($blockFunction)) {
$buffer .= call_user_func($blockFunction, $context);
} else {%s
}
%s}
';

const BLOCK_VAR_ELSE = '} else {%s';

/**
* Generate Mustache Template inheritance block variable PHP source.
*
Expand All @@ -261,10 +260,15 @@ private function blockVar($nodes, $id, $start, $end, $otag, $ctag, $level)
{
$id = var_export($id, true);

return sprintf($this->prepare(self::BLOCK_VAR, $level), $id, $this->walk($nodes, $level));
$else = $this->walk($nodes, $level);
if ($else !== '') {
$else = sprintf($this->prepare(self::BLOCK_VAR_ELSE, $level + 1, false, true), $else);
}

return sprintf($this->prepare(self::BLOCK_VAR, $level), $id, $else);
}

const BLOCK_ARG = '$blocksContext[%s] = array($this, \'block%s\');';
const BLOCK_ARG = '%s => array($this, \'block%s\'),';

/**
* Generate Mustache Template inheritance block argument PHP source.
Expand All @@ -285,14 +289,13 @@ private function blockArg($nodes, $id, $start, $end, $otag, $ctag, $level)
$keystr = var_export($key, true);
$id = var_export($id, true);

return sprintf($this->prepare(self::BLOCK_ARG, 1), $id, $key);
return sprintf($this->prepare(self::BLOCK_ARG, $level), $id, $key);
}

const BLOCK_FUNCTION = '
public function block%s($context)
{
$indent = $buffer = \'\';
$blocksContext = array();%s
$indent = $buffer = \'\';%s
return $buffer;
}
Expand Down Expand Up @@ -327,7 +330,6 @@ private function block($nodes)
private function section%s(Mustache_Context $context, $indent, $value)
{
$buffer = \'\';
$blocksContext = array();
if (%s) {
$source = %s;
Expand Down Expand Up @@ -363,11 +365,10 @@ private function section%s(Mustache_Context $context, $indent, $value)
* @param string $otag Current Mustache opening tag
* @param string $ctag Current Mustache closing tag
* @param int $level
* @param bool $arg (default: false)
*
* @return string Generated section PHP source code
*/
private function section($nodes, $id, $filters, $start, $end, $otag, $ctag, $level, $arg = false)
private function section($nodes, $id, $filters, $start, $end, $otag, $ctag, $level)
{
$source = var_export(substr($this->source, $start, $end - $start), true);
$callable = $this->getCallable();
Expand All @@ -387,15 +388,11 @@ private function section($nodes, $id, $filters, $start, $end, $otag, $ctag, $lev
$this->sections[$key] = sprintf($this->prepare(self::SECTION), $key, $callable, $source, $helper, $delims, $this->walk($nodes, 2));
}

if ($arg === true) {
return $key;
} else {
$method = $this->getFindMethod($id);
$id = var_export($id, true);
$filters = $this->getFilters($filters, $level);
$method = $this->getFindMethod($id);
$id = var_export($id, true);
$filters = $this->getFilters($filters, $level);

return sprintf($this->prepare(self::SECTION_CALL, $level), $id, $method, $id, $filters, $key);
}
return sprintf($this->prepare(self::SECTION_CALL, $level), $id, $method, $id, $filters, $key);
}

const INVERTED_SECTION = '
Expand Down Expand Up @@ -457,15 +454,20 @@ private function partial($id, $indent, $level)
}

const PARENT = '
%s
if ($parent = $this->mustache->loadPartial(%s)) {
$context->pushBlockContext($blocksContext);
$context->pushBlockContext(array(%s
));
$buffer .= $parent->renderInternal($context, $indent);
$context->popBlockContext();
}
';

const PARENT_NO_CONTEXT = '
if ($parent = $this->mustache->loadPartial(%s)) {
$buffer .= $parent->renderInternal($context, $indent);
}
';

/**
* Generate Mustache Template inheritance parent call PHP source.
*
Expand All @@ -480,11 +482,14 @@ private function parent($id, $indent, array $children, $level)
{
$realChildren = array_filter($children, array(__CLASS__, 'onlyBlockArgs'));

if (empty($realChildren)) {
return sprintf($this->prepare(self::PARENT_NO_CONTEXT, $level), var_export($id, true));
}

return sprintf(
$this->prepare(self::PARENT, $level),
$this->walk($realChildren, $level),
var_export($id, true),
var_export($indent, true)
$this->walk($realChildren, $level + 1)
);
}

Expand Down Expand Up @@ -621,7 +626,7 @@ private function getEscape($value = '$value')
/**
* Select the appropriate Context `find` method for a given $id.
*
* The return value will be one of `find`, `findDot` or `last`.
* The return value will be one of `find`, `findDot`, `findAnchoredDot` or `last`.
*
* @see Mustache_Context::find
* @see Mustache_Context::findDot
Expand Down
2 changes: 1 addition & 1 deletion src/Mustache/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of Mustache.php.
*
* (c) 2010-2016 Justin Hileman
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
Loading

0 comments on commit fe8fe72

Please sign in to comment.