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

Public Member Functions

 __construct (Zend_Oauth_Consumer $consumer, array $parameters=null, Zend_Oauth_Http_Utility $utility=null)
 
 setMethod ($method)
 
 getMethod ()
 
 setParameters (array $customServiceParameters)
 
 getParameters ()
 
 getConsumer ()
 
 startRequestCycle (array $params)
 
 getRequestSchemeQueryStringClient (array $params, $url)
 

Protected Member Functions

 _assessRequestAttempt (Zend_Http_Response $response=null)
 
 _toAuthorizationHeader (array $params, $realm=null)
 

Protected Attributes

 $_parameters = array()
 
 $_consumer = null
 
 $_preferredRequestScheme = null
 
 $_preferredRequestMethod = Zend_Oauth::POST
 
 $_httpUtility = null
 

Detailed Description

Definition at line 34 of file Http.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Zend_Oauth_Consumer  $consumer,
array  $parameters = null,
Zend_Oauth_Http_Utility  $utility = null 
)

Constructor

Parameters
Zend_Oauth_Consumer$consumer
null | array$parameters
null | Zend_Oauth_Http_Utility$utility
Returns
void

Definition at line 82 of file Http.php.

86  {
87  $this->_consumer = $consumer;
88  $this->_preferredRequestScheme = $this->_consumer->getRequestScheme();
89  if ($parameters !== null) {
90  $this->setParameters($parameters);
91  }
92  if ($utility !== null) {
93  $this->_httpUtility = $utility;
94  } else {
95  $this->_httpUtility = new Zend_Oauth_Http_Utility;
96  }
97  }
setParameters(array $customServiceParameters)
Definition: Http.php:131

Member Function Documentation

◆ _assessRequestAttempt()

_assessRequestAttempt ( Zend_Http_Response  $response = null)
protected

Manages the switch from OAuth request scheme to another lower preference scheme during a request cycle.

Parameters
Zend_Http_Response
Returns
void
Exceptions
Zend_Oauth_Exceptionif unable to retrieve valid token response

Definition at line 223 of file Http.php.

224  {
225  switch ($this->_preferredRequestScheme) {
227  $this->_preferredRequestScheme = Zend_Oauth::REQUEST_SCHEME_POSTBODY;
228  break;
230  $this->_preferredRequestScheme = Zend_Oauth::REQUEST_SCHEME_QUERYSTRING;
231  break;
232  default:
233  #require_once 'Zend/Oauth/Exception.php';
234  throw new Zend_Oauth_Exception(
235  'Could not retrieve a valid Token response from Token URL:'
236  . ($response !== null
237  ? PHP_EOL . $response->getBody()
238  : ' No body - check for headers')
239  );
240  }
241  }
$response
Definition: 404.php:11
const REQUEST_SCHEME_HEADER
Definition: Oauth.php:33
const REQUEST_SCHEME_QUERYSTRING
Definition: Oauth.php:35
const REQUEST_SCHEME_POSTBODY
Definition: Oauth.php:34

◆ _toAuthorizationHeader()

_toAuthorizationHeader ( array  $params,
  $realm = null 
)
protected

Generates a valid OAuth Authorization header based on the provided parameters and realm.

Parameters
array$params
string$realm
Returns
string

Definition at line 251 of file Http.php.

252  {
253  $headerValue = array();
254  $headerValue[] = 'OAuth realm="' . $realm . '"';
255  foreach ($params as $key => $value) {
256  if (!preg_match("/^oauth_/", $key)) {
257  continue;
258  }
259  $headerValue[] = Zend_Oauth_Http_Utility::urlEncode($key)
260  . '="'
262  . '"';
263  }
264  return implode(",", $headerValue);
265  }
static urlEncode($value)
Definition: Utility.php:211
$value
Definition: gender.phtml:16
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getConsumer()

getConsumer ( )

Return the Consumer instance in use.

Returns
Zend_Oauth_Consumer

Definition at line 152 of file Http.php.

153  {
154  return $this->_consumer;
155  }

◆ getMethod()

getMethod ( )

Preferred HTTP request method accessor.

Returns
string

Definition at line 120 of file Http.php.

121  {
123  }
$_preferredRequestMethod
Definition: Http.php:65

◆ getParameters()

getParameters ( )

Accessor for an array of custom parameters.

Returns
array

Definition at line 142 of file Http.php.

143  {
144  return $this->_parameters;
145  }

◆ getRequestSchemeQueryStringClient()

getRequestSchemeQueryStringClient ( array  $params,
  $url 
)

Return an instance of Zend_Http_Client configured to use the Query String scheme for an OAuth driven HTTP request.

Parameters
array$params
string$url
Returns
Zend_Http_Client

Definition at line 204 of file Http.php.

205  {
206  $client = Zend_Oauth::getHttpClient();
207  $client->setUri($url);
208  $client->getUri()->setQuery(
209  $this->_httpUtility->toEncodedQueryString($params)
210  );
211  $client->setMethod($this->_preferredRequestMethod);
212  return $client;
213  }
static getHttpClient()
Definition: Oauth.php:69
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ setMethod()

setMethod (   $method)

Set a preferred HTTP request method.

Parameters
string$method
Returns
Zend_Oauth_Http

Definition at line 105 of file Http.php.

106  {
107  if (!in_array($method, array(Zend_Oauth::POST, Zend_Oauth::GET))) {
108  #require_once 'Zend/Oauth/Exception.php';
109  throw new Zend_Oauth_Exception('invalid HTTP method: ' . $method);
110  }
111  $this->_preferredRequestMethod = $method;
112  return $this;
113  }
const POST
Definition: Oauth.php:37
$method
Definition: info.phtml:13
const GET
Definition: Oauth.php:36

◆ setParameters()

setParameters ( array  $customServiceParameters)

Mutator to set an array of custom parameters for the HTTP request.

Parameters
array$customServiceParameters
Returns
Zend_Oauth_Http

Definition at line 131 of file Http.php.

132  {
133  $this->_parameters = $customServiceParameters;
134  return $this;
135  }

◆ startRequestCycle()

startRequestCycle ( array  $params)

Commence a request cycle where the current HTTP method and OAuth request scheme set an upper preferred HTTP request style and where failures generate a new HTTP request style further down the OAuth preference list for OAuth Request Schemes. On success, return the Request object that results for processing.

Parameters
array$params
Returns
Zend_Http_Response
Exceptions
Zend_Oauth_Exceptionon HTTP request errors
Todo:
Remove cycling?; Replace with upfront do-or-die configuration

Definition at line 169 of file Http.php.

170  {
171  $response = null;
172  $body = null;
173  $status = null;
174  try {
175  $response = $this->_attemptRequest($params);
176  } catch (Zend_Http_Client_Exception $e) {
177  #require_once 'Zend/Oauth/Exception.php';
178  throw new Zend_Oauth_Exception('Error in HTTP request', null, $e);
179  }
180  if ($response !== null) {
181  $body = $response->getBody();
182  $status = $response->getStatus();
183  }
184  if ($response === null // Request failure/exception
185  || $status == 500 // Internal Server Error
186  || $status == 400 // Bad Request
187  || $status == 401 // Unauthorized
188  || empty($body) // Missing token
189  ) {
192  }
193  return $response;
194  }
$response
Definition: 404.php:11
_assessRequestAttempt(Zend_Http_Response $response=null)
Definition: Http.php:223
startRequestCycle(array $params)
Definition: Http.php:169
$status
Definition: order_status.php:8
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

Field Documentation

◆ $_consumer

$_consumer = null
protected

Definition at line 49 of file Http.php.

◆ $_httpUtility

$_httpUtility = null
protected

Definition at line 72 of file Http.php.

◆ $_parameters

$_parameters = array()
protected

Definition at line 42 of file Http.php.

◆ $_preferredRequestMethod

$_preferredRequestMethod = Zend_Oauth::POST
protected

Definition at line 65 of file Http.php.

◆ $_preferredRequestScheme

$_preferredRequestScheme = null
protected

Definition at line 58 of file Http.php.


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