Esempio n. 1
0
 /**
  * Compiles the node
  *
  * @param Context $context The context
  * @param array|null $arguments Array of arguments
  * @param boolean|null $important Important flag
  * @return boolean
  */
 public function compile(Context $context, $arguments = null, $important = null)
 {
     $a = $this->lvalue->compile($context);
     $b = $this->rvalue->compile($context);
     switch ($this->op) {
         case 'and':
             $result = $a && $b;
             break;
         case 'or':
             $result = $a || $b;
             break;
         default:
             $compared = Util::compareNodes($a, $b);
             // strict comparison, we cannot use switch here
             if ($compared === -1) {
                 $result = $this->op === '<' || $this->op === '=<' || $this->op === '<=';
             } elseif ($compared === 0) {
                 $result = $this->op === '=' || $this->op === '>=' || $this->op === '=<' || $this->op === '<=';
             } elseif ($compared === 1) {
                 $result = $this->op === '>' || $this->op === '>=' || $this->op === '=>';
             } else {
                 $result = false;
             }
             break;
     }
     return $this->negate ? !$result : $result;
 }
Esempio 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 array|ImportNode|MediaNode
  * @throws Exception
  * @throws LogicException
  */
 public function compile(Context $context, $arguments = null, $important = null)
 {
     if ($this->getOption('plugin')) {
         $registry = isset($context->frames[0]) && $context->frames[0]->functionRegistry ? $context->frames[0]->functionRegistry : null;
         if ($registry && $this->root && $this->root->functions) {
             /* @var $registry FunctionRegistry */
             foreach ($this->root->functions as $funcFile) {
                 $registry->loadPlugin($funcFile);
             }
         }
         return [];
     }
     if ($this->skip) {
         return [];
     }
     if ($this->getOption('inline')) {
         $contents = new AnonymousNode($this->root, 0, new FileInfo(['filename' => $this->importedFilename, 'reference' => $this->path->currentFileInfo->reference]), true, true, false);
         return $this->features ? new MediaNode([$contents], $this->features->value) : [$contents];
     } elseif ($this->css) {
         $features = $this->features ? $this->features->compile($context) : null;
         $import = new ImportNode($this->compilePath($context), $features, $this->options, $this->index);
         if (!$import->css && $this->hasError()) {
             throw $this->getError();
         }
         return $import;
     } else {
         $ruleset = new RulesetNode([], $this->root ? $this->root->rules : []);
         $ruleset->compileImports($context);
         return $this->features ? new MediaNode($ruleset->rules, $this->features->value) : $ruleset->rules;
     }
 }
Esempio n. 3
0
 /**
  * Compiles the node.
  *
  * @param Context $context The context
  * @param array|null $arguments Array of arguments
  * @param bool|null $important Important flag
  *
  * @return AttributeNode
  */
 public function compile(Context $context, $arguments = null, $important = null)
 {
     return new self($this->key instanceof CompilableInterface ? $this->key->compile($context) : $this->key, $this->operator, $this->value instanceof CompilableInterface ? $this->value->compile($context) : $this->value);
 }