protected function validateType(&$value, $type, $name = '', $def = null) {
        switch ($type) {
            case 'boolean':
                if (is_bool($value)) {
                    $valid = true;
                } elseif ($value === 0) {
                    // 0 doesn't work well with in_array() so check it separately.
                    $value = false;
                    $valid = true;
                } elseif (in_array($value, [null, '', '0', 'false', 'no', 'disabled'])) {
                    $value = false;
                    $valid = true;
                } elseif (in_array($value, [1, '1', 'true', 'yes', 'enabled'])) {
                    $value = true;
                    $valid = true;
                } else {
                    $valid = false;
                }
                break;
            case 'integer':
                if (is_numeric($value)) {
                    $value = (int)$value;
                    $valid = true;
                } else {
                    $valid = false;
                }
                break;
            case 'string':
                $value = (string)$value;
                $valid = true;
                break;
            default:
                throw new \Exception("Unknown type: $type.", 400);
        }

        if (!$valid && $name) {
            $short = static::val('short', (array)$def);
            $nameStr = "--$name".($short ? " (-$short)" : '');
            echo $this->red("The value of $nameStr is not a valid $type.".PHP_EOL);
        }

        return $valid;
    }