4 * OpenID protocol key-value/comma-newline format parsing and
9 * LICENSE: See the COPYING file included in this distribution.
13 * @author JanRain, Inc. <openid@janrain.com>
14 * @copyright 2005-2008 Janrain, Inc.
15 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache
19 * Container for key-value/comma-newline OpenID format and parsing
21 class Auth_OpenID_KVForm {
23 * Convert an OpenID colon/newline separated string into an
29 static function toArray($kvs, $strict=false)
31 $lines = explode("\n", $kvs);
33 $last = array_pop($lines);
35 array_push($lines, $last);
43 for ($lineno = 0; $lineno < count($lines); $lineno++) {
44 $line = $lines[$lineno];
45 $kv = explode(':', $line, 2);
46 if (count($kv) != 2) {
63 if ($tval != $value) {
69 $values[$tkey] = $tval;
76 * Convert an array into an OpenID colon/newline separated string
81 static function fromArray($values)
83 if ($values === null) {
90 foreach ($values as $key => $value) {
91 if (is_array($value)) {
92 list($key, $value) = array($value[0], $value[1]);
95 if (strpos($key, ':') !== false) {
99 if (strpos($key, "\n") !== false) {
103 if (strpos($value, "\n") !== false) {
106 $serialized .= "$key:$value\n";