Exemplo n.º 1
0
 /**
  * Match a condition.
  *
  * @param array $arguments
  * @param Context $context
  *
  * @return bool
  */
 public function matchCondition(array $arguments, Context $context)
 {
     if (!$this->condition) {
         return true;
     }
     $frame = $this->compileParams($context, Context::createCopyForCompilation($context, array_merge($this->frames, $context->frames)), $arguments);
     $compileEnv = Context::createCopyForCompilation($context, array_merge([$frame], $this->frames, $context->frames));
     if (!$this->condition->compile($compileEnv)) {
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * Compiles the node
  *
  * @param Context $context The context
  * @param array|null $arguments Array of arguments
  * @param boolean|null $important Important flag
  * @return SelectorNode
  */
 public function compile(Context $context, $arguments = null, $important = null)
 {
     $elements = $extendList = [];
     // compile elements
     foreach ($this->elements as $e) {
         $elements[] = $e->compile($context);
     }
     // compile extended list
     foreach ($this->extendList as $e) {
         $extendList[] = $e->compile($context);
     }
     // compile condition
     $compiledCondition = null;
     if ($this->condition) {
         $compiledCondition = $this->condition->compile($context);
     }
     return $this->createDerived($elements, $extendList, $compiledCondition);
 }
Exemplo n.º 3
0
 /**
  * @covers compile
  */
 public function testCompile()
 {
     $env = new Context();
     // equal - false condition
     $c = new ConditionNode('=', new AnonymousNode(5), new AnonymousNode(4));
     $result = $c->compile($env);
     $this->assertFalse($result);
     // equal
     $c = new ConditionNode('=', new AnonymousNode(5), new AnonymousNode(5));
     $result = $c->compile($env);
     $this->assertTrue($result);
     // greater than
     $c = new ConditionNode('>', new DimensionNode(5), new DimensionNode(4));
     $result = $c->compile($env);
     $this->assertTrue($result);
     // lower than
     $c = new ConditionNode('<', new DimensionNode(5), new DimensionNode(4));
     $result = $c->compile($env);
     $this->assertFalse($result);
     // lower or equal than
     $c = new ConditionNode('<=', new DimensionNode(5), new DimensionNode(5));
     $result = $c->compile($env);
     $this->assertTrue($result);
     // lower or equal than -> operator modified
     $c = new ConditionNode('=<', new DimensionNode(5), new DimensionNode(5));
     $result = $c->compile($env);
     $this->assertTrue($result);
     // greater or equal than
     $c = new ConditionNode('>=', new DimensionNode(5), new DimensionNode(5));
     $result = $c->compile($env);
     $this->assertTrue($result);
     // greater or equal than -> operator modified
     $c = new ConditionNode('=>', new DimensionNode(6), new DimensionNode(5));
     $result = $c->compile($env);
     $this->assertTrue($result);
     // greater or equal than -> false condition
     $c = new ConditionNode('=>', new DimensionNode(5), new DimensionNode(7));
     $result = $c->compile($env);
     $this->assertFalse($result);
 }