/**
* Constructor
*
* @param string $fg Foreground color.
* @param string $bg Background color.
* @param array $options Style options.
*
* @since 4.0.0
* @throws \InvalidArgumentException
*/
public function __construct(string $fg = '', string $bg = '', array $options = [])
{
if ($fg) {
if (\array_key_exists($fg, static::$knownColors) == false) {
throw new \InvalidArgumentException(sprintf('Invalid foreground color "%1$s" [%2$s]', $fg, implode(', ', $this->getKnownColors())));
}
$this->fgColor = static::$fgBase + static::$knownColors[$fg];
}
if ($bg) {
if (\array_key_exists($bg, static::$knownColors) == false) {
throw new \InvalidArgumentException(sprintf('Invalid background color "%1$s" [%2$s]', $bg, implode(', ', $this->getKnownColors())));
}
$this->bgColor = static::$bgBase + static::$knownColors[$bg];
}
foreach ($options as $option) {
if (\array_key_exists($option, static::$knownOptions) == false) {
throw new \InvalidArgumentException(sprintf('Invalid option "%1$s" [%2$s]', $option, implode(', ', $this->getKnownOptions())));
}
$this->options[] = $option;
}
}