summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortailor <cygnus@janrain.com>2007-10-16 20:15:56 +0000
committertailor <cygnus@janrain.com>2007-10-16 20:15:56 +0000
commitc0a45e443054d8fc9e67b7c88a121c2e9f0ab68e (patch)
treea250b6276fcb700fc621f06738b36f4953744dc5
parentb4a2eda736995f1ae9d23171fcce753cd85b786a (diff)
downloadphp-openid-c0a45e443054d8fc9e67b7c88a121c2e9f0ab68e.zip
php-openid-c0a45e443054d8fc9e67b7c88a121c2e9f0ab68e.tar.gz
php-openid-c0a45e443054d8fc9e67b7c88a121c2e9f0ab68e.tar.bz2
[project @ Add support for openid.ax.count.ALIAS="unlimited"]
-rw-r--r--Auth/OpenID/AX.php29
-rw-r--r--Tests/Auth/OpenID/AX.php28
2 files changed, 54 insertions, 3 deletions
diff --git a/Auth/OpenID/AX.php b/Auth/OpenID/AX.php
index 4ca27f0..715c3d8 100644
--- a/Auth/OpenID/AX.php
+++ b/Auth/OpenID/AX.php
@@ -11,6 +11,10 @@ require_once "Auth/OpenID/Message.php";
define('Auth_OpenID_AX_NS_URI',
'http://openid.net/srv/ax/1.0');
+// Use this as the 'count' value for an attribute in a FetchRequest to
+// ask for as many values as the OP can provide.
+define('Auth_OpenID_AX_UNLIMITED_VALUES', 'unlimited');
+
class Auth_OpenID_AX {
function isError($thing)
{
@@ -150,6 +154,18 @@ class Auth_OpenID_AX_AttrInfo {
return new Auth_OpenID_AX_AttrInfo($type_uri, $count, $required,
$alias);
}
+
+ /*
+ * When processing a request for this attribute, the OP should
+ * call this method to determine whether all available attribute
+ * values were requested. If self.count == UNLIMITED_VALUES, this
+ * returns True. Otherwise this returns False, in which case
+ * self.count is an integer.
+ */
+ function wantsUnlimitedValues()
+ {
+ return $this->count === Auth_OpenID_AX_UNLIMITED_VALUES;
+ }
}
/*
@@ -364,6 +380,10 @@ class Auth_OpenID_AX_FetchRequest extends Auth_OpenID_AX_Message {
$count_s = Auth_OpenID::arrayGet($ax_args, 'count.' . $alias);
if ($count_s) {
$count = Auth_OpenID::intval($count_s);
+ if (($count === false) &&
+ ($count_s === Auth_OpenID_AX_UNLIMITED_VALUES)) {
+ $count = $count_s;
+ }
} else {
$count = 1;
}
@@ -559,15 +579,18 @@ class Auth_OpenID_AX_KeyValueMessage extends Auth_OpenID_AX_Message {
list($type_uri, $alias) = $pair;
if (array_key_exists('count.' . $alias, $ax_args)) {
- $count_s = $ax_args['count.' . $alias];
+
+ $count_key = 'count.' . $alias;
+ $count_s = $ax_args[$count_key];
$count = Auth_OpenID::intval($count_s);
if ($count === false) {
return new Auth_OpenID_AX_Error(
sprintf("Integer value expected for %s, got %s",
- 'count.' . $alias, $count_s)
- );
+ 'count. %s' . $alias, $count_s,
+ Auth_OpenID_AX_UNLIMITED_VALUES)
+ );
}
$values = array();
diff --git a/Tests/Auth/OpenID/AX.php b/Tests/Auth/OpenID/AX.php
index 96e7cfa..9c9c397 100644
--- a/Tests/Auth/OpenID/AX.php
+++ b/Tests/Auth/OpenID/AX.php
@@ -160,6 +160,34 @@ class ParseAXValuesTest extends PHPUnit_TestCase {
'count.foo' => '1'));
}
+ function test_invalidCountValue()
+ {
+ $msg = new Auth_OpenID_AX_FetchRequest();
+
+ $result = $msg->parseExtensionArgs(
+ array('type.foo' => 'urn:foo',
+ 'count.foo' => 'bogus'));
+
+ $this->assertTrue(Auth_OpenID_AX::isError($result));
+ }
+
+ function test_requestUnlimitedValues()
+ {
+ $msg = new Auth_OpenID_AX_FetchRequest();
+
+ $result = $msg->parseExtensionArgs(
+ array('mode' => 'fetch_request',
+ 'required' => 'foo',
+ 'type.foo' => 'urn:foo',
+ 'count.foo' => Auth_OpenID_AX_UNLIMITED_VALUES));
+
+ $attrs = $msg->iterAttrs();
+ $foo = $attrs[0];
+
+ $this->assertTrue($foo->count == Auth_OpenID_AX_UNLIMITED_VALUES);
+ $this->assertTrue($foo->wantsUnlimitedValues());
+ }
+
function test_countPresentAndIsZero()
{
$this->failUnlessAXValues(