src/Chromabits/TutumClient/Entities/Container.php
public function findLinks($serviceName, $tcpPorts = [], $udpPorts = [])
    {
        // First match names
        $matching = [];
        $encodedName = $this->encodeServiceName($serviceName);

        $regex = '/^' . $encodedName . '_([0-9]+)$/';

        if (!is_array($this->links)) {
            return [];
        }

        foreach ($this->links as $link) {
            if (preg_match($regex, $link->getName())) {
                $matching[] = $link;
            }
        }

        // Find those that match TCP ports
        $matching = array_filter(
            $matching,
            function (ContainerLink $link) use ($tcpPorts) {
                foreach ($tcpPorts as $tcpPort) {
                    if (!$link->hasEndpoint($tcpPort, 'tcp')) {
                        return false;
                    }
                }

                return true;
            }
        );

        // Reduce even more by finding those that match UDP ports
        $matching = array_filter(
            $matching,
            function (ContainerLink $link) use ($udpPorts) {
                foreach ($udpPorts as $udpPort) {
                    if (!$link->hasEndpoint($udpPort, 'udp')) {
                        return false;
                    }
                }

                return true;
            }
        );

        return $matching;
    }
public function findLinks($serviceName, $tcpPorts = [], $udpPorts = [])
    {
        // First match names
        $matching = [];
        $encodedName = $this->encodeServiceName($serviceName);

        $regex = '/^' . $encodedName . '_([0-9]+)$/';

        if (!is_array($this->links)) {
            return [];
        }

        foreach ($this->links as $link) {
            if (preg_match($regex, $link->getName())) {
                $matching[] = $link;
            }
        }

        // Find those that match TCP ports
        $matching = array_filter(
            $matching,
            function (ContainerLink $link) use ($tcpPorts) {
                foreach ($tcpPorts as $tcpPort) {
                    if (!$link->hasEndpoint($tcpPort, 'tcp')) {
                        return false;
                    }
                }

                return true;
            }
        );

        // Reduce even more by finding those that match UDP ports
        $matching = array_filter(
            $matching,
            function (ContainerLink $link) use ($udpPorts) {
                foreach ($udpPorts as $udpPort) {
                    if (!$link->hasEndpoint($udpPort, 'udp')) {
                        return false;
                    }
                }

                return true;
            }
        );

        return $matching;
    }
public function findLinks ( $ serviceName , $ tcpPorts = [ ] , $ udpPorts = [ ] ) { // First match names $ matching = [ ] ; $ encodedName = $ this -> encodeServiceName ( $ serviceName ) ; $ regex = '/^' . $ encodedName . '_([0-9]+)$/' ; if ( ! is_array ( $ this -> links ) ) { return [ ] ; } foreach ( $ this -> links as $ link ) { if ( preg_match ( $ regex , $ link -> getName ( ) ) ) { $ matching [ ] = $ link ; } } // Find those that match TCP ports $ matching = array_filter ( $ matching , function ( ContainerLink $ link ) use ( $ tcpPorts ) { foreach ( $ tcpPorts as $ tcpPort ) { if ( ! $ link -> hasEndpoint ( $ tcpPort , 'tcp' ) ) { return false ; } } return true ; } ) ; // Reduce even more by finding those that match UDP ports $ matching = array_filter ( $ matching , function ( ContainerLink $ link ) use ( $ udpPorts ) { foreach ( $ udpPorts as $ udpPort ) { if ( ! $ link -> hasEndpoint ( $ udpPort , 'udp' ) ) { return false ; } } return true ; } ) ; return $ matching ; }
Find linked services that match a certain criteria

@param string $serviceName
@param int[] $tcpPorts
@param int[] $udpPorts

@return ContainerLink[]
Find linked services that match a certain criteria