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