Browse Source

Decouple simple registration extension

tags/0.6
Chris Smith 14 years ago
parent
commit
6febf21cc2
4 changed files with 53 additions and 17 deletions
  1. 3
    0
      examples/basic/index.php
  2. 15
    2
      processor.php
  3. 27
    5
      sreg.ext.php
  4. 8
    10
      urlbuilder.inc.php

+ 3
- 0
examples/basic/index.php View File

@@ -55,6 +55,9 @@
55 55
    define('OPENID_URL', $_POST['openid_type']);
56 56
   }
57 57
 
58
+  // Include the simple registration extension
59
+  require('../../sreg.ext.php');
60
+
58 61
   require('../../processor.php');
59 62
 
60 63
  } else {

+ 15
- 2
processor.php View File

@@ -25,7 +25,6 @@
25 25
  require_once(dirname(__FILE__) . '/logging.inc.php');
26 26
  require_once(dirname(__FILE__) . '/discoverer.inc.php');
27 27
  require_once(dirname(__FILE__) . '/poster.inc.php');
28
- require_once(dirname(__FILE__) . '/sreg.inc.php');
29 28
  require_once(dirname(__FILE__) . '/urlbuilder.inc.php');
30 29
  require_once(dirname(__FILE__) . '/keymanager.inc.php');
31 30
 
@@ -333,7 +332,7 @@
333 332
    error('noauth', 'Provider didn\'t authenticate response');
334 333
   }
335 334
 
336
-  parseSRegResponse();
335
+  Processor::callHandlers();
337 336
   URLBuilder::redirect(); 
338 337
  }
339 338
 
@@ -368,6 +367,20 @@
368 367
   URLBuilder::redirect();
369 368
  }
370 369
 
370
+ class Processor {
371
+
372
+  public static function callHandlers() {
373
+   global $_POIDSY;
374
+
375
+   if (empty($_POIDSY['handlers'])) { return; }
376
+
377
+   foreach ($_POIDSY['handlers'] as $handler) {
378
+    $handler->parseResponse();
379
+   }
380
+  }
381
+
382
+ }
383
+
371 384
  // Here we go!
372 385
  process();
373 386
 ?>

sreg.inc.php → sreg.ext.php View File

@@ -36,13 +36,35 @@
36 36
              . ',' . SREG_DOB . ',' . SREG_GENDER . ',' . SREG_POSTCODE . ','
37 37
              . SREG_COUNTRY . ',' . SREG_LANGUAGE . ', ' . SREG_TIMEZONE);
38 38
 
39
- function parseSRegResponse() {
40
-  foreach (explode(',', SREG_ALL) as $reg) {
41
-   $reg = str_replace('.', '_', $reg);
42
-   if (isset($_REQUEST[$reg])) {
43
-    $_SESSION['openid']['sreg'][substr($reg, 12)] = $_REQUEST[$reg];
39
+ class SReg {
40
+
41
+  public function parseResponse() {
42
+   foreach (explode(',', SREG_ALL) as $reg) {
43
+    $reg = str_replace('.', '_', $reg);
44
+    if (isset($_REQUEST[$reg])) {
45
+     $_SESSION['openid']['sreg'][substr($reg, 12)] = $_REQUEST[$reg];
46
+    }
47
+   }
48
+  }
49
+
50
+  public function decorate(&$args, $ns) {
51
+   if (defined('OPENID_SREG_REQUEST')) {
52
+    $args['openid.sreg.required'] = OPENID_SREG_REQUEST;
53
+   }
54
+
55
+   if (defined('OPENID_SREG_OPTIONAL')) {
56
+    $args['openid.sreg.optional'] = OPENID_SREG_OPTIONAL;
57
+   }
58
+
59
+   if (defined('OPENID_SREG_POLICY')) {
60
+    $args['openid.sreg.policy_url'] = OPENID_SREG_POLICY;
44 61
    }
45 62
   }
63
+
46 64
  }
47 65
 
66
+ $sreg = new SReg();
67
+ $_POIDSY['decorators'][] = $sreg;
68
+ $_POIDSY['handlers'][] = $sreg;
69
+
48 70
 ?>

+ 8
- 10
urlbuilder.inc.php View File

@@ -76,7 +76,7 @@
76 76
     $args['openid.assoc_handle'] = $handle;
77 77
    }
78 78
 
79
-   self::addSRegArgs($args);
79
+   self::decorateArgs($args);
80 80
 
81 81
    return self::addArguments($base, $args);
82 82
   }
@@ -99,17 +99,15 @@
99 99
    return $root; 
100 100
   }
101 101
 
102
-  private static function addSRegArgs(&$args) {
103
-   if (defined('OPENID_SREG_REQUEST')) {
104
-    $args['openid.sreg.required'] = OPENID_SREG_REQUEST;
105
-   }
102
+  private static function decorateArgs(&$args) {
103
+   global $_POIDSY;
106 104
 
107
-   if (defined('OPENID_SREG_OPTIONAL')) {
108
-    $args['openid.sreg.optional'] = OPENID_SREG_OPTIONAL;
109
-   }
105
+   if (empty($_POIDSY['decorators'])) { return; }
106
+
107
+   $id = 1;
110 108
 
111
-   if (defined('OPENID_SREG_POLICY')) {
112
-    $args['openid.sreg.policy_url'] = OPENID_SREG_POLICY;
109
+   foreach ($_POIDSY['decorators'] as $decorator) {
110
+    $decorator->decorate($args, 'ext' . ($id++));
113 111
    }
114 112
   }
115 113
 

Loading…
Cancel
Save