From ea1f213b42f676625a6428b3fddca50937bbf2a2 Mon Sep 17 00:00:00 2001 From: ncosmin2001 Date: Mon, 24 Mar 2014 15:18:46 +0200 Subject: [PATCH 1/8] Update Interpreter.php Adding possibility to return context keys for dynamically populate context. --- Visitor/Interpreter.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Visitor/Interpreter.php b/Visitor/Interpreter.php index abd1ab5..c1800d2 100644 --- a/Visitor/Interpreter.php +++ b/Visitor/Interpreter.php @@ -84,7 +84,13 @@ class Interpreter implements \Hoa\Visitor\Visit { */ protected $_current = null; - + /** + * Current node. + * + * @var \Hoa\Ruler\Visitor\Interpreter object + */ + 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,17 @@ public function getRoot ( ) { return $this->_root; } + + /** + * Get context keys. + * + * @access public + * @return \Hoa\Ruler\Model + */ + public function getContextKeys ( ) { + + return $this->_contextKeys; + } } } From 27f0cdd643d4f27879c804e2616258580d196017 Mon Sep 17 00:00:00 2001 From: ncosmin2001 Date: Mon, 24 Mar 2014 15:21:21 +0200 Subject: [PATCH 2/8] Update Interpreter.php --- Visitor/Interpreter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Visitor/Interpreter.php b/Visitor/Interpreter.php index c1800d2..d480f78 100644 --- a/Visitor/Interpreter.php +++ b/Visitor/Interpreter.php @@ -85,9 +85,9 @@ class Interpreter implements \Hoa\Visitor\Visit { protected $_current = null; /** - * Current node. + * Context keys. * - * @var \Hoa\Ruler\Visitor\Interpreter object + * @var array */ protected $_contextKeys = array(); @@ -282,7 +282,7 @@ public function getRoot ( ) { * Get context keys. * * @access public - * @return \Hoa\Ruler\Model + * @return array */ public function getContextKeys ( ) { From 4f56193ba22a34bfe94610d90961f453359105ee Mon Sep 17 00:00:00 2001 From: ncosmin2001 Date: Mon, 24 Mar 2014 15:24:46 +0200 Subject: [PATCH 3/8] Update Ruler.php Adding possibility to return context keys for dynamically populate context. --- Ruler.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Ruler.php b/Ruler.php index b66eeed..3e527dd 100644 --- a/Ruler.php +++ b/Ruler.php @@ -225,6 +225,17 @@ public static function getCompiler ( ) { return static::$_compiler; } + + /** + * Get context keys. + * + * @access public + * @return array + */ + public function getContextKeys ( $rule ) { + + return static::getInterpreter()->getContextKeys(); + } } } From dfed1516f0e780dcda68e31c9a7a4aa8f8d48dac Mon Sep 17 00:00:00 2001 From: ncosmin2001 Date: Mon, 24 Mar 2014 15:32:13 +0200 Subject: [PATCH 4/8] Update Ruler.php --- Ruler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ruler.php b/Ruler.php index 3e527dd..0d54a68 100644 --- a/Ruler.php +++ b/Ruler.php @@ -232,7 +232,7 @@ public static function getCompiler ( ) { * @access public * @return array */ - public function getContextKeys ( $rule ) { + public function getContextKeys ( ) { return static::getInterpreter()->getContextKeys(); } From 0d26cc30efcbabf2b970c3f81c888830fa453430 Mon Sep 17 00:00:00 2001 From: ncosmin2001 Date: Mon, 24 Mar 2014 15:42:16 +0200 Subject: [PATCH 5/8] Update Ruler.php --- Ruler.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Ruler.php b/Ruler.php index 0d54a68..c061445 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 content keys + $interpreter->clearContentKeys(); + + return $interpreter->visit( static::getCompiler()->parse($rule) ); } From 39562960c7d22242800421ba391cee53668394f1 Mon Sep 17 00:00:00 2001 From: ncosmin2001 Date: Mon, 24 Mar 2014 15:45:27 +0200 Subject: [PATCH 6/8] Update Ruler.php fixed --- Ruler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ruler.php b/Ruler.php index c061445..76e84ae 100644 --- a/Ruler.php +++ b/Ruler.php @@ -142,7 +142,7 @@ public static function interprete ( $rule ) { $interpreter = static::getInterpreter(); //clear content keys - $interpreter->clearContentKeys(); + $interpreter->clearContextKeys(); return $interpreter->visit( static::getCompiler()->parse($rule) From 4b684f43af14ee4833b37c1d9071c6a6b9ecb6e1 Mon Sep 17 00:00:00 2001 From: ncosmin2001 Date: Mon, 24 Mar 2014 15:46:18 +0200 Subject: [PATCH 7/8] Update Ruler.php --- Ruler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ruler.php b/Ruler.php index 76e84ae..ca15ce9 100644 --- a/Ruler.php +++ b/Ruler.php @@ -141,7 +141,7 @@ public function assert ( $rule, Context $context = null ) { public static function interprete ( $rule ) { $interpreter = static::getInterpreter(); - //clear content keys + //clear context keys $interpreter->clearContextKeys(); return $interpreter->visit( From 5dc28b5d2af94683f8fb7afbde9f4d832a4dee6d Mon Sep 17 00:00:00 2001 From: ncosmin2001 Date: Mon, 24 Mar 2014 15:48:05 +0200 Subject: [PATCH 8/8] Update Interpreter.php --- Visitor/Interpreter.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Visitor/Interpreter.php b/Visitor/Interpreter.php index d480f78..ba8d8d7 100644 --- a/Visitor/Interpreter.php +++ b/Visitor/Interpreter.php @@ -288,6 +288,16 @@ public function getContextKeys ( ) { return $this->_contextKeys; } + + /** + * Clear context keys. + * + * @access public + */ + public function clearContextKeys ( ) { + + $this->_contextKeys = array(); + } } }