Skip to content

Commit 40dada8

Browse files
committed
Notification Handler
1 parent c0dde63 commit 40dada8

File tree

3 files changed

+76
-67
lines changed

3 files changed

+76
-67
lines changed

src/Fident.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function decodeNotification($requestBody): ?FidentNotification
7070
$sig = self::urlsafeB64Decode(Objects::property($notification, 'Signature', ''));
7171
if(openssl_verify($data, $sig, $this->getConfig()->getPublicKey(), OPENSSL_ALGO_SHA256))
7272
{
73-
return FidentNotification::fromString($data);
73+
return FidentNotification::generate(Objects::property($notification, 'DataType', 1), $data);
7474
}
7575
return null;
7676
}
Lines changed: 7 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,20 @@
11
<?php
22
namespace Fident\Web\Notifications;
33

4-
use Fident\Web\UserData\UserAttribute;
5-
use Packaged\Helpers\Objects;
6-
74
class FidentNotification
85
{
9-
protected $_id;
10-
protected $_created;
11-
protected $_username;
12-
protected $_attributes;
13-
protected $_type;
14-
156
const SUCCESS_RESPONSE = 'con';
167

17-
public static function fromString($rawNotificationData)
8+
const DT_USER_UPDATE = 1;
9+
10+
public static function generate($dataType, $jsonString)
1811
{
19-
$notification = new static();
20-
$notificationData = json_decode($rawNotificationData);
21-
$notification->_id = Objects::property($notificationData, 'ID');
22-
$notification->_created = Objects::property($notificationData, 'Created');
23-
$notification->_username = Objects::property($notificationData, 'Username');
24-
$notification->_type = Objects::property($notificationData, 'Type');
25-
$notification->_attributes = [];
26-
foreach(Objects::property($notificationData, 'Attributes', []) as $attr)
12+
switch($dataType)
2713
{
28-
$notification->addAttribute(Objects::property($attr, 'Key'), Objects::property($attr, 'Value'));
14+
case self::DT_USER_UPDATE:
15+
return UserUpdateNotification::fromString($jsonString);
2916
}
30-
return $notification;
31-
}
32-
33-
public function addAttribute($key, $value)
34-
{
35-
$this->_attributes[$key] = new UserAttribute($key, $value);
36-
return $this;
37-
}
38-
39-
/**
40-
* @return mixed
41-
*/
42-
public function getId()
43-
{
44-
return $this->_id;
45-
}
46-
47-
/**
48-
* @return mixed
49-
*/
50-
public function getCreated()
51-
{
52-
return $this->_created;
53-
}
54-
55-
/**
56-
* @return mixed
57-
*/
58-
public function getUsername()
59-
{
60-
return $this->_username;
61-
}
62-
63-
/**
64-
* @return UserAttribute[]
65-
*/
66-
public function getAttributes()
67-
{
68-
return $this->_attributes;
69-
}
70-
71-
/**
72-
* @return mixed
73-
*/
74-
public function getType()
75-
{
76-
return $this->_type;
17+
return null;
7718
}
7819

7920
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
namespace Fident\Web\Notifications;
3+
4+
use Fident\Web\UserData\UserAttribute;
5+
use Packaged\Helpers\Objects;
6+
7+
class UserUpdateNotification extends FidentNotification
8+
{
9+
protected $_id;
10+
protected $_created;
11+
protected $_username;
12+
protected $_attributes;
13+
14+
const SUCCESS_RESPONSE = 'con';
15+
16+
public static function fromString($rawNotificationData)
17+
{
18+
$notification = new static();
19+
$notificationData = json_decode($rawNotificationData);
20+
$notification->_id = Objects::property($notificationData, 'ID');
21+
$notification->_created = Objects::property($notificationData, 'Created');
22+
$notification->_username = Objects::property($notificationData, 'Username');
23+
$notification->_attributes = [];
24+
foreach(Objects::property($notificationData, 'Attributes', []) as $attr)
25+
{
26+
$notification->addAttribute(Objects::property($attr, 'Key'), Objects::property($attr, 'Value'));
27+
}
28+
return $notification;
29+
}
30+
31+
public function addAttribute($key, $value)
32+
{
33+
$this->_attributes[$key] = new UserAttribute($key, $value);
34+
return $this;
35+
}
36+
37+
/**
38+
* @return mixed
39+
*/
40+
public function getId()
41+
{
42+
return $this->_id;
43+
}
44+
45+
/**
46+
* @return mixed
47+
*/
48+
public function getCreated()
49+
{
50+
return $this->_created;
51+
}
52+
53+
/**
54+
* @return mixed
55+
*/
56+
public function getUsername()
57+
{
58+
return $this->_username;
59+
}
60+
61+
/**
62+
* @return UserAttribute[]
63+
*/
64+
public function getAttributes()
65+
{
66+
return $this->_attributes;
67+
}
68+
}

0 commit comments

Comments
 (0)