public static function getAcceptedType(string $accept, array $available)
    {
        $list = static::compareAccept($accept, $available);
        if (empty($list)) {
            return array_values($available)[0];
        }

        $result = static::firstHigher($list);
        if ($result !== null) {
            return $result;
        }

        $forbidden = array_filter($list, function ($value) {
            return $value === 0;
        });
        $allowed = array_diff($available, array_keys($forbidden));

        if (empty($allowed)) {
            return false;
        }

        return array_values($allowed)[0];
    }
public static function getAcceptedType(string $accept, array $available)
    {
        $list = static::compareAccept($accept, $available);
        if (empty($list)) {
            return array_values($available)[0];
        }

        $result = static::firstHigher($list);
        if ($result !== null) {
            return $result;
        }

        $forbidden = array_filter($list, function ($value) {
            return $value === 0;
        });
        $allowed = array_diff($available, array_keys($forbidden));

        if (empty($allowed)) {
            return false;
        }

        return array_values($allowed)[0];
    }
public static function getAcceptedType ( string $ accept , array $ available ) { $ list = static :: compareAccept ( $ accept , $ available ) ; if ( empty ( $ list ) ) { return array_values ( $ available ) [ 0 ] ; } $ result = static :: firstHigher ( $ list ) ; if ( $ result !== null ) { return $ result ; } $ forbidden = array_filter ( $ list , function ( $ value ) { return $ value === 0 ; } ) ; $ allowed = array_diff ( $ available , array_keys ( $ forbidden ) ) ; if ( empty ( $ allowed ) ) { return false ; } return array_values ( $ allowed ) [ 0 ] ; }
Determines an accepted Content-Type from a list

NOTE:
- If no $available content types match $accept, but at least one of them
is not forbidden by $accept (i.e. ';q=0'), it is returned. It is better
to respond something the client doesn't complain about than a useless
error message

@param string   $accept    Accept header
@param string[] $available List of available content types

@return string
@return false  If no content type is acceptable
Determines an accepted Content - Type from a list