Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
23 #require_once 'Zend/Oauth.php';
24 
26 #require_once 'Zend/Uri.php';
27 
29 #require_once 'Zend/Oauth/Config/ConfigInterface.php';
30 
38 {
44  protected $_signatureMethod = 'HMAC-SHA1';
45 
54 
63 
69  protected $_version = '1.0';
70 
79  protected $_callbackUrl = null;
80 
86  protected $_siteUrl = null;
87 
94  protected $_requestTokenUrl = null;
95 
102  protected $_accessTokenUrl = null;
103 
110  protected $_authorizeUrl = null;
111 
117  protected $_consumerKey = null;
118 
124  protected $_consumerSecret = null;
125 
132  protected $_rsaPrivateKey = null;
133 
140  protected $_rsaPublicKey = null;
141 
148  protected $_token = null;
149 
155  protected $_realm = null;
156 
164  public function __construct($options = null)
165  {
166  if ($options !== null) {
167  if ($options instanceof Zend_Config) {
168  $options = $options->toArray();
169  }
170  $this->setOptions($options);
171  }
172  }
173 
181  public function setOptions(array $options)
182  {
183  foreach ($options as $key => $value) {
184  switch ($key) {
185  case 'consumerKey':
186  $this->setConsumerKey($value);
187  break;
188  case 'consumerSecret':
189  $this->setConsumerSecret($value);
190  break;
191  case 'signatureMethod':
192  $this->setSignatureMethod($value);
193  break;
194  case 'version':
195  $this->setVersion($value);
196  break;
197  case 'callbackUrl':
198  $this->setCallbackUrl($value);
199  break;
200  case 'siteUrl':
201  $this->setSiteUrl($value);
202  break;
203  case 'requestTokenUrl':
204  $this->setRequestTokenUrl($value);
205  break;
206  case 'accessTokenUrl':
207  $this->setAccessTokenUrl($value);
208  break;
209  case 'userAuthorizationUrl':
211  break;
212  case 'authorizeUrl':
213  $this->setAuthorizeUrl($value);
214  break;
215  case 'requestMethod':
216  $this->setRequestMethod($value);
217  break;
218  case 'rsaPrivateKey':
219  $this->setRsaPrivateKey($value);
220  break;
221  case 'rsaPublicKey':
222  $this->setRsaPublicKey($value);
223  break;
224  case 'realm':
225  $this->setRealm($value);
226  break;
227  }
228  }
229  if (isset($options['requestScheme'])) {
230  $this->setRequestScheme($options['requestScheme']);
231  }
232 
233  return $this;
234  }
235 
242  public function setConsumerKey($key)
243  {
244  $this->_consumerKey = $key;
245  return $this;
246  }
247 
253  public function getConsumerKey()
254  {
255  return $this->_consumerKey;
256  }
257 
264  public function setConsumerSecret($secret)
265  {
266  $this->_consumerSecret = $secret;
267  return $this;
268  }
269 
278  public function getConsumerSecret()
279  {
280  if ($this->_rsaPrivateKey !== null) {
281  return $this->_rsaPrivateKey;
282  }
283  return $this->_consumerSecret;
284  }
285 
293  public function setSignatureMethod($method)
294  {
295  $method = strtoupper($method);
296  if (!in_array($method, array(
297  'HMAC-SHA1', 'HMAC-SHA256', 'RSA-SHA1', 'PLAINTEXT'
298  ))
299  ) {
300  #require_once 'Zend/Oauth/Exception.php';
301  throw new Zend_Oauth_Exception('Unsupported signature method: '
302  . $method
303  . '. Supported are HMAC-SHA1, RSA-SHA1, PLAINTEXT and HMAC-SHA256');
304  }
305  $this->_signatureMethod = $method;;
306  return $this;
307  }
308 
314  public function getSignatureMethod()
315  {
317  }
318 
326  public function setRequestScheme($scheme)
327  {
328  $scheme = strtolower($scheme);
329  if (!in_array($scheme, array(
333  ))
334  ) {
335  #require_once 'Zend/Oauth/Exception.php';
336  throw new Zend_Oauth_Exception(
337  '\'' . $scheme . '\' is an unsupported request scheme'
338  );
339  }
340  if ($scheme == Zend_Oauth::REQUEST_SCHEME_POSTBODY
341  && $this->getRequestMethod() == Zend_Oauth::GET
342  ) {
343  #require_once 'Zend/Oauth/Exception.php';
344  throw new Zend_Oauth_Exception(
345  'Cannot set POSTBODY request method if HTTP method set to GET'
346  );
347  }
348  $this->_requestScheme = $scheme;
349  return $this;
350  }
351 
357  public function getRequestScheme()
358  {
359  return $this->_requestScheme;
360  }
361 
368  public function setVersion($version)
369  {
370  $this->_version = $version;
371  return $this;
372  }
373 
379  public function getVersion()
380  {
381  return $this->_version;
382  }
383 
391  public function setCallbackUrl($url)
392  {
393  if (!Zend_Uri::check($url) && $url !== 'oob') {
394  #require_once 'Zend/Oauth/Exception.php';
395  throw new Zend_Oauth_Exception(
396  '\'' . $url . '\' is not a valid URI'
397  );
398  }
399  $this->_callbackUrl = $url;
400  return $this;
401  }
402 
408  public function getCallbackUrl()
409  {
410  return $this->_callbackUrl;
411  }
412 
420  public function setSiteUrl($url)
421  {
422  if (!Zend_Uri::check($url)) {
423  #require_once 'Zend/Oauth/Exception.php';
424  throw new Zend_Oauth_Exception(
425  '\'' . $url . '\' is not a valid URI'
426  );
427  }
428  $this->_siteUrl = $url;
429  return $this;
430  }
431 
437  public function getSiteUrl()
438  {
439  return $this->_siteUrl;
440  }
441 
449  public function setRequestTokenUrl($url)
450  {
451  if (!Zend_Uri::check($url)) {
452  #require_once 'Zend/Oauth/Exception.php';
453  throw new Zend_Oauth_Exception(
454  '\'' . $url . '\' is not a valid URI'
455  );
456  }
457  $this->_requestTokenUrl = rtrim($url, '/');
458  return $this;
459  }
460 
469  public function getRequestTokenUrl()
470  {
471  if (!$this->_requestTokenUrl && $this->_siteUrl) {
472  return $this->_siteUrl . '/request_token';
473  }
474  return $this->_requestTokenUrl;
475  }
476 
484  public function setAccessTokenUrl($url)
485  {
486  if (!Zend_Uri::check($url)) {
487  #require_once 'Zend/Oauth/Exception.php';
488  throw new Zend_Oauth_Exception(
489  '\'' . $url . '\' is not a valid URI'
490  );
491  }
492  $this->_accessTokenUrl = rtrim($url, '/');
493  return $this;
494  }
495 
504  public function getAccessTokenUrl()
505  {
506  if (!$this->_accessTokenUrl && $this->_siteUrl) {
507  return $this->_siteUrl . '/access_token';
508  }
509  return $this->_accessTokenUrl;
510  }
511 
519  public function setUserAuthorizationUrl($url)
520  {
521  return $this->setAuthorizeUrl($url);
522  }
523 
531  public function setAuthorizeUrl($url)
532  {
533  if (!Zend_Uri::check($url)) {
534  #require_once 'Zend/Oauth/Exception.php';
535  throw new Zend_Oauth_Exception(
536  '\'' . $url . '\' is not a valid URI'
537  );
538  }
539  $this->_authorizeUrl = rtrim($url, '/');
540  return $this;
541  }
542 
548  public function getUserAuthorizationUrl()
549  {
550  return $this->getAuthorizeUrl();
551  }
552 
561  public function getAuthorizeUrl()
562  {
563  if (!$this->_authorizeUrl && $this->_siteUrl) {
564  return $this->_siteUrl . '/authorize';
565  }
566  return $this->_authorizeUrl;
567  }
568 
576  public function setRequestMethod($method)
577  {
578  $method = strtoupper($method);
579  if (!in_array($method, array(
580  Zend_Oauth::GET,
581  Zend_Oauth::POST,
582  Zend_Oauth::PUT,
583  Zend_Oauth::DELETE,
584  Zend_Oauth::OPTIONS,
585  ))
586  ) {
587  #require_once 'Zend/Oauth/Exception.php';
588  throw new Zend_Oauth_Exception('Invalid method: ' . $method);
589  }
590  $this->_requestMethod = $method;
591  return $this;
592  }
593 
599  public function getRequestMethod()
600  {
601  return $this->_requestMethod;
602  }
603 
610  public function setRsaPublicKey(Zend_Crypt_Rsa_Key_Public $key)
611  {
612  $this->_rsaPublicKey = $key;
613  return $this;
614  }
615 
621  public function getRsaPublicKey()
622  {
623  return $this->_rsaPublicKey;
624  }
625 
632  public function setRsaPrivateKey(Zend_Crypt_Rsa_Key_Private $key)
633  {
634  $this->_rsaPrivateKey = $key;
635  return $this;
636  }
637 
643  public function getRsaPrivateKey()
644  {
645  return $this->_rsaPrivateKey;
646  }
647 
654  public function setToken(Zend_Oauth_Token $token)
655  {
656  $this->_token = $token;
657  return $this;
658  }
659 
665  public function getToken()
666  {
667  return $this->_token;
668  }
669 
676  public function setRealm($realm)
677  {
678  $this->_realm = $realm;
679  return $this;
680  }
681 
687  public function getRealm()
688  {
689  return $this->_realm;
690  }
691 }
setSignatureMethod($method)
Definition: Config.php:293
const REQUEST_SCHEME_HEADER
Definition: Oauth.php:33
setConsumerKey($key)
Definition: Config.php:242
const POST
Definition: Oauth.php:37
setVersion($version)
Definition: Config.php:368
setRequestMethod($method)
Definition: Config.php:576
__construct($options=null)
Definition: Config.php:164
setUserAuthorizationUrl($url)
Definition: Config.php:519
setConsumerSecret($secret)
Definition: Config.php:264
setOptions(array $options)
Definition: Config.php:181
setAccessTokenUrl($url)
Definition: Config.php:484
$value
Definition: gender.phtml:16
setRequestScheme($scheme)
Definition: Config.php:326
const REQUEST_SCHEME_QUERYSTRING
Definition: Oauth.php:35
setSiteUrl($url)
Definition: Config.php:420
setRequestTokenUrl($url)
Definition: Config.php:449
setRsaPrivateKey(Zend_Crypt_Rsa_Key_Private $key)
Definition: Config.php:632
$method
Definition: info.phtml:13
setCallbackUrl($url)
Definition: Config.php:391
setAuthorizeUrl($url)
Definition: Config.php:531
setRealm($realm)
Definition: Config.php:676
const REQUEST_SCHEME_POSTBODY
Definition: Oauth.php:34
setRsaPublicKey(Zend_Crypt_Rsa_Key_Public $key)
Definition: Config.php:610