You are here

public function SassVariableNode::__construct in Sassy 7.3

Same name and namespace in other branches
  1. 7 phamlp/sass/tree/SassVariableNode.php \SassVariableNode::__construct()

SassVariableNode constructor.

Parameters

object source token:

Return value

SassVariableNode

Overrides SassNode::__construct

File

phpsass/tree/SassVariableNode.php, line 47

Class

SassVariableNode
SassVariableNode class. Represents a variable. @package PHamlP @subpackage Sass.tree

Code

public function __construct($token) {
  parent::__construct($token);
  preg_match(self::MATCH, $token->source, $matches);
  if (empty($matches[self::NAME]) || $matches[self::VALUE] === '') {
    throw new SassVariableNodeException('Invalid variable definition; name and expression required', $this);
  }
  $this->name = $matches[self::NAME];
  $this->value = $matches[self::VALUE];
  $this->isDefault = !empty($matches[self::SASS_DEFAULT]) || !empty($matches[self::SCSS_DEFAULT]);

  // Warn about deprecated features
  if ($matches[self::IDENTIFIER] === self::SASS_IDENTIFIER) {
    $this
      ->addWarning('Variables prefixed with "!" is deprecated; use "' . $this->name . '"');
  }
  if (!empty($matches[SassVariableNode::SASS_ASSIGNMENT])) {
    $this
      ->addWarning('Setting variables with "' . (!empty($matches[SassVariableNode::SASS_DEFAULT]) ? '||' : '') . '=" is deprecated; use "$' . $this->name . ': ' . $this->value . (!empty($matches[SassVariableNode::SASS_DEFAULT]) ? ' !default' : ''));
  }
}