src/MIBS/Cisco/SMST.php
public function vlansMappedAsRanges( $instanceID = false )
    {
        $vlansMapped = $this->vlansMapped( $instanceID );

        if ( $instanceID )
            $vlansMapped[ $instanceID ] = $vlansMapped;

        $ranges = [];

        // big loop to turn sequential VLANs into ranges
        // FIXME extract as utility function?
        foreach( $vlansMapped as $id => $mapped )
        {
            $start = false;
            $inc = false;

            foreach( $mapped as $vid => $flag )
            {
                if( $flag )
                {
                    if( !$start )
                    {
                        $start = $vid;
                        $inc   = $vid;
                        continue;
                    }

                    if( $vid - $inc == 1 )
                    {
                        $inc++;
                        continue;
                    }

                    if( $vid - $inc != 1 )
                    {
                        if( $start == $inc )
                            $ranges[ $id ][] = $start;
                        else
                            $ranges[ $id ][] = "{$start}-{$inc}";

                        $start = false;
                        continue;
                    }
                }
                else
                {
                    if( !$start )
                        continue;
                    else
                    {
                        if( $start == $inc )
                            $ranges[ $id ][] = $start;
                        else
                            $ranges[ $id ][] = "{$start}-{$inc}";

                        $start = false;
                        continue;
                    }

                }

            }

            if( $start )
            {
                if( $start == $inc )
                    $ranges[ $id ][] = $start;
                else
                    $ranges[ $id ][] = "{$start}-{$inc}";
            }
        }

        if( $instanceID )
            return $ranges[ $instanceID ];

        return $ranges;
    }
public function vlansMappedAsRanges( $instanceID = false )
    {
        $vlansMapped = $this->vlansMapped( $instanceID );

        if ( $instanceID )
            $vlansMapped[ $instanceID ] = $vlansMapped;

        $ranges = [];

        // big loop to turn sequential VLANs into ranges
        // FIXME extract as utility function?
        foreach( $vlansMapped as $id => $mapped )
        {
            $start = false;
            $inc = false;

            foreach( $mapped as $vid => $flag )
            {
                if( $flag )
                {
                    if( !$start )
                    {
                        $start = $vid;
                        $inc   = $vid;
                        continue;
                    }

                    if( $vid - $inc == 1 )
                    {
                        $inc++;
                        continue;
                    }

                    if( $vid - $inc != 1 )
                    {
                        if( $start == $inc )
                            $ranges[ $id ][] = $start;
                        else
                            $ranges[ $id ][] = "{$start}-{$inc}";

                        $start = false;
                        continue;
                    }
                }
                else
                {
                    if( !$start )
                        continue;
                    else
                    {
                        if( $start == $inc )
                            $ranges[ $id ][] = $start;
                        else
                            $ranges[ $id ][] = "{$start}-{$inc}";

                        $start = false;
                        continue;
                    }

                }

            }

            if( $start )
            {
                if( $start == $inc )
                    $ranges[ $id ][] = $start;
                else
                    $ranges[ $id ][] = "{$start}-{$inc}";
            }
        }

        if( $instanceID )
            return $ranges[ $instanceID ];

        return $ranges;
    }
public function vlansMappedAsRanges ( $ instanceID = false ) { $ vlansMapped = $ this -> vlansMapped ( $ instanceID ) ; if ( $ instanceID ) $ vlansMapped [ $ instanceID ] = $ vlansMapped ; $ ranges = [ ] ; // big loop to turn sequential VLANs into ranges // FIXME extract as utility function? foreach ( $ vlansMapped as $ id => $ mapped ) { $ start = false ; $ inc = false ; foreach ( $ mapped as $ vid => $ flag ) { if ( $ flag ) { if ( ! $ start ) { $ start = $ vid ; $ inc = $ vid ; continue ; } if ( $ vid - $ inc == 1 ) { $ inc ++ ; continue ; } if ( $ vid - $ inc != 1 ) { if ( $ start == $ inc ) $ ranges [ $ id ] [ ] = $ start ; else $ ranges [ $ id ] [ ] = "{$start}-{$inc}" ; $ start = false ; continue ; } } else { if ( ! $ start ) continue ; else { if ( $ start == $ inc ) $ ranges [ $ id ] [ ] = $ start ; else $ ranges [ $ id ] [ ] = "{$start}-{$inc}" ; $ start = false ; continue ; } } } if ( $ start ) { if ( $ start == $ inc ) $ ranges [ $ id ] [ ] = $ start ; else $ ranges [ $ id ] [ ] = "{$start}-{$inc}" ; } } if ( $ instanceID ) return $ ranges [ $ instanceID ] ; return $ ranges ; }
Return array of MST instances containing an array of mapped VLAN ranges

The form of the returned array is:

[
$mstInstanceId => [
500-599,
3000-4094,
...
],
...
]

Example usage:

foreach( $ports as $id => $portConf )
{
echo sprintf( "%-16s - %-8s:\t", $portConf['host'], $portConf['port'] );
echo $hosts[ $portConf['host'] ]->useIface()->operationStates( true )[ $portNameToIndex[ $portConf['host'] ][ $portConf['port'] ] ] . "\n";
}

Which results in (for example):

MST0       vlans mapped: 1-299,400-499,600-799,900-999,1800-4094
MST1       vlans mapped: 300-399
MST2       vlans mapped: 500-599,800-899,1000-1099,1300-1499
MST3       vlans mapped: 1500-1599
MST4       vlans mapped: 1100-1199
MST5       vlans mapped: 1200-1299
MST6       vlans mapped: 1600-1799


@see vlansMapped()
@param int $instanceId Limit results to a single instance ID (returned array is one dimensional)
@return Array as described above.
Return array of MST instances containing an array of mapped VLAN ranges