Example #1
0
 /**
  * @covers getType
  */
 public function testGetType()
 {
     $md = new ILess_Node_MixinDefinition('foobar');
     $this->assertEquals('MixinDefinition', $md->getType());
 }
Example #2
0
 /**
  * @see ILess_Node::compile
  */
 public function compile(ILess_Environment $env, $arguments = null, $important = null)
 {
     $rules = array();
     $match = false;
     $isOneFound = false;
     $args = array();
     foreach ($this->arguments as $a) {
         $args[] = array('name' => $a['name'], 'value' => $a['value']->compile($env));
     }
     foreach ($env->frames as $frame) {
         $mixins = $frame->find($this->selector, $env);
         if (!$mixins) {
             continue;
         }
         $isOneFound = true;
         for ($m = 0; $m < count($mixins); $m++) {
             $mixin = $mixins[$m];
             $isRecursive = false;
             foreach ($env->frames as $recurFrame) {
                 if (!$mixin instanceof ILess_Node_MixinDefinition) {
                     if (isset($recurFrame->originalRulesetId) && $mixin->rulesetId === $recurFrame->originalRulesetId || $mixin === $recurFrame) {
                         $isRecursive = true;
                         break;
                     }
                 }
             }
             if ($isRecursive) {
                 continue;
             }
             if ($mixin->matchArgs($args, $env)) {
                 if (!ILess_Node::methodExists($mixin, 'matchCondition') || $mixin->matchCondition($args, $env)) {
                     try {
                         if (!$mixin instanceof ILess_Node_MixinDefinition) {
                             $mixin = new ILess_Node_MixinDefinition('', array(), $mixin->rules, null, false);
                             $mixin->originalRulesetId = $mixins[$m]->originalRulesetId ? $mixins[$m]->originalRulesetId : $mixin->originalRulesetId;
                         }
                         $rules = array_merge($rules, $mixin->compile($env, $args, $this->important)->rules);
                     } catch (Exception $e) {
                         throw new ILess_Exception_Compiler($e->getMessage(), $this->index, $this->currentFileInfo, $e);
                     }
                 }
                 $match = true;
             }
         }
         if ($match) {
             if (!$this->currentFileInfo || !$this->currentFileInfo->reference) {
                 foreach ($rules as $rule) {
                     if ($rule instanceof ILess_Node_MarkableAsReferencedInterface) {
                         $rule->markReferenced();
                     }
                 }
             }
             return $rules;
         }
     }
     if ($isOneFound) {
         $message = array();
         if ($args) {
             foreach ($args as $a) {
                 $argValue = '';
                 if ($a['name']) {
                     $argValue .= $a['name'] . ':';
                 }
                 if (ILess_Node::methodExists($a['value'], 'toCSS')) {
                     $argValue .= $a['value']->toCSS($env);
                 } else {
                     $argValue .= '???';
                 }
                 $message[] = $argValue;
             }
         }
         throw new ILess_Exception_Compiler(sprintf('No matching definition was found for `%s(%s)`', trim($this->selector->toCSS($env)), join(',', $message)), $this->index, $this->currentFileInfo);
     } else {
         throw new ILess_Exception_Compiler(sprintf('%s is undefined.', trim($this->selector->toCSS($env))), $this->index, $this->currentFileInfo);
     }
 }