Source for file Message.php
Documentation is available at Message.php
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2009 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
require_once 'OpenID.php';
require_once 'OpenID/Message/Exception.php';
* A class that handles any OpenID protocol messages, as described in section 4.1 of
* the {@link http://openid.net/specs/openid-authentication-2_0.html#anchor4}
* OpenID 2.0 spec}. You can set or get messages in one of 3 formats: Key Value
* (KV), Array, or HTTP. KV is described in the spec (4.1.1 of the 2.0 spec), HTTP
* is urlencoded key value pairs, as you would see them in a query string or an HTTP
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2009 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
const FORMAT_HTTP =
'HTTP';
const FORMAT_ARRAY =
'ARRAY';
protected $data =
array();
* Optionally instanciates this object with the contents of an OpenID message.
* @param mixed $message Message contents
* @param string $format Source message format (KV, HTTP, or ARRAY)
public function __construct($message =
null, $format =
self::FORMAT_ARRAY)
* Gets the value of any key in this message.
* @param string $name Name of key
* @return mixed Value of key if set, defaults to null
public function get($name)
if (isset
($this->data[$name])) {
return $this->data[$name];
* Sets a message key value.
* @param string $name Key name
* @param mixed $val Key value
public function set($name, $val)
if ($name ==
'openid.ns' &&
$val !=
OpenID::NS_2_0) {
$this->data[$name] =
$val;
* Deletes a key from a message
* @param string $name Key name
unset
($this->data[$name]);
* Gets the current message in KV format
* Gets the current message in HTTP (url encoded) format
* Gets the current message in ARRAY format
* Gets the message in one of three formats:
* OpenID_Message::FORMAT_ARRAY (default)
* OpenID_Message::FORMAT_KV (KV pairs, OpenID response format)
* OpenID_Message::FORMAT_HTTP (url encoded pairs, for use in a query string)
* @param string $format One of the above three formats
* @throws OpenID_Message_Exception When passed an invalid format argument
* @return mixed array, kv string, or url query string paramters
public function getMessage($format =
self::FORMAT_ARRAY)
if ($format ===
self::FORMAT_ARRAY) {
if ($format ===
self::FORMAT_HTTP) {
foreach ($this->data as $k =>
$v) {
if ($format ===
self::FORMAT_KV) {
foreach ($this->data as $k =>
$v) {
* Sets message contents. Wipes out any existing message contents. Default
* source format is Array, but you can also use KV and HTTP formats.
* @param mixed $message Source message
* @param mixed $format Source message format (OpenID_Message::FORMAT_KV,
* OpenID_Message::FORMAT_ARRAY,
* OpenID_Message::FORMAT_HTTP)
public function setMessage($message, $format =
self::FORMAT_ARRAY)
if ($format ==
self::FORMAT_ARRAY) {
foreach ($message as $k =>
$v) {
if ($format ==
self::FORMAT_KV) {
foreach ($lines as $line) {
list
($key, $value) =
explode(':', $line, 2);
$this->set($key, $value);
if ($format ==
self::FORMAT_HTTP) {
foreach ($array as $pair) {
list
($key, $value) =
explode('=', $pair, 2);
* Adds an extension to an OpenID_Message object.
* @param OpenID_Extension $extension Instance of OpenID_Extension
$extension->toMessage($this);
Documentation generated on Tue, 15 Dec 2009 19:00:55 -0800 by phpDocumentor 1.4.3