Oauth.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_Http_Client */
  22. #require_once 'Zend/Http/Client.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Oauth
  26. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. class Zend_Oauth
  30. {
  31. const REQUEST_SCHEME_HEADER = 'header';
  32. const REQUEST_SCHEME_POSTBODY = 'postbody';
  33. const REQUEST_SCHEME_QUERYSTRING = 'querystring';
  34. const GET = 'GET';
  35. const POST = 'POST';
  36. const PUT = 'PUT';
  37. const DELETE = 'DELETE';
  38. const HEAD = 'HEAD';
  39. const OPTIONS = 'OPTIONS';
  40. /**
  41. * Singleton instance if required of the HTTP client
  42. *
  43. * @var Zend_Http_Client
  44. */
  45. protected static $httpClient = null;
  46. /**
  47. * Allows the external environment to make Zend_Oauth use a specific
  48. * Client instance.
  49. *
  50. * @param Zend_Http_Client $httpClient
  51. * @return void
  52. */
  53. public static function setHttpClient(Zend_Http_Client $httpClient)
  54. {
  55. self::$httpClient = $httpClient;
  56. }
  57. /**
  58. * Return the singleton instance of the HTTP Client. Note that
  59. * the instance is reset and cleared of previous parameters and
  60. * Authorization header values.
  61. *
  62. * @return Zend_Http_Client
  63. */
  64. public static function getHttpClient()
  65. {
  66. if (!isset(self::$httpClient)) {
  67. self::$httpClient = new Zend_Http_Client;
  68. } else {
  69. self::$httpClient->setHeaders('Authorization', null);
  70. self::$httpClient->resetParameters();
  71. }
  72. return self::$httpClient;
  73. }
  74. /**
  75. * Simple mechanism to delete the entire singleton HTTP Client instance
  76. * which forces an new instantiation for subsequent requests.
  77. *
  78. * @return void
  79. */
  80. public static function clearHttpClient()
  81. {
  82. self::$httpClient = null;
  83. }
  84. }