You are here

private function SassColour::assertValid in Sassy 7

Same name and namespace in other branches
  1. 7.3 phpsass/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: * @param boolean whether all colour space keys must be given * @return 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 phamlp/sass/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 phamlp/sass/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…

File

phamlp/sass/script/literals/SassColour.php, line 849

Class

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

Code

private 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', array(), 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 {colourSpace} keys specified', array(
        '{colourSpace}' => 'RGB',
      ), 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 {colourSpace} keys specified', array(
        '{colourSpace}' => 'HSL',
      ), SassScriptParser::$context->node);
    }
    return 'hsl';
  }
  elseif ($all && sizeof($colour) < 3) {
    throw new SassColourException('SassColour array must have at least 3 elements', array(), SassScriptParser::$context->node);
  }
}