Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Token.php
Go to the documentation of this file.
1 <?php
23 #require_once 'Zend/Oauth/Http/Utility.php';
24 
31 abstract class Zend_Oauth_Token
32 {
36  const TOKEN_PARAM_KEY = 'oauth_token';
37  const TOKEN_SECRET_PARAM_KEY = 'oauth_token_secret';
38  const TOKEN_PARAM_CALLBACK_CONFIRMED = 'oauth_callback_confirmed';
46  protected $_params = array();
47 
53  protected $_response = null;
54 
58  protected $_httpUtility = null;
59 
67  public function __construct(
69  Zend_Oauth_Http_Utility $utility = null
70  ) {
71  if ($response !== null) {
72  $this->_response = $response;
74  if (count($params) > 0) {
75  $this->setParams($params);
76  }
77  }
78  if ($utility !== null) {
79  $this->_httpUtility = $utility;
80  } else {
81  $this->_httpUtility = new Zend_Oauth_Http_Utility;
82  }
83  }
84 
91  public function isValid()
92  {
93  if (isset($this->_params[self::TOKEN_PARAM_KEY])
94  && !empty($this->_params[self::TOKEN_PARAM_KEY])
95  && isset($this->_params[self::TOKEN_SECRET_PARAM_KEY])
96  ) {
97  return true;
98  }
99  return false;
100  }
101 
107  public function getResponse()
108  {
109  return $this->_response;
110  }
111 
119  public function setTokenSecret($secret)
120  {
121  $this->setParam(self::TOKEN_SECRET_PARAM_KEY, $secret);
122  return $this;
123  }
124 
131  public function getTokenSecret()
132  {
133  return $this->getParam(self::TOKEN_SECRET_PARAM_KEY);
134  }
135 
144  public function setParam($key, $value)
145  {
146  $this->_params[$key] = trim($value, "\n");
147  return $this;
148  }
149 
157  public function setParams(array $params)
158  {
159  foreach ($params as $key=>$value) {
160  $this->setParam($key, $value);
161  }
162  return $this;
163  }
164 
171  public function getParam($key)
172  {
173  if (isset($this->_params[$key])) {
174  return $this->_params[$key];
175  }
176  return null;
177  }
178 
185  public function setToken($token)
186  {
187  $this->setParam(self::TOKEN_PARAM_KEY, $token);
188  return $this;
189  }
190 
196  public function getToken()
197  {
198  return $this->getParam(self::TOKEN_PARAM_KEY);
199  }
200 
206  public function __get($key)
207  {
208  return $this->getParam($key);
209  }
210 
218  public function __set($key, $value)
219  {
220  $this->setParam($key, $value);
221  }
222 
228  public function toString()
229  {
230  return $this->_httpUtility->toEncodedQueryString($this->_params);
231  }
232 
239  public function __toString()
240  {
241  return $this->toString();
242  }
243 
252  {
253  $params = array();
254  $body = $response->getBody();
255  if (empty($body)) {
256  return;
257  }
258 
259  // validate body based on acceptable characters...todo
260  $parts = explode('&', $body);
261  foreach ($parts as $kvpair) {
262  $pair = explode('=', $kvpair);
263  $params[rawurldecode($pair[0])] = rawurldecode($pair[1]);
264  }
265  return $params;
266  }
267 
271  public function __sleep()
272  {
273  return array('_params');
274  }
275 
279  public function __wakeup()
280  {
281  if ($this->_httpUtility === null) {
282  $this->_httpUtility = new Zend_Oauth_Http_Utility;
283  }
284  }
285 }
const TOKEN_SECRET_PARAM_KEY
Definition: Token.php:37
$response
Definition: 404.php:11
setTokenSecret($secret)
Definition: Token.php:119
const TOKEN_PARAM_CALLBACK_CONFIRMED
Definition: Token.php:38
setParam($key, $value)
Definition: Token.php:144
setParams(array $params)
Definition: Token.php:157
setToken($token)
Definition: Token.php:185
__set($key, $value)
Definition: Token.php:218
_parseParameters(Zend_Http_Response $response)
Definition: Token.php:251
$value
Definition: gender.phtml:16
const TOKEN_PARAM_KEY
Definition: Token.php:36
getParam($key)
Definition: Token.php:171
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
__construct(Zend_Http_Response $response=null, Zend_Oauth_Http_Utility $utility=null)
Definition: Token.php:67