public function preferred(array $types): ?string
    {
        if (empty($types)) {
            return null;
        }
        foreach ($this->types as $type) {
            if (in_array($type, $types, true)) {
                return $type;
            } elseif ('*/*' == $type) {
                return current($types);
            } elseif (strlen($type) > 2 && substr($type, -2, 2) == '/*') {
                $prefix = substr($type, 0, strpos($type, '/') + 1);
                $plen = strlen($prefix);
                foreach ($types as $t) {
                    if (strncmp($prefix, $t, $plen) === 0) {
                        return $t;
                    }
                }
            }
        }
        return null;
    }