Hoa central
Model.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Ruler\Model;
38 
39 use Hoa\Core;
40 use Hoa\Ruler;
41 use Hoa\Visitor;
42 
51 class Model implements Visitor\Element
52 {
58  protected $_root = null;
59 
65  protected static $_compiler = null;
66 
67 
68 
76  public function __set($name, $value)
77  {
78  if ('expression' !== $name) {
79  return $this->$name = $value;
80  }
81 
82  if (is_scalar($value)) {
83  $value = new Bag\Scalar($value);
84  } elseif (is_array($value)) {
85  $value = new Bag\RulerArray($value);
86  }
87 
88  $this->_root = $value;
89 
90  return;
91  }
92 
98  public function getExpression()
99  {
100  return $this->_root;
101  }
102 
110  public function func()
111  {
112  $arguments = func_get_args();
113  $name = array_shift($arguments);
114 
115  return $this->_operator($name, $arguments, true);
116  }
117 
125  public function operation($name, Array $arguments)
126  {
127  return $this->_operator($name, $arguments, false);
128  }
129 
138  public function _operator($name, Array $arguments, $isFunction)
139  {
140  return new Operator(mb_strtolower($name), $arguments, $isFunction);
141  }
142 
150  public function __call($name, Array $arguments)
151  {
152  return $this->operation($name, $arguments);
153  }
154 
161  public function variable($id)
162  {
163  return new Bag\Context($id);
164  }
165 
174  public function accept(
175  Visitor\Visit $visitor,
176  &$handle = null,
177  $eldnah = null
178  ) {
179  return $visitor->visit($this, $handle, $eldnah);
180  }
181 
187  public function __toString()
188  {
189  if (null === static::$_compiler) {
190  static::$_compiler = new Ruler\Visitor\Compiler();
191  }
192 
193  return static::$_compiler->visit($this);
194  }
195 }
196 
200 Core\Consistency::flexEntity('Hoa\Ruler\Model\Model');
accept(Visitor\Visit $visitor, &$handle=null, $eldnah=null)
Definition: Model.php:174
__call($name, Array $arguments)
Definition: Model.php:150
_operator($name, Array $arguments, $isFunction)
Definition: Model.php:138
__set($name, $value)
Definition: Model.php:76
operation($name, Array $arguments)
Definition: Model.php:125