composer package updates
[openemr.git] / vendor / zendframework / zend-mail / src / Protocol / Smtp / Auth / Login.php
blob6c5354b926a6d971ee0e6dade6b0fec30383258e
1 <?php
2 /**
3 * @see https://github.com/zendframework/zend-mail for the canonical source repository
4 * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-mail/blob/master/LICENSE.md New BSD License
6 */
8 namespace Zend\Mail\Protocol\Smtp\Auth;
10 use Zend\Mail\Protocol\Smtp;
12 /**
13 * Performs LOGIN authentication
15 class Login extends Smtp
17 /**
18 * LOGIN username
20 * @var string
22 protected $username;
24 /**
25 * LOGIN password
27 * @var string
29 protected $password;
31 /**
32 * Constructor.
34 * @param string $host (Default: 127.0.0.1)
35 * @param int $port (Default: null)
36 * @param array $config Auth-specific parameters
38 public function __construct($host = '127.0.0.1', $port = null, $config = null)
40 // Did we receive a configuration array?
41 $origConfig = $config;
42 if (is_array($host)) {
43 // Merge config array with principal array, if provided
44 if (is_array($config)) {
45 $config = array_replace_recursive($host, $config);
46 } else {
47 $config = $host;
51 if (is_array($config)) {
52 if (isset($config['username'])) {
53 $this->setUsername($config['username']);
55 if (isset($config['password'])) {
56 $this->setPassword($config['password']);
60 // Call parent with original arguments
61 parent::__construct($host, $port, $origConfig);
64 /**
65 * Perform LOGIN authentication with supplied credentials
68 public function auth()
70 // Ensure AUTH has not already been initiated.
71 parent::auth();
73 $this->_send('AUTH LOGIN');
74 $this->_expect(334);
75 $this->_send(base64_encode($this->getUsername()));
76 $this->_expect(334);
77 $this->_send(base64_encode($this->getPassword()));
78 $this->_expect(235);
79 $this->auth = true;
82 /**
83 * Set value for username
85 * @param string $username
86 * @return Login
88 public function setUsername($username)
90 $this->username = $username;
91 return $this;
94 /**
95 * Get username
97 * @return string
99 public function getUsername()
101 return $this->username;
105 * Set value for password
107 * @param string $password
108 * @return Login
110 public function setPassword($password)
112 $this->password = $password;
113 return $this;
117 * Get password
119 * @return string
121 public function getPassword()
123 return $this->password;