Access.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Oauth
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /** Zend_Oauth_Token */
  22. #require_once 'Zend/Oauth/Token.php';
  23. /** Zend_Oauth_Http */
  24. #require_once 'Zend/Oauth/Http.php';
  25. /** Zend_Uri_Http */
  26. #require_once 'Zend/Uri/Http.php';
  27. /** Zend_Oauth_Client */
  28. #require_once 'Zend/Oauth/Client.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Oauth
  32. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Oauth_Token_Access extends Zend_Oauth_Token
  36. {
  37. /**
  38. * Cast to HTTP header
  39. *
  40. * @param string $url
  41. * @param Zend_Oauth_Config_ConfigInterface $config
  42. * @param null|array $customParams
  43. * @param null|string $realm
  44. * @return string
  45. */
  46. public function toHeader(
  47. $url, Zend_Oauth_Config_ConfigInterface $config, array $customParams = null, $realm = null
  48. ) {
  49. if (!Zend_Uri::check($url)) {
  50. #require_once 'Zend/Oauth/Exception.php';
  51. throw new Zend_Oauth_Exception(
  52. '\'' . $url . '\' is not a valid URI'
  53. );
  54. }
  55. $params = $this->_httpUtility->assembleParams($url, $config, $customParams);
  56. return $this->_httpUtility->toAuthorizationHeader($params, $realm);
  57. }
  58. /**
  59. * Cast to HTTP query string
  60. *
  61. * @param mixed $url
  62. * @param Zend_Oauth_Config_ConfigInterface $config
  63. * @param null|array $params
  64. * @return string
  65. */
  66. public function toQueryString($url, Zend_Oauth_Config_ConfigInterface $config, array $params = null)
  67. {
  68. if (!Zend_Uri::check($url)) {
  69. #require_once 'Zend/Oauth/Exception.php';
  70. throw new Zend_Oauth_Exception(
  71. '\'' . $url . '\' is not a valid URI'
  72. );
  73. }
  74. $params = $this->_httpUtility->assembleParams($url, $config, $params);
  75. return $this->_httpUtility->toEncodedQueryString($params);
  76. }
  77. /**
  78. * Get OAuth client
  79. *
  80. * @param array $oauthOptions
  81. * @param null|string $uri
  82. * @param null|array|Zend_Config $config
  83. * @param bool $excludeCustomParamsFromHeader
  84. * @return Zend_Oauth_Client
  85. */
  86. public function getHttpClient(array $oauthOptions, $uri = null, $config = null, $excludeCustomParamsFromHeader = true)
  87. {
  88. $client = new Zend_Oauth_Client($oauthOptions, $uri, $config, $excludeCustomParamsFromHeader);
  89. $client->setToken($this);
  90. return $client;
  91. }
  92. }