diff --git a/Ruler.php b/Ruler.php index b66eeed..ca15ce9 100644 --- a/Ruler.php +++ b/Ruler.php @@ -139,8 +139,12 @@ public function assert ( $rule, Context $context = null ) { * @throw \Hoa\Ruler\Exception */ public static function interprete ( $rule ) { - - return static::getInterpreter()->visit( + + $interpreter = static::getInterpreter(); + //clear context keys + $interpreter->clearContextKeys(); + + return $interpreter->visit( static::getCompiler()->parse($rule) ); } @@ -225,6 +229,17 @@ public static function getCompiler ( ) { return static::$_compiler; } + + /** + * Get context keys. + * + * @access public + * @return array + */ + public function getContextKeys ( ) { + + return static::getInterpreter()->getContextKeys(); + } } } diff --git a/Visitor/Interpreter.php b/Visitor/Interpreter.php index abd1ab5..ba8d8d7 100644 --- a/Visitor/Interpreter.php +++ b/Visitor/Interpreter.php @@ -84,7 +84,13 @@ class Interpreter implements \Hoa\Visitor\Visit { */ protected $_current = null; - + /** + * Context keys. + * + * @var array + */ + protected $_contextKeys = array(); + /** * Visit an element. @@ -219,9 +225,11 @@ public function visit ( \Hoa\Visitor\Element $element, &$handle = null, $eldnah switch($token) { case 'identifier': - return true === $variable - ? $this->_root->variable($value) - : $value; + if (true === $variable) { + array_push($this->_contextKeys, $value); + return $this->_root->variable($value); + } + return $value; case 'true': return true; @@ -269,6 +277,27 @@ public function getRoot ( ) { return $this->_root; } + + /** + * Get context keys. + * + * @access public + * @return array + */ + public function getContextKeys ( ) { + + return $this->_contextKeys; + } + + /** + * Clear context keys. + * + * @access public + */ + public function clearContextKeys ( ) { + + $this->_contextKeys = array(); + } } }