You are here

public function SassColour::assertValid in Sassy 7.3

Same name and namespace in other branches
  1. 7 phamlp/sass/script/literals/SassColour.php \SassColour::assertValid()

Asserts that the colour space is valid. Returns the name of the colour space: 'rgb' if red, green, or blue keys given; 'hsl' if hue, saturation or lightness keys given; null if a non-associative array

Parameters

array the colour to test:

boolean whether all colour space keys must be given:

Return value

string name of the colour space

Throws

SassColourException if mixed colour space keys given or not all keys for a colour space are required but not given (contructor)

2 calls to SassColour::assertValid()
SassColour::with in phpsass/script/literals/SassColour.php
Returns a copy of this colour with one or more channels changed. RGB or HSL attributes may be changed, but not both at once.
SassColour::__construct in phpsass/script/literals/SassColour.php
Constructs an RGB or HSL color object, optionally with an alpha channel. RGB values must be between 0 and 255. Saturation and lightness values must be between 0 and 100. The alpha value must be between 0 and 1. The colour can be specified as: + a…

File

phpsass/script/literals/SassColour.php, line 856

Class

SassColour
SassColour class. A SassScript object representing a CSS colour.

Code

public function assertValid($colour, $all = true) {
  if (array_key_exists('red', $colour) || array_key_exists('green', $colour) || array_key_exists('blue', $colour)) {
    if (array_key_exists('hue', $colour) || array_key_exists('saturation', $colour) || array_key_exists('lightness', $colour)) {
      throw new SassColourException('SassColour can not have HSL and RGB keys specified', SassScriptParser::$context->node);
    }
    if ($all && (!array_key_exists('red', $colour) || !array_key_exists('green', $colour) || !array_key_exists('blue', $colour))) {
      throw new SassColourException('SassColour must have all RGB keys specified', SassScriptParser::$context->node);
    }
    return 'rgb';
  }
  elseif (array_key_exists('hue', $colour) || array_key_exists('saturation', $colour) || array_key_exists('lightness', $colour)) {
    if ($all && (!array_key_exists('hue', $colour) || !array_key_exists('saturation', $colour) || !array_key_exists('lightness', $colour))) {
      throw new SassColourException('SassColour must have all HSL keys specified', SassScriptParser::$context->node);
    }
    return 'hsl';
  }
  elseif ($all && sizeof($colour) < 3) {
    throw new SassColourException('SassColour array must have at least 3 elements', SassScriptParser::$context->node);
  }
}