/** * @return Preset */ public static function getFromFile($lessFile, $urlroot) { $o = new static(); $o->file = $lessFile; $o->urlroot = $urlroot; $o->filename = basename($lessFile); $o->handle = substr($o->filename, 0, strrpos($o->filename, '.')); $l = new Less_Parser(); $parser = $l->parseFile($lessFile, false, true); $rules = $parser->rules; foreach ($rules as $rule) { switch (isset($rule->name) ? $rule->name : '') { case static::PRESET_RULE_NAME: $o->name = $rule->value->value[0]->value[0]->value; break; case static::PRESET_RULE_ICON: $method = $rule->value->value[0]->value[0]; if ($method instanceof Less_Tree_Call) { // extract the name and arguments from the method $color = TreeCallColor::fromTreeCall($method); if ($color->getName() == static::PRESET_RULE_ICON_FUNCTION) { $args = $color->getArguments(); $cv1 = ColorStyle::parse($args[0]->value[0]); $cv2 = ColorStyle::parse($args[1]->value[0]); $cv3 = ColorStyle::parse($args[2]->value[0]); $o->color1 = $cv1; $o->color2 = $cv2; $o->color3 = $cv3; } } break; } } return $o; }
public static function parse($value, $variable = false) { if ($value instanceof Less_Tree_Color) { if ($value->isTransparentKeyword) { return false; } $cv = new ColorValue($variable); $cv->setRed($value->rgb[0]); $cv->setGreen($value->rgb[1]); $cv->setBlue($value->rgb[2]); } elseif ($value instanceof Less_Tree_Call) { // Extract the arguments from the value $color = TreeCallColor::fromTreeCall($value); $args = $color->getArguments(); // might be rgb() or rgba() $cv = new ColorValue($variable); $cv->setRed($args[0]->value[0]->value); $cv->setGreen($args[1]->value[0]->value); $cv->setBlue($args[2]->value[0]->value); if ($color->getName() == 'rgba') { $cv->setAlpha($args[3]->value[0]->value); } } return $cv; }