SassColour::assertValid PHP Méthode

assertValid() public méthode

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
public assertValid ( array $colour, boolean $all = true ) : string
$colour array the colour to test
$all boolean whether all colour space keys must be given
Résultat string name of the colour space
    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);
        }
    }