Skip to content

Commit

Permalink
Merge branch 'release/2.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Jun 20, 2014
2 parents 43dc945 + b1e0a6d commit 1430ca8
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 60 deletions.
18 changes: 9 additions & 9 deletions bin/build_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
* containing all Mustache library classes. This file can then be included in
* your project, rather than requiring the Mustache Autoloader.
*/
$baseDir = realpath(dirname(__FILE__).'/..');
$baseDir = realpath(dirname(__FILE__) . '/..');

require $baseDir.'/src/Mustache/Autoloader.php';
require $baseDir . '/src/Mustache/Autoloader.php';
Mustache_Autoloader::register();

// delete the old file
$file = $baseDir.'/mustache.php';
$file = $baseDir . '/mustache.php';
if (file_exists($file)) {
unlink($file);
}
Expand Down Expand Up @@ -77,7 +77,7 @@
*/
class SymfonyClassCollectionLoader
{
static private $loaded;
private static $loaded;

const HEADER = <<<EOS
<?php
Expand All @@ -102,7 +102,7 @@ class SymfonyClassCollectionLoader
*
* @throws InvalidArgumentException When class can't be loaded
*/
static public function load(array $classes, $cacheDir, $name, $extension = '.php')
public static function load(array $classes, $cacheDir, $name, $extension = '.php')
{
// each $name can only be loaded once per PHP process
if (isset(self::$loaded[$name])) {
Expand All @@ -121,9 +121,9 @@ static public function load(array $classes, $cacheDir, $name, $extension = '.php
$content .= preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($r->getFileName()));
}

$cache = $cacheDir.'/'.$name.$extension;
$cache = $cacheDir . '/' . $name . $extension;
$header = sprintf(self::HEADER, strftime('%Y'));
self::writeCacheFile($cache, $header . substr(self::stripComments('<?php '.$content), 5));
self::writeCacheFile($cache, $header . substr(self::stripComments('<?php ' . $content), 5));
}

/**
Expand All @@ -134,7 +134,7 @@ static public function load(array $classes, $cacheDir, $name, $extension = '.php
*
* @throws RuntimeException when a cache file cannot be written
*/
static private function writeCacheFile($file, $content)
private static function writeCacheFile($file, $content)
{
$tmpFile = tempnam(dirname($file), basename($file));
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
Expand All @@ -156,7 +156,7 @@ static private function writeCacheFile($file, $content)
*
* @return string The PHP string with the comments removed
*/
static private function stripComments($source)
private static function stripComments($source)
{
if (!function_exists('token_get_all')) {
return $source;
Expand Down
31 changes: 18 additions & 13 deletions bin/create_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

define('EXAMPLE_PATH', realpath(dirname(__FILE__) . '/../test/fixtures/examples'));


/**
* transform a string to lowercase using underlines.
* Examples:
Expand All @@ -37,7 +36,8 @@
* @access public
* @return string
*/
function getLowerCaseName($name) {
function getLowerCaseName($name)
{
return preg_replace_callback("/([A-Z])/", create_function (
'$match',
'return "_" . strtolower($match[1]);'
Expand All @@ -56,23 +56,25 @@ function getLowerCaseName($name) {
* @access public
* @return string
*/
function getUpperCaseName($name) {
function getUpperCaseName($name)
{
return preg_replace_callback("/_([a-z])/", create_function (
'$match',
'return strtoupper($match{1});'
), ucfirst($name));
}


/**
* return the given value and echo it out appending "\n"
*
* @param mixed $value
* @access public
* @return mixed
*/
function out($value) {
function out($value)
{
echo $value . "\n";

return $value;
}

Expand All @@ -88,7 +90,8 @@ function out($value) {
* @access public
* @return string
*/
function buildPath($directory, $filename = null, $extension = null) {
function buildPath($directory, $filename = null, $extension = null)
{
return out(EXAMPLE_PATH . '/' . $directory.
($extension !== null && $filename !== null ? '/' . $filename. "." . $extension : ""));
}
Expand All @@ -101,8 +104,9 @@ function buildPath($directory, $filename = null, $extension = null) {
* @access public
* @return void
*/
function createDirectory($directory) {
if(!@mkdir(buildPath($directory))) {
function createDirectory($directory)
{
if (!@mkdir(buildPath($directory))) {
die("FAILED to create directory\n");
}
}
Expand All @@ -118,17 +122,17 @@ function createDirectory($directory) {
* @access public
* @return void
*/
function createFile($directory, $filename, $extension, $content = "") {
function createFile($directory, $filename, $extension, $content = "")
{
$handle = @fopen(buildPath($directory, $filename, $extension), "w");
if($handle) {
if ($handle) {
fwrite($handle, $content);
fclose($handle);
} else {
die("FAILED to create file\n");
}
}


/**
* routine to create the example directory and 3 files
*
Expand All @@ -142,7 +146,8 @@ function createFile($directory, $filename, $extension, $content = "") {
* @access public
* @return void
*/
function main($example_name) {
function main($example_name)
{
$lowercase = getLowerCaseName($example_name);
$uppercase = getUpperCaseName($example_name);
createDirectory($lowercase);
Expand All @@ -160,7 +165,7 @@ class {$uppercase} {
}

// check if enougth arguments are given
if(count($argv) > 1) {
if (count($argv) > 1) {
// get the name of the example
$example_name = $argv[1];

Expand Down
1 change: 0 additions & 1 deletion src/Mustache/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
class Mustache_Autoloader
{

private $baseDir;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Mustache/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
class Mustache_Compiler
{

private $sections;
private $source;
private $indentNextLine;
Expand Down
3 changes: 3 additions & 0 deletions src/Mustache/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ private function findVariableInStack($id, array $stack)
{
for ($i = count($stack) - 1; $i >= 0; $i--) {
if (is_object($stack[$i]) && !($stack[$i] instanceof Closure)) {

// Note that is_callable() *will not work here*
// See https://github.com/bobthecow/mustache.php/wiki/Magic-Methods
if (method_exists($stack[$i], $id)) {
return $stack[$i]->$id();
} elseif (isset($stack[$i]->$id)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Mustache/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class Mustache_Engine
{
const VERSION = '2.6.0';
const VERSION = '2.6.1';
const SPEC_VERSION = '1.1.2';

const PRAGMA_FILTERS = 'FILTERS';
Expand Down Expand Up @@ -213,7 +213,7 @@ public function getEscape()
*/
public function getEntityFlags()
{
return $this->entityFlags;
return $this->entityFlags;
}

/**
Expand Down
18 changes: 10 additions & 8 deletions src/Mustache/HelperCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ class Mustache_HelperCollection
*/
public function __construct($helpers = null)
{
if ($helpers !== null) {
if (!is_array($helpers) && !$helpers instanceof Traversable) {
throw new Mustache_Exception_InvalidArgumentException('HelperCollection constructor expects an array of helpers');
}

foreach ($helpers as $name => $helper) {
$this->add($name, $helper);
}
if ($helpers === null) {
return;
}

if (!is_array($helpers) && !$helpers instanceof Traversable) {
throw new Mustache_Exception_InvalidArgumentException('HelperCollection constructor expects an array of helpers');
}

foreach ($helpers as $name => $helper) {
$this->add($name, $helper);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/Mustache/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
interface Mustache_Loader
{

/**
* Load a Template by name.
*
Expand Down
1 change: 0 additions & 1 deletion src/Mustache/Loader/MutableLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
interface Mustache_Loader_MutableLoader
{

/**
* Set an associative array of Template sources for this loader.
*
Expand Down
1 change: 0 additions & 1 deletion src/Mustache/Loader/StringLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
class Mustache_Loader_StringLoader implements Mustache_Loader
{

/**
* Load a Template by source.
*
Expand Down
1 change: 0 additions & 1 deletion src/Mustache/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
abstract class Mustache_Template
{

/**
* @var Mustache_Engine
*/
Expand Down
47 changes: 34 additions & 13 deletions src/Mustache/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
class Mustache_Tokenizer
{

// Finite state machine states
const IN_TEXT = 0;
const IN_TAG_TYPE = 1;
Expand Down Expand Up @@ -85,6 +84,8 @@ class Mustache_Tokenizer
/**
* Scan and tokenize template source.
*
* @throws Mustache_Exception_SyntaxException when mismatched section tags are encountered.
*
* @param string $text Mustache template source to tokenize
* @param string $delimiters Optionally, pass initial opening and closing delimiters (default: null)
*
Expand Down Expand Up @@ -117,7 +118,7 @@ public function scan($text, $delimiters = null)
} else {
$char = $text[$i];
$this->buffer .= $char;
if ($char == "\n") {
if ($char === "\n") {
$this->flushBuffer();
$this->line++;
}
Expand Down Expand Up @@ -152,29 +153,49 @@ public function scan($text, $delimiters = null)

default:
if ($this->tagChange($this->ctag, $this->ctagLen, $text, $i)) {
$this->tokens[] = array(
$token = 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 - $this->otagLen : $i + $this->ctagLen
self::INDEX => ($this->tagType === self::T_END_SECTION) ? $this->seenTag - $this->otagLen : $i + $this->ctagLen
);

$this->buffer = '';
$i += $this->ctagLen - 1;
$this->state = self::IN_TEXT;
if ($this->tagType == self::T_UNESCAPED) {
if ($this->ctag == '}}') {
$i++;
if ($this->tagType === self::T_UNESCAPED) {
// Clean up `{{{ tripleStache }}}` style tokens.
if ($this->ctag === '}}') {
if (($i + 2 < $len) && $text[$i + 2] === '}') {
$i++;
} else {
$msg = sprintf(
'Mismatched tag delimiters: %s on line %d',
$token[self::NAME],
$token[self::LINE]
);

throw new Mustache_Exception_SyntaxException($msg, $token);
}
} else {
// Clean up `{{{ tripleStache }}}` style tokens.
$lastName = $this->tokens[count($this->tokens) - 1][self::NAME];
$lastName = $token[self::NAME];
if (substr($lastName, -1) === '}') {
$this->tokens[count($this->tokens) - 1][self::NAME] = trim(substr($lastName, 0, -1));
$token[self::NAME] = trim(substr($lastName, 0, -1));
} else {
$msg = sprintf(
'Mismatched tag delimiters: %s on line %d',
$token[self::NAME],
$token[self::LINE]
);

throw new Mustache_Exception_SyntaxException($msg, $token);
}
}
}

$this->buffer = '';
$i += $this->ctagLen - 1;
$this->state = self::IN_TEXT;
$this->tokens[] = $token;
} else {
$this->buffer .= $text[$i];
}
Expand Down
4 changes: 2 additions & 2 deletions test/Mustache/Test/Cache/FilesystemCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Mustache_Test_Cache_FilesystemCacheTest extends Mustache_Test_FunctionalTe
public function testCacheGetNone()
{
$key = 'some key';
$cache = new Mustache_Cache_FilesystemCache(self::$tempDir);;
$cache = new Mustache_Cache_FilesystemCache(self::$tempDir);
$loaded = $cache->load($key);

$this->assertFalse($loaded);
Expand All @@ -27,7 +27,7 @@ public function testCachePut()
{
$key = 'some key';
$value = '<?php /* some value */';
$cache = new Mustache_Cache_FilesystemCache(self::$tempDir);;
$cache = new Mustache_Cache_FilesystemCache(self::$tempDir);
$cache->cache($key, $value);
$loaded = $cache->load($key);

Expand Down
4 changes: 2 additions & 2 deletions test/Mustache/Test/FiveThree/Functional/FiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function singleFilterData()
array(
'{{% FILTERS }}{{ date | longdate }}',
$helpers,
(object) array('date' => new DateTime('1/1/2000')),
(object) array('date' => new DateTime('1/1/2000', new DateTimeZone("UTC"))),
'2000-01-01 12:01:00'
),

Expand All @@ -72,7 +72,7 @@ public function testChainedFilters()
});

$foo = new \StdClass;
$foo->date = new DateTime('1/1/2000');
$foo->date = new DateTime('1/1/2000', new DateTimeZone("UTC"));

$this->assertEquals('[[2000-01-01 12:01:00]]', $tpl->render($foo));
}
Expand Down
Loading

0 comments on commit 1430ca8

Please sign in to comment.