Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Mail_Protocol_Abstract Class Reference
Inheritance diagram for Zend_Mail_Protocol_Abstract:
Zend_Mail_Protocol_Smtp Zend_Mail_Protocol_Smtp_Auth_Crammd5 Zend_Mail_Protocol_Smtp_Auth_Login Zend_Mail_Protocol_Smtp_Auth_Plain

Public Member Functions

 __construct ($host='127.0.0.1', $port=null)
 
 __destruct ()
 
 setMaximumLog ($maximumLog)
 
 getMaximumLog ()
 
 connect ()
 
 getRequest ()
 
 getResponse ()
 
 getLog ()
 
 resetLog ()
 

Data Fields

const EOL = "\r\n"
 
const TIMEOUT_CONNECTION = 30
 

Protected Member Functions

 _addLog ($value)
 
 _connect ($remote)
 
 _disconnect ()
 
 _send ($request)
 
 _receive ($timeout=null)
 
 _expect ($code, $timeout=null)
 
 _setStreamTimeout ($timeout)
 

Protected Attributes

 $_maximumLog = 64
 
 $_host
 
 $_port
 
 $_validHost
 
 $_socket
 
 $_request
 
 $_response
 
 $_template = '%d%s'
 

Detailed Description

Definition at line 50 of file Abstract.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $host = '127.0.0.1',
  $port = null 
)

Constructor.

Parameters
string$hostOPTIONAL Hostname of remote connection (default: 127.0.0.1)
integer$portOPTIONAL Port number (default: null)
Exceptions
Zend_Mail_Protocol_Exception
Returns
void
See also
Zend_Mail_Protocol_Exception

Definition at line 135 of file Abstract.php.

136  {
137  $this->_validHost = new Zend_Validate();
138  $this->_validHost->addValidator(new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL));
139 
140  if (!$this->_validHost->isValid($host)) {
144  #require_once 'Zend/Mail/Protocol/Exception.php';
145  throw new Zend_Mail_Protocol_Exception(join(', ', $this->_validHost->getMessages()));
146  }
147 
148  $this->_host = $host;
149  $this->_port = $port;
150  }

◆ __destruct()

__destruct ( )

Class destructor to cleanup open resources

Returns
void

Definition at line 158 of file Abstract.php.

159  {
160  $this->_disconnect();
161  }

Member Function Documentation

◆ _addLog()

_addLog (   $value)
protected

Add the transaction log

Parameters
stringnew transaction
Returns
void

Definition at line 243 of file Abstract.php.

244  {
245  if ($this->_maximumLog >= 0 && count($this->_log) >= $this->_maximumLog) {
246  array_shift($this->_log);
247  }
248 
249  $this->_log[] = $value;
250  }
$value
Definition: gender.phtml:16

◆ _connect()

_connect (   $remote)
protected

Connect to the server using the supplied transport and target

An example $remote string may be 'tcp://mail.example.com:25' or 'ssh://hostname.com:2222'

Parameters
string$remoteRemote
Exceptions
Zend_Mail_Protocol_Exception
Returns
boolean
See also
Zend_Mail_Protocol_Exception
Zend_Mail_Protocol_Exception

Definition at line 261 of file Abstract.php.

262  {
263  $errorNum = 0;
264  $errorStr = '';
265 
266  // open connection
267  $this->_socket = @stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
268 
269  if ($this->_socket === false) {
270  if ($errorNum == 0) {
271  $errorStr = 'Could not open socket';
272  }
276  #require_once 'Zend/Mail/Protocol/Exception.php';
277  throw new Zend_Mail_Protocol_Exception($errorStr);
278  }
279 
280  if (($result = $this->_setStreamTimeout(self::TIMEOUT_CONNECTION)) === false) {
284  #require_once 'Zend/Mail/Protocol/Exception.php';
285  throw new Zend_Mail_Protocol_Exception('Could not set stream timeout');
286  }
287 
288  return $result;
289  }

◆ _disconnect()

_disconnect ( )
protected

Disconnect from remote host and free resource

Returns
void

Definition at line 297 of file Abstract.php.

298  {
299  if (is_resource($this->_socket)) {
300  fclose($this->_socket);
301  }
302  }

◆ _expect()

_expect (   $code,
  $timeout = null 
)
protected

Parse server response for successful codes

Read the response from the stream and check for expected return code. Throws a Zend_Mail_Protocol_Exception if an unexpected code is returned.

Parameters
string | array$codeOne or more codes that indicate a successful response
Exceptions
Zend_Mail_Protocol_Exception
Returns
string Last line of response string
See also
Zend_Mail_Protocol_Exception

Definition at line 402 of file Abstract.php.

403  {
404  $this->_response = array();
405  $cmd = '';
406  $more = '';
407  $msg = '';
408  $errMsg = '';
409 
410  if (!is_array($code)) {
411  $code = array($code);
412  }
413 
414  do {
415  $this->_response[] = $result = $this->_receive($timeout);
416  list($cmd, $more, $msg) = preg_split('/([\s-]+)/', $result, 2, PREG_SPLIT_DELIM_CAPTURE);
417 
418  if ($errMsg !== '') {
419  $errMsg .= ' ' . $msg;
420  } elseif ($cmd === null || !in_array($cmd, $code)) {
421  $errMsg = $msg;
422  }
423 
424  } while (strpos($more, '-') === 0); // The '-' message prefix indicates an information string instead of a response string.
425 
426  if ($errMsg !== '') {
430  #require_once 'Zend/Mail/Protocol/Exception.php';
431  throw new Zend_Mail_Protocol_Exception($errMsg, $cmd);
432  }
433 
434  return $msg;
435  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
_receive($timeout=null)
Definition: Abstract.php:348
$code
Definition: info.phtml:12

◆ _receive()

_receive (   $timeout = null)
protected
See also
Zend_Mail_Protocol_Exception
Zend_Mail_Protocol_Exception
Zend_Mail_Protocol_Exception

Definition at line 348 of file Abstract.php.

349  {
350  if (!is_resource($this->_socket)) {
354  #require_once 'Zend/Mail/Protocol/Exception.php';
355  throw new Zend_Mail_Protocol_Exception('No connection has been established to ' . $this->_host);
356  }
357 
358  // Adapters may wish to supply per-commend timeouts according to appropriate RFC
359  if ($timeout !== null) {
360  $this->_setStreamTimeout($timeout);
361  }
362 
363  // Retrieve response
364  $reponse = fgets($this->_socket, 1024);
365 
366  // Save request to internal log
367  $this->_addLog($reponse);
368 
369  // Check meta data to ensure connection is still valid
370  $info = stream_get_meta_data($this->_socket);
371 
372  if (!empty($info['timed_out'])) {
376  #require_once 'Zend/Mail/Protocol/Exception.php';
377  throw new Zend_Mail_Protocol_Exception($this->_host . ' has timed out');
378  }
379 
380  if ($reponse === false) {
384  #require_once 'Zend/Mail/Protocol/Exception.php';
385  throw new Zend_Mail_Protocol_Exception('Could not read from ' . $this->_host);
386  }
387 
388  return $reponse;
389  }
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ _send()

_send (   $request)
protected

Send the given request followed by a LINEEND to the server.

Parameters
string$request
Exceptions
Zend_Mail_Protocol_Exception
Returns
integer|boolean Number of bytes written to remote host
See also
Zend_Mail_Protocol_Exception
Zend_Mail_Protocol_Exception

Definition at line 312 of file Abstract.php.

313  {
314  if (!is_resource($this->_socket)) {
318  #require_once 'Zend/Mail/Protocol/Exception.php';
319  throw new Zend_Mail_Protocol_Exception('No connection has been established to ' . $this->_host);
320  }
321 
322  $this->_request = $request;
323 
324  $result = fwrite($this->_socket, $request . self::EOL);
325 
326  // Save request to internal log
327  $this->_addLog($request . self::EOL);
328 
329  if ($result === false) {
333  #require_once 'Zend/Mail/Protocol/Exception.php';
334  throw new Zend_Mail_Protocol_Exception('Could not send request to ' . $this->_host);
335  }
336 
337  return $result;
338  }

◆ _setStreamTimeout()

_setStreamTimeout (   $timeout)
protected

Set stream timeout

Parameters
integer$timeout
Returns
boolean

Definition at line 443 of file Abstract.php.

444  {
445  return stream_set_timeout($this->_socket, $timeout);
446  }

◆ connect()

connect ( )
abstract

Create a connection to the remote host

Concrete adapters for this class will implement their own unique connect scripts, using the _connect() method to create the socket resource.

◆ getLog()

getLog ( )

Retrieve the transaction log

Returns
string

Definition at line 221 of file Abstract.php.

222  {
223  return implode('', $this->_log);
224  }

◆ getMaximumLog()

getMaximumLog ( )

Get the maximum log size

Returns
int the maximum log size

Definition at line 180 of file Abstract.php.

181  {
182  return $this->_maximumLog;
183  }

◆ getRequest()

getRequest ( )

Retrieve the last client request

Returns
string

Definition at line 199 of file Abstract.php.

200  {
201  return $this->_request;
202  }

◆ getResponse()

getResponse ( )

Retrieve the last server response

Returns
array

Definition at line 210 of file Abstract.php.

211  {
212  return $this->_response;
213  }

◆ resetLog()

resetLog ( )

Reset the transaction log

Returns
void

Definition at line 232 of file Abstract.php.

233  {
234  $this->_log = array();
235  }

◆ setMaximumLog()

setMaximumLog (   $maximumLog)

Set the maximum log size

Parameters
integer$maximumLogMaximum log size
Returns
void

Definition at line 169 of file Abstract.php.

170  {
171  $this->_maximumLog = (int) $maximumLog;
172  }

Field Documentation

◆ $_host

$_host
protected

Definition at line 74 of file Abstract.php.

◆ $_maximumLog

$_maximumLog = 64
protected

Definition at line 67 of file Abstract.php.

◆ $_port

$_port
protected

Definition at line 81 of file Abstract.php.

◆ $_request

$_request
protected

Definition at line 102 of file Abstract.php.

◆ $_response

$_response
protected

Definition at line 109 of file Abstract.php.

◆ $_socket

$_socket
protected

Definition at line 95 of file Abstract.php.

◆ $_template

$_template = '%d%s'
protected

Definition at line 117 of file Abstract.php.

◆ $_validHost

$_validHost
protected

Definition at line 88 of file Abstract.php.

◆ EOL

const EOL = "\r\n"

Mail default EOL string

Definition at line 55 of file Abstract.php.

◆ TIMEOUT_CONNECTION

const TIMEOUT_CONNECTION = 30

Default timeout in seconds for initiating session

Definition at line 61 of file Abstract.php.


The documentation for this class was generated from the following file: