Another cleanup

This commit is contained in:
fzerorubigd 2013-11-08 18:48:19 +03:30
parent 287a8da70c
commit 8938fdc5c3
No known key found for this signature in database
GPG Key ID: D6EE858AF9D2999A
10 changed files with 106 additions and 82 deletions

View File

@ -39,7 +39,7 @@ class APC implements Cache
*
* @param string $name Cache id
*
* @return data on hit, boolean false on cache not found
* @return mixed data on hit, boolean false on cache not found
*/
public function get($name)
{

View File

@ -44,16 +44,19 @@ class Disk implements Cache
* @param string $path Filesystem path to the disk cache location
* @param string $prefix optional file prefix, defaults to empty string
* @param string $suffix optional file extension, defaults to empty string
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
*/
public function __construct($path, $prefix = '', $suffix = '')
{
if (empty($path)) {
throw new InvalidArgumentException('Must specify disk cache path');
throw new \InvalidArgumentException('Must specify disk cache path');
} elseif (!is_dir($path)) {
@mkdir($path, 0777, true);
if (!is_dir($path)) {
throw new RuntimeException('Could not create cache file path');
throw new \RuntimeException('Could not create cache file path');
}
}
@ -82,7 +85,7 @@ class Disk implements Cache
*
* @param string $name Cache id
*
* @return data on hit, boolean false on cache not found
* @return mixed data on hit, boolean false on cache not found
*/
public function get($name)
{

View File

@ -40,7 +40,7 @@ class Dummy implements Cache
*
* @param string $name Cache id
*
* @return data on hit, boolean false on cache not found
* @return mixed data on hit, boolean false on cache not found
*/
public function get($name)
{

View File

@ -169,6 +169,7 @@ class Context
{
$value = $this->get($variableName);
$this->push($value);
return $value;
}
@ -198,6 +199,7 @@ class Context
'can not find variable in context'
);
}
return '';
}
end($this->stack);
@ -212,6 +214,7 @@ class Context
'can not find variable in context'
);
}
return '';
} elseif ($variableName == '.' || $variableName == 'this') {
return $current;
@ -224,6 +227,7 @@ class Context
$current = $this->_findVariableInContext($current, $chunk, $strict);
}
}
return $current;
}
@ -257,6 +261,7 @@ class Context
} elseif ($strict) {
throw new \InvalidArgumentException('can not find variable in context');
}
return $value;
}

View File

@ -42,13 +42,14 @@ class Handlebars
*
* @param array $options see __construct's options parameter
*
* @return void
* @return Handlebars
*/
public static function factory($options = array())
{
if (self::$_instance === false) {
self::$_instance = new Handlebars($options);
}
return self::$_instance;
}
@ -193,6 +194,7 @@ class Handlebars
if (!isset($this->_helpers)) {
$this->_helpers = new Helpers();
}
return $this->_helpers;
}
@ -218,7 +220,7 @@ class Handlebars
*/
public function getHelper($name)
{
return $this->getHelpers()->get($name);
return $this->getHelpers()->__get($name);
}
/**
@ -267,6 +269,7 @@ class Handlebars
if (!isset($this->_loader)) {
$this->_loader = new StringLoader();
}
return $this->_loader;
}
@ -292,6 +295,7 @@ class Handlebars
if (!isset($this->_partialsLoader)) {
$this->_partialsLoader = new StringLoader();
}
return $this->_partialsLoader;
}
@ -317,8 +321,10 @@ class Handlebars
if (!isset($this->_cache)) {
$this->_cache = new Dummy();
}
return $this->_cache;
}
/**
* Get current escape function
*
@ -330,7 +336,7 @@ class Handlebars
}
/**
* Set current escpae function
* Set current escape function
*
* @param callable $escape function
*
@ -358,7 +364,7 @@ class Handlebars
}
/**
* Set current escpae function
* Set current escape function
*
* @param array $escapeArgs arguments to pass as extra arg to function
*
@ -401,6 +407,7 @@ class Handlebars
return $this->_tokenizer;
}
/**
* Set the Handlebars Parser instance.
*
@ -429,6 +436,7 @@ class Handlebars
return $this->_parser;
}
/**
* Load a template by name with current template loader
*
@ -440,6 +448,7 @@ class Handlebars
{
$source = $this->getLoader()->load($name);
$tree = $this->_tokenize($source);
return new Template($this, $tree, $source);
}
@ -457,6 +466,7 @@ class Handlebars
}
$source = $this->getPartialsLoader()->load($name);
$tree = $this->_tokenize($source);
return new Template($this, $tree, $source);
}
@ -497,6 +507,7 @@ class Handlebars
public function loadString($source)
{
$tree = $this->_tokenize($source);
return new Template($this, $tree, $source);
}
@ -516,6 +527,7 @@ class Handlebars
$tree = $this->getParser()->parse($tokens);
$this->getCache()->set($hash, $tree);
}
return $tree;
}

View File

@ -31,7 +31,6 @@ use Handlebars\String;
* @license MIT <http://opensource.org/licenses/MIT>
* @version Release: @package_version@
* @link http://xamin.ir *
* @implements Loader
*/
class FilesystemLoader implements Loader
@ -54,7 +53,7 @@ class FilesystemLoader implements Loader
* @param string|array $baseDirs A path contain template files or array of paths
* @param array $options Array of Loader options (default: array())
*
* @throws RuntimeException if $baseDir does not exist.
* @throws \RuntimeException if $baseDir does not exist.
*/
public function __construct($baseDirs, array $options = array())
{
@ -101,6 +100,7 @@ class FilesystemLoader implements Loader
if (!isset($this->_templates[$name])) {
$this->_templates[$name] = $this->loadFile($name);
}
return new String($this->_templates[$name]);
}
@ -109,8 +109,8 @@ class FilesystemLoader implements Loader
*
* @param string $name template name
*
* @throws \InvalidArgumentException if a template file is not found.
* @return string Handlebars Template source
* @throws InvalidArgumentException if a template file is not found.
*/
protected function loadFile($name)
{
@ -149,11 +149,11 @@ class FilesystemLoader implements Loader
$fileName .= $this->_extension;
}
if (file_exists($fileName)) {
break;
}
$fileName = false;
}
return $fileName;
}
}
return false;
}
}

View File

@ -30,7 +30,6 @@ use Handlebars\String;
* @license MIT <http://opensource.org/licenses/MIT>
* @version Release: @package_version@
* @link http://xamin.ir *
* @implements Loader
*/
class StringLoader implements Loader

View File

@ -117,6 +117,7 @@ class Template
public function getStopToken()
{
$topStack = end($this->_stack);
return $topStack[2];
}
@ -192,6 +193,7 @@ class Template
$newStack[2] = false; //No stop token from now on
array_push($this->_stack, $newStack);
}
return $buffer;
}
@ -227,6 +229,7 @@ class Template
$newStack[2] = false;
array_push($this->_stack, $newStack);
}
return '';
}
@ -293,6 +296,7 @@ class Template
} elseif ($sectionVar) {
$buffer = $this->render($context);
}
return $buffer;
} else {
throw new \RuntimeException(
@ -367,6 +371,7 @@ class Template
array_values($args)
);
}
return $value;
}
}