Extension.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * An interface for OpenID extensions.
  4. *
  5. * @package OpenID
  6. */
  7. /**
  8. * Require the Message implementation.
  9. */
  10. require_once 'Auth/OpenID/Message.php';
  11. /**
  12. * A base class for accessing extension request and response data for
  13. * the OpenID 2 protocol.
  14. *
  15. * @package OpenID
  16. */
  17. class Auth_OpenID_Extension {
  18. /**
  19. * ns_uri: The namespace to which to add the arguments for this
  20. * extension
  21. */
  22. var $ns_uri = null;
  23. var $ns_alias = null;
  24. /**
  25. * Get the string arguments that should be added to an OpenID
  26. * message for this extension.
  27. */
  28. function getExtensionArgs()
  29. {
  30. return null;
  31. }
  32. /**
  33. * Add the arguments from this extension to the provided message.
  34. *
  35. * Returns the message with the extension arguments added.
  36. */
  37. function toMessage($message, $request = null)
  38. {
  39. $implicit = $message->isOpenID1();
  40. $added = $message->namespaces->addAlias($this->ns_uri,
  41. $this->ns_alias,
  42. $implicit);
  43. if ($added === null) {
  44. if ($message->namespaces->getAlias($this->ns_uri) !=
  45. $this->ns_alias) {
  46. return null;
  47. }
  48. }
  49. if ($request !== null) {
  50. $message->updateArgs($this->ns_uri,
  51. $this->getExtensionArgs($request));
  52. } else {
  53. $message->updateArgs($this->ns_uri,
  54. $this->getExtensionArgs());
  55. }
  56. return $message;
  57. }
  58. }