Horde\ManageSieve::_getBestAuthMethod PHP Method

_getBestAuthMethod() protected method

Returns the name of the best authentication method that the server has advertised.
protected _getBestAuthMethod ( string $authmethod = null ) : string
$authmethod string Only consider this method as available.
return string The name of the best supported authentication method.
    protected function _getBestAuthMethod($authmethod = null)
    {
        if (!isset($this->_capability['sasl'])) {
            throw new Exception('This server doesn\'t support any authentication methods. SASL problem?');
        }
        if (!$this->_capability['sasl']) {
            throw new Exception('This server doesn\'t support any authentication methods.');
        }
        if ($authmethod) {
            if (in_array($authmethod, $this->_capability['sasl'])) {
                return $authmethod;
            }
            throw new Exception(sprintf('No supported authentication method found. The server supports these methods: %s, but we want to use: %s', implode(', ', $this->_capability['sasl']), $authmethod));
        }
        foreach ($this->supportedAuthMethods as $method) {
            if (in_array($method, $this->_capability['sasl'])) {
                return $method;
            }
        }
        throw new Exception(sprintf('No supported authentication method found. The server supports these methods: %s, but we only support: %s', implode(', ', $this->_capability['sasl']), implode(', ', $this->supportedAuthMethods)));
    }