Sulu\Bundle\ContactBundle\Contact\AbstractContactManager::getAddressByCondition PHP Метод

getAddressByCondition() публичный Метод

Returns an address by callback-condition.
public getAddressByCondition ( Sulu\Bundle\ContactBundle\Entity\AccountInterface | Contact $entity, callable $conditionCallback, boolean $force = false ) : mixed
$entity Sulu\Bundle\ContactBundle\Entity\AccountInterface | Sulu\Bundle\ContactBundle\Entity\Contact
$conditionCallback callable
$force boolean 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
Результат mixed
    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 ($main === null && $addresses->first()) {
                    return $addresses->first()->getAddress();
                }
            }
        }
        return $main;
    }