You are here

class SassScriptVariable in Sassy 7

Same name and namespace in other branches
  1. 7.3 phpsass/script/SassScriptVariable.php \SassScriptVariable

SassVariable class. @package PHamlP @subpackage Sass.script.literals

Hierarchy

Expanded class hierarchy of SassScriptVariable

File

phamlp/sass/script/SassScriptVariable.php, line 17

View source
class SassScriptVariable {

  /**
   * Regex for matching and extracting Variables
   */
  const MATCH = '/^(?<!\\\\)(?(?!!important\\b)[!\\$]([\\w-]+))/';

  /**
   * @var string name of variable
   */
  private $name;

  /**
   * SassVariable constructor
   * @param string value of the Variable type
   * @return SassVariable
   */
  public function __construct($value) {
    $this->name = substr($value, 1);
  }

  /**
   * Returns the SassScript object for this variable.
   * @param SassContext context of the variable
   * @return SassLiteral the SassScript object for this variable
   */
  public function evaluate($context) {
    return $context
      ->getVariable($this->name);
  }

  /**
   * Returns a value indicating if a token of this type can be matched at
   * the start of the subject string.
   * @param string the subject string
   * @return mixed match at the start of the string or false if no match
   */
  public static function isa($subject) {

    // we need to do the check as preg_match returns a count of 1 if
    // subject == '!important'; the match being an empty match
    return preg_match(self::MATCH, $subject, $matches) ? empty($matches[0]) ? false : $matches[0] : false;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SassScriptVariable::$name private property *
SassScriptVariable::evaluate public function * Returns the SassScript object for this variable. *
SassScriptVariable::isa public static function * Returns a value indicating if a token of this type can be matched at * the start of the subject string. *
SassScriptVariable::MATCH constant * Regex for matching and extracting Variables
SassScriptVariable::__construct public function * SassVariable constructor *