/** * Match a condition * * @param array $arguments * @param ILess_Environment $env * @return boolean */ public function matchCondition(array $arguments, ILess_Environment $env) { if (!$this->condition) { return true; } $frame = $this->compileParams($env, ILess_Environment::createCopy($env, array_merge($this->frames, $env->frames)), $arguments); $compileEnv = ILess_Environment::createCopy($env, array_merge(array($frame), $this->frames, $env->frames)); if (!$this->condition->compile($compileEnv)) { return false; } return true; }
/** * @covers compile */ public function testCompile() { $env = new ILess_Environment(); // equal $c = new ILess_Node_Condition('=', new ILess_Node_Anonymous(5), new ILess_Node_Anonymous(5)); $result = $c->compile($env); $this->assertTrue($result); // equal - false condition $c = new ILess_Node_Condition('=', new ILess_Node_Anonymous(5), new ILess_Node_Anonymous(4)); $result = $c->compile($env); $this->assertFalse($result); // greater than $c = new ILess_Node_Condition('>', new ILess_Node_Anonymous(5), new ILess_Node_Anonymous(4)); $result = $c->compile($env); $this->assertTrue($result); // lower than $c = new ILess_Node_Condition('<', new ILess_Node_Anonymous(5), new ILess_Node_Anonymous(4)); $result = $c->compile($env); $this->assertFalse($result); // lower or equal than $c = new ILess_Node_Condition('<=', new ILess_Node_Anonymous(5), new ILess_Node_Anonymous(5)); $result = $c->compile($env); $this->assertTrue($result); // lower or equal than -> operator modified $c = new ILess_Node_Condition('=<', new ILess_Node_Anonymous(5), new ILess_Node_Anonymous(5)); $result = $c->compile($env); $this->assertTrue($result); // greater or equal than $c = new ILess_Node_Condition('>=', new ILess_Node_Anonymous(5), new ILess_Node_Anonymous(5)); $result = $c->compile($env); $this->assertTrue($result); // greater or equal than -> operator modified $c = new ILess_Node_Condition('=>', new ILess_Node_Anonymous(6), new ILess_Node_Anonymous(5)); $result = $c->compile($env); $this->assertTrue($result); // greater or equal than -> false condition $c = new ILess_Node_Condition('=>', new ILess_Node_Anonymous(5), new ILess_Node_Anonymous(7)); $result = $c->compile($env); $this->assertFalse($result); }
/** * @see ILess_Node */ public function compile(ILess_Environment $env, $arguments = null, $important = null) { $elements = $extendList = array(); // compile elements foreach ($this->elements as $e) { $elements[] = $e->compile($env); } // compile extended list foreach ($this->extendList as $e) { $extendList[] = $e->compile($env); } // compile condition $compiledCondition = null; if ($this->condition) { $compiledCondition = $this->condition->compile($env); } return $this->createDerived($elements, $extendList, $compiledCondition); }