getValue(); $cc = new ChainCollectorStartNode('IntermediateObject'); return $cc->if($what); } class IfIntermediate extends BaseIntermediateObject { protected $_conditionStack; public function __construct($value, $stack = array()) { parent::__construct($value); $this->_conditionStack = $stack; } /** * Return an IsObject * * @return IsObject */ protected function _createObject() { return new IsObject($this->_value, $this->_conditionStack); } public function __get($name) { $obj = $this->_createObject(); if($name == 'not') $obj->setMode(IsObject::NOT); if($name == 'not' || $name == 'is') return $obj; } } class IsObject extends BaseIntermediateObject { const IS = 1; const NOT = 2; /** * Used to identify the type of the comparison */ const SAME_AS = 1; const GREATER_THAN = 2; const LESS_THAN = 3; private $_mode = IsObject::IS; private $_conditionType = IsObject::SAME_AS; protected $_conditionStack; private $_comparisonValue; public function __construct($value, $stack = array()) { parent::__construct($value); $this->_conditionStack = $stack; $this->_conditionStack[] = $this; } public function evaluate() { $value = false; switch($this->_conditionType) { case IsObject::SAME_AS: $value = ($this->_value == $this->_comparisonValue); break; case IsObject::GREATER_THAN: $value = ($this->_value > $this->_comparisonValue); break; case IsObject::LESS_THAN: $value = ($this->_value < $this->_comparisonValue); break; } if($this->_mode == IsObject::NOT) $value = !$value; return $value; } public function setMode($isMode) { $this->_mode = $isMode; } public function getConditionStack() { return $this->_conditionStack; } public function greaterThan($value) { return $this->_setType(IsObject::GREATER_THAN, $value); } public function lessThan($value) { return $this->_setType(IsObject::LESS_THAN, $value); } public function sameAs($value) { return $this->_setType(IsObject::SAME_AS, $value); } protected function _setType($type, $value) { $this->_comparisonValue = $value; $this->_conditionType = $type; return new IfAndObject($this->_conditionStack); } } class IfAndObject { protected $_stack; public function __construct($stack) { $this->_stack = $stack; } public function and_($what) { return new IfIntermediate($what, $this->_stack); } public function __call($method,$args) { if($method == 'and') return $this->and_($args[0]); if($method == 'do') { return $this->do_($args[0]); } } public function do_($what) { foreach($this->_stack as $c) { if(!$c->evaluate()) { /*if($method == 'evaluate') return false; */ return new ElseObject(false); } } /*if($method == 'evaluate') return true; */ return ChainRunner::getInstance()->runChain($what->getChain()); } } class ElseObject extends BaseIntermediateObject { public function __call($method, $args) { if($method == 'else' && $this->_value == false) return ChainRunner::getInstance()->runChain($args[0]->getChain()); $o = new IntermediateObject($this->_value); return call_user_func_array(array($o,$method),$args); } public function __get($property) { $o = new IntermediateObject($this->_value); return $o->$property; } }