private function coerceValue($value)
{
if (is_array($value) || $value instanceof \ArrayAccess) {
return $value;
}
if (is_bool($value)) {
return $this->toBool($value);
}
if ($value === null) {
return static::$null;
}
if (is_numeric($value)) {
return new Node\Number($value, '');
}
if ($value === '') {
return static::$emptyString;
}
if (preg_match('/^(#([0-9a-f]{6})|#([0-9a-f]{3}))$/i', $value, $m)) {
$color = [Type::T_COLOR];
if (isset($m[3])) {
$num = hexdec($m[3]);
foreach ([3, 2, 1] as $i) {
$t = $num & 0xf;
$color[$i] = $t << 4 | $t;
$num >>= 4;
}
} else {
$num = hexdec($m[2]);
foreach ([3, 2, 1] as $i) {
$color[$i] = $num & 0xff;
$num >>= 8;
}
}
return $color;
}
return [Type::T_KEYWORD, $value];
}