diff --git a/src/Handlebars/Context.php b/src/Handlebars/Context.php index f92d601..b364c24 100755 --- a/src/Handlebars/Context.php +++ b/src/Handlebars/Context.php @@ -9,6 +9,7 @@ * @package Handlebars * @author fzerorubigd * @author Behrooz Shabani + * @author Chris Gray * @copyright 2012 (c) ParsPooyesh Co * @copyright 2013 (c) Behrooz Shabani * @copyright 2013 (c) f0ruD A @@ -183,6 +184,7 @@ class Context * @param boolean $strict strict search? if not found then throw exception * * @throws \InvalidArgumentException in strict mode and variable not found + * @throws \RuntimeException if supplied argument is a malformed quoted string * @return mixed */ public function get($variableName, $strict = false) @@ -219,6 +221,16 @@ class Context return ''; } elseif ($variableName == '.' || $variableName == 'this') { return $current; + } elseif ($variableName == '@index') { + $current = $this->lastIndex(); + } elseif ($variableName == '@key') { + $current = $this->lastKey(); + } elseif ($variableName[0] == "'" || $variableName[0] == '"') { + if ($variableName[0] == substr($variableName, -1) && strlen($variableName) > 2) { + $current = substr($variableName, 1, strlen($variableName) -2); + } else { + throw new \RuntimeException("Malformed string: ".$variableName); + } } else { $chunks = explode('.', $variableName); foreach ($chunks as $chunk) { @@ -228,7 +240,6 @@ class Context $current = $this->_findVariableInContext($current, $chunk, $strict); } } - return $current; } diff --git a/src/Handlebars/Template.php b/src/Handlebars/Template.php index 0c77ee3..eb19fca 100755 --- a/src/Handlebars/Template.php +++ b/src/Handlebars/Template.php @@ -9,6 +9,7 @@ * @package Handlebars * @author fzerorubigd * @author Behrooz Shabani + * @author Chris Gray * @copyright 2012 (c) ParsPooyesh Co * @copyright 2013 (c) Behrooz Shabani * @license MIT @@ -408,12 +409,6 @@ class Template { $name = $current[Tokenizer::NAME]; $value = $context->get($name); - if ($name == '@index') { - return $context->lastIndex(); - } - if ($name == '@key') { - return $context->lastKey(); - } if ($escaped) { $args = $this->handlebars->getEscapeArgs(); array_unshift($args, $value); @@ -425,4 +420,20 @@ class Template return $value; } + + /** + * Break an argument string into an array of strings + * + * @param string $string Argument String as passed to a helper + * + * @return array the argument list as an array + */ + public function parseArguments($string) + { + $parts = array(); + preg_match_all('#(?