Zend_Http_Client::setAuth PHP Method

setAuth() public method

$type should be one of the supported types - see the self::AUTH_* constants. To enable authentication: $this->setAuth('shahar', 'secret', Zend_Http_Client::AUTH_BASIC); To disable authentication: $this->setAuth(false);
See also: http://www.faqs.org/rfcs/rfc2617.html
public setAuth ( string | false $user, string $password = '', string $type = self::AUTH_BASIC ) : Zend_Http_Client
$user string | false User name or false disable authentication
$password string Password
$type string Authentication type
return Zend_Http_Client
    public function setAuth($user, $password = '', $type = self::AUTH_BASIC)
    {
        // If we got false or null, disable authentication
        if ($user === false || $user === null) {
            $this->auth = null;
            // Clear the auth information in the uri instance as well
            if ($this->uri instanceof Zend_Uri_Http) {
                $this->getUri()->setUsername('');
                $this->getUri()->setPassword('');
            }
            // Else, set up authentication
        } else {
            // Check we got a proper authentication type
            if (!defined('self::AUTH_' . strtoupper($type))) {
                /** @see Zend_Http_Client_Exception */
                require_once 'Zend/Http/Client/Exception.php';
                throw new Zend_Http_Client_Exception("Invalid or not supported authentication type: '{$type}'");
            }
            $this->auth = array('user' => (string) $user, 'password' => (string) $password, 'type' => $type);
        }
        return $this;
    }

Usage Example

Example #1
0
 public function __construct($apiKey, $subdomain, Zend_Http_Client $client)
 {
     $this->apiKey = $apiKey;
     $this->client = $client;
     $this->subdomain = $subdomain;
     $this->client->setAuth($this->apiKey, 'X');
 }
All Usage Examples Of Zend_Http_Client::setAuth