aboutsummaryrefslogtreecommitdiffstats
path: root/Model/Declaration.php
diff options
context:
space:
mode:
Diffstat (limited to 'Model/Declaration.php')
-rw-r--r--Model/Declaration.php36
1 files changed, 34 insertions, 2 deletions
diff --git a/Model/Declaration.php b/Model/Declaration.php
index 11c9e4e..373d52a 100644
--- a/Model/Declaration.php
+++ b/Model/Declaration.php
@@ -82,6 +82,13 @@ abstract class Declaration
*/
protected $_predicates = array();
+ /**
+ * Whether declaring a local variable or not.
+ *
+ * @var \Hoa\Praspel\Model\Declaration bool
+ */
+ protected $_let = false;
+
/**
@@ -105,8 +112,13 @@ abstract class Declaration
*/
public function offsetGet ( $offset ) {
- if(false === $this->offsetExists($offset))
- return $this->_variables[$offset] = new Variable($offset, $this);
+ if(false === $this->offsetExists($offset)) {
+
+ $variable = new Variable($offset, $this->_let, $this);
+ $this->_let = false;
+
+ return $this->_variables[$offset] = $variable;
+ }
return $this->_variables[$offset];
}
@@ -143,6 +155,26 @@ abstract class Declaration
}
/**
+ * Allow to write $clause->let['var'] = … to define a local variable (if
+ * $name is not equal to "let", then it is a normal behavior).
+ *
+ * @access public
+ * @param string $name Name.
+ * @return \Hoa\Praspel\Model\Declaration
+ */
+ public function __get ( $name ) {
+
+ if('let' !== $name) {
+
+ return $this->$name;
+ }
+
+ $this->_let = true;
+
+ return $this;
+ }
+
+ /**
* Alias of $this->offsetGet().
*
* @access public