Oauth.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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-2010 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-2010 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. /**
  39. * Singleton instance if required of the HTTP client
  40. *
  41. * @var Zend_Http_Client
  42. */
  43. protected static $httpClient = null;
  44. /**
  45. * Allows the external environment to make Zend_Oauth use a specific
  46. * Client instance.
  47. *
  48. * @param Zend_Http_Client $httpClient
  49. * @return void
  50. */
  51. public static function setHttpClient(Zend_Http_Client $httpClient)
  52. {
  53. self::$httpClient = $httpClient;
  54. }
  55. /**
  56. * Return the singleton instance of the HTTP Client. Note that
  57. * the instance is reset and cleared of previous parameters and
  58. * Authorization header values.
  59. *
  60. * @return Zend_Http_Client
  61. */
  62. public static function getHttpClient()
  63. {
  64. if (!isset(self::$httpClient)) {
  65. self::$httpClient = new Zend_Http_Client;
  66. } else {
  67. self::$httpClient->setHeaders('Authorization', null);
  68. self::$httpClient->resetParameters();
  69. }
  70. return self::$httpClient;
  71. }
  72. /**
  73. * Simple mechanism to delete the entire singleton HTTP Client instance
  74. * which forces an new instantiation for subsequent requests.
  75. *
  76. * @return void
  77. */
  78. public static function clearHttpClient()
  79. {
  80. self::$httpClient = null;
  81. }
  82. }