src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php
public function getAddressByCondition($entity, callable $conditionCallback, $force = false)
    {
        $addresses = $this->getAddresses($entity);
        $address = null;
        $main = null;

        if (!is_null($addresses)) {
            /* @var AccountAddress $accountAddress */
            foreach ($addresses as $address) {
                if ($conditionCallback($address->getAddress())) {
                    return $address->getAddress();
                }
                if ($address->getMain()) {
                    $main = $address->getAddress();
                }
            }
            if ($force) {
                // return main or first address
                if (null === $main && $addresses->first()) {
                    return $addresses->first()->getAddress();
                }
            }
        }

        return $main;
    }
public function getAddressByCondition($entity, callable $conditionCallback, $force = false)
    {
        $addresses = $this->getAddresses($entity);
        $address = null;
        $main = null;

        if (!is_null($addresses)) {
            /* @var AccountAddress $accountAddress */
            foreach ($addresses as $address) {
                if ($conditionCallback($address->getAddress())) {
                    return $address->getAddress();
                }
                if ($address->getMain()) {
                    $main = $address->getAddress();
                }
            }
            if ($force) {
                // return main or first address
                if (null === $main && $addresses->first()) {
                    return $addresses->first()->getAddress();
                }
            }
        }

        return $main;
    }
public function getAddressByCondition ( $ entity , callable $ conditionCallback , $ force = false ) { $ addresses = $ this -> getAddresses ( $ entity ) ; $ address = null ; $ main = null ; if ( ! is_null ( $ addresses ) ) { /* @var AccountAddress $accountAddress */ foreach ( $ addresses as $ address ) { if ( $ conditionCallback ( $ address -> getAddress ( ) ) ) { return $ address -> getAddress ( ) ; } if ( $ address -> getMain ( ) ) { $ main = $ address -> getAddress ( ) ; } } if ( $ force ) { // return main or first address if ( null === $ main && $ addresses -> first ( ) ) { return $ addresses -> first ( ) -> getAddress ( ) ; } } } return $ main ; }
Returns an address by callback-condition.

@param AccountInterface|Contact $entity
@param callable $conditionCallback
@param bool $force Forces function to return an address if any address is defined
if no delivery address is defined it will first return the main address then any

@return mixed
Returns an address by callback - condition .