<?php
class Palette
{
protected static $_valid_colours = array(
'red' => array(255,0,0),
'green' => array(0,255,0),
'blue' => array(0,0,255),
'yellow' => array(255,255,0),
'magenta' => array(255,0,255),
'cyan' => array(0,255,255),
'black' => array(0,0,0)
);
protected $_selected_colours;
public function __construct($selections){
foreach($selections as $selection){
if( is_array($selection) ){
if( count($selection) !== 3 ){
throw new InvalidArgumentException("Invalid RGB value");
}
foreach( $selection as $value ){
if( !is_int($value) || $value < 0 || $value > 255 ){
throw new InvalidArgumentException("Invalid RGB value");
}
}
$this->_selected_colours[] = $selection;
continue;
}
if( !is_string($selection) ){
throw new InvalidArgumentException("Invalid (non-string, non-array) colour");
}
$selection = strtolower($selection);
if( !isset(static::$_valid_colours[ $selection ]) ){
throw new InvalidArgumentException("Unknown colour [$selection]");
}
$this->_selected_colours[] = static::$_valid_colours[ $selection ];
}
}
public function get_colours()
{
return $this->_selected_colours;
}
}
preferences:
39.33 ms | 402 KiB | 5 Q