Oauth.php 2.6 KB

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