fix phpcs and also add mustache.php copyright notice

This commit is contained in:
fzerorubigd 2015-01-29 22:28:38 +03:30
parent ccaa5b1d21
commit 382938b82e
No known key found for this signature in database
GPG Key ID: D6EE858AF9D2999A
2 changed files with 75 additions and 44 deletions

View File

@ -1,5 +1,8 @@
<?php
/**
* This file is part of Handlebars-php
* Base on mustache-php https://github.com/bobthecow/mustache.php
*
* Handlebars Inline Template string Loader implementation.
*
* With the InlineLoader, templates can be defined at the end of any PHP source
@ -18,18 +21,40 @@
* Goodbye, cruel {{ planet }}
*
* Templates are deliniated by lines containing only `@@ name`.
*
* @category Xamin
* @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com>
* @author Hiroyuki Toda <mai7star@gmail.com>
* @copyright 2010-2015 (c) Justin Hileman
* @copyright 2015 (c) fzerorubigd
* @license MIT <http://opensource.org/licenses/MIT>
* @version Release: @package_version@
* @link http://xamin.ir
*/
namespace Handlebars\Loader;
use Handlebars\Loader;
use Handlebars\String;
/**
* The inline loader
*
* @category Xamin
* @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com>
* @author Hiroyuki Toda <mai7star@gmail.com>
* @copyright 2010-2015 (c) Justin Hileman
* @copyright 2015 (c) fzerorubigd
* @license MIT <http://opensource.org/licenses/MIT>
* @version Release: @package_version@
* @link http://xamin.ir *
*/
class InlineLoader implements Loader
{
protected $_fileName;
protected $_offset;
protected $_templates;
protected $fileName;
protected $offset;
protected $templates;
/**
* The InlineLoader requires a filename and offset to process templates.
@ -57,43 +82,45 @@ class InlineLoader implements Loader
throw new \InvalidArgumentException('InlineLoader expects a valid file offset.');
}
$this->_fileName = $fileName;
$this->_offset = $offset;
$this->fileName = $fileName;
$this->offset = $offset;
}
/**
* Load a Template by name.
*
* @param string $name
* @param string $name template name
*
* @return string Mustache Template source
* @return string Handlebars Template source
*/
public function load($name)
{
$this->loadTemplates();
if (!array_key_exists($name, $this->_templates)) {
if (!array_key_exists($name, $this->templates)) {
throw new \InvalidArgumentException("Template {$name} not found.");
}
return $this->_templates[$name];
return $this->templates[$name];
}
/**
* Parse and load templates from the end of a source file.
*
* @return void
*/
protected function loadTemplates()
{
if (!is_null($this->_templates)) {
if (!is_null($this->templates)) {
return;
}
$this->_templates = array();
$data = file_get_contents($this->_fileName, false, null, $this->_offset);
$this->templates = array();
$data = file_get_contents($this->fileName, false, null, $this->offset);
foreach (preg_split('/^@@(?= [\w\d\.]+$)/m', $data, -1) as $chunk) {
if (trim($chunk)) {
list($name, $content) = explode("\n", $chunk, 2);
$this->_templates[trim($name)] = trim($content);
$this->templates[trim($name)] = trim($content);
}
}
}

View File

@ -16,7 +16,7 @@
*/
/**
* Class AutoloaderTest
* Class HandlebarsTest
*/
class HandlebarsTest extends \PHPUnit_Framework_TestCase
{
@ -509,11 +509,14 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($helpers->has('test'));
$this->assertFalse(isset($helpers->test));
$this->assertTrue($helpers->isEmpty());
$helpers->add('test', function() {});
$helpers->add('test', function () {
});
$this->assertCount(0, array_diff(array_keys($helpers->getAll()), array('test')));
$extraHelpers = new \Handlebars\Helpers();
$extraHelpers->add('test', function() {});
$extraHelpers->add('test2', function() {});
$extraHelpers->add('test', function () {
});
$extraHelpers->add('test2', function () {
});
$helpers->addHelpers($extraHelpers);
$this->assertTrue($helpers->has('test2'));
$this->assertEquals($helpers->test, $extraHelpers->test);
@ -1174,7 +1177,8 @@ EOM;
}
public function stringLiteralsInIfAndUnlessHelpersProvider() {
public function stringLiteralsInIfAndUnlessHelpersProvider()
{
return array(
// IfHelper
array('{{#if "truthyString"}}true{{else}}false{{/if}}', array(), "true"),