Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Http_Client_Adapter_Test Class Reference
Inheritance diagram for Zend_Http_Client_Adapter_Test:
Zend_Http_Client_Adapter_Interface

Public Member Functions

 __construct ()
 
 setNextRequestWillFail ($flag)
 
 setConfig ($config=array())
 
 connect ($host, $port=80, $secure=false)
 
 write ($method, $uri, $http_ver='1.1', $headers=array(), $body='')
 
 read ()
 
 close ()
 
 setResponse ($response)
 
 addResponse ($response)
 
 setResponseIndex ($index)
 
 getConfig ()
 

Protected Attributes

 $config = array()
 
 $responses = array("HTTP/1.1 400 Bad Request\r\n\r\n")
 
 $responseIndex = 0
 
 $_nextRequestWillFail = false
 

Detailed Description

Definition at line 50 of file Test.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Adapter constructor, currently empty. Config is set using setConfig()

Definition at line 85 of file Test.php.

86  { }

Member Function Documentation

◆ addResponse()

addResponse (   $response)

Add another response to the response buffer.

Parameters
stringZend_Http_Response|$response

Definition at line 214 of file Test.php.

215  {
216  if ($response instanceof Zend_Http_Response) {
217  $response = $response->asString("\r\n");
218  }
219 
220  $this->responses[] = $response;
221  }
$response
Definition: 404.php:11

◆ close()

close ( )

Close the connection (dummy)

Implements Zend_Http_Client_Adapter_Interface.

Definition at line 191 of file Test.php.

192  { }

◆ connect()

connect (   $host,
  $port = 80,
  $secure = false 
)

Connect to the remote server

Parameters
string$host
int$port
boolean$secure
int$timeout
Exceptions
Zend_Http_Client_Adapter_Exception

Implements Zend_Http_Client_Adapter_Interface.

Definition at line 133 of file Test.php.

134  {
135  if ($this->_nextRequestWillFail) {
136  $this->_nextRequestWillFail = false;
137  #require_once 'Zend/Http/Client/Adapter/Exception.php';
138  throw new Zend_Http_Client_Adapter_Exception('Request failed');
139  }
140  }

◆ getConfig()

getConfig ( )

Retrieve the array of all configuration options

Returns
array

Definition at line 244 of file Test.php.

245  {
246  return $this->config;
247  }

◆ read()

read ( )

Return the response set in $this->setResponse()

Returns
string

Implements Zend_Http_Client_Adapter_Interface.

Definition at line 179 of file Test.php.

180  {
181  if ($this->responseIndex >= count($this->responses)) {
182  $this->responseIndex = 0;
183  }
184  return $this->responses[$this->responseIndex++];
185  }

◆ setConfig()

setConfig (   $config = array())

Set the configuration array for the adapter

Parameters
Zend_Config  |  array$config

Implements Zend_Http_Client_Adapter_Interface.

Definition at line 106 of file Test.php.

107  {
108  if ($config instanceof Zend_Config) {
109  $config = $config->toArray();
110 
111  } elseif (! is_array($config)) {
112  #require_once 'Zend/Http/Client/Adapter/Exception.php';
114  'Array or Zend_Config object expected, got ' . gettype($config)
115  );
116  }
117 
118  foreach ($config as $k => $v) {
119  $this->config[strtolower($k)] = $v;
120  }
121  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ setNextRequestWillFail()

setNextRequestWillFail (   $flag)

Set the nextRequestWillFail flag

Parameters
boolean$flag
Returns
Zend_Http_Client_Adapter_Test

Definition at line 94 of file Test.php.

95  {
96  $this->_nextRequestWillFail = (bool) $flag;
97 
98  return $this;
99  }

◆ setResponse()

setResponse (   $response)

Set the HTTP response(s) to be returned by this adapter

Parameters
Zend_Http_Response | array | string$response

Definition at line 199 of file Test.php.

200  {
201  if ($response instanceof Zend_Http_Response) {
202  $response = $response->asString("\r\n");
203  }
204 
205  $this->responses = (array)$response;
206  $this->responseIndex = 0;
207  }
$response
Definition: 404.php:11

◆ setResponseIndex()

setResponseIndex (   $index)

Sets the position of the response buffer. Selects which response will be returned on the next call to read().

Parameters
integer$index

Definition at line 229 of file Test.php.

230  {
231  if ($index < 0 || $index >= count($this->responses)) {
232  #require_once 'Zend/Http/Client/Adapter/Exception.php';
234  'Index out of range of response buffer size');
235  }
236  $this->responseIndex = $index;
237  }
$index
Definition: list.phtml:44

◆ write()

write (   $method,
  $uri,
  $http_ver = '1.1',
  $headers = array(),
  $body = '' 
)

Send request to the remote server

Parameters
string$method
Zend_Uri_Http$uri
string$http_ver
array$headers
string$body
Returns
string Request as string

Implements Zend_Http_Client_Adapter_Interface.

Definition at line 152 of file Test.php.

153  {
154  $host = $uri->getHost();
155  $host = (strtolower($uri->getScheme()) == 'https' ? 'sslv2://' . $host : $host);
156 
157  // Build request headers
158  $path = $uri->getPath();
159  if ($uri->getQuery()) $path .= '?' . $uri->getQuery();
160  $request = "{$method} {$path} HTTP/{$http_ver}\r\n";
161  foreach ($headers as $k => $v) {
162  if (is_string($k)) $v = ucfirst($k) . ": $v";
163  $request .= "$v\r\n";
164  }
165 
166  // Add the request body
167  $request .= "\r\n" . $body;
168 
169  // Do nothing - just return the request as string
170 
171  return $request;
172  }

Field Documentation

◆ $_nextRequestWillFail

$_nextRequestWillFail = false
protected

Definition at line 79 of file Test.php.

◆ $config

$config = array()
protected

Definition at line 57 of file Test.php.

◆ $responseIndex

$responseIndex = 0
protected

Definition at line 72 of file Test.php.

◆ $responses

$responses = array("HTTP/1.1 400 Bad Request\r\n\r\n")
protected

Definition at line 65 of file Test.php.


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