From 40dada827c72f63a11a69ec121d7c9d5b1f043bf Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Tue, 22 Jan 2019 15:21:42 +0000 Subject: [PATCH] Notification Handler --- src/Fident.php | 2 +- src/Notifications/FidentNotification.php | 73 ++------------------ src/Notifications/UserUpdateNotification.php | 68 ++++++++++++++++++ 3 files changed, 76 insertions(+), 67 deletions(-) create mode 100644 src/Notifications/UserUpdateNotification.php diff --git a/src/Fident.php b/src/Fident.php index 2456210..b311001 100644 --- a/src/Fident.php +++ b/src/Fident.php @@ -70,7 +70,7 @@ public function decodeNotification($requestBody): ?FidentNotification $sig = self::urlsafeB64Decode(Objects::property($notification, 'Signature', '')); if(openssl_verify($data, $sig, $this->getConfig()->getPublicKey(), OPENSSL_ALGO_SHA256)) { - return FidentNotification::fromString($data); + return FidentNotification::generate(Objects::property($notification, 'DataType', 1), $data); } return null; } diff --git a/src/Notifications/FidentNotification.php b/src/Notifications/FidentNotification.php index dc4b93f..1dbc342 100644 --- a/src/Notifications/FidentNotification.php +++ b/src/Notifications/FidentNotification.php @@ -1,79 +1,20 @@ _id = Objects::property($notificationData, 'ID'); - $notification->_created = Objects::property($notificationData, 'Created'); - $notification->_username = Objects::property($notificationData, 'Username'); - $notification->_type = Objects::property($notificationData, 'Type'); - $notification->_attributes = []; - foreach(Objects::property($notificationData, 'Attributes', []) as $attr) + switch($dataType) { - $notification->addAttribute(Objects::property($attr, 'Key'), Objects::property($attr, 'Value')); + case self::DT_USER_UPDATE: + return UserUpdateNotification::fromString($jsonString); } - return $notification; - } - - public function addAttribute($key, $value) - { - $this->_attributes[$key] = new UserAttribute($key, $value); - return $this; - } - - /** - * @return mixed - */ - public function getId() - { - return $this->_id; - } - - /** - * @return mixed - */ - public function getCreated() - { - return $this->_created; - } - - /** - * @return mixed - */ - public function getUsername() - { - return $this->_username; - } - - /** - * @return UserAttribute[] - */ - public function getAttributes() - { - return $this->_attributes; - } - - /** - * @return mixed - */ - public function getType() - { - return $this->_type; + return null; } } diff --git a/src/Notifications/UserUpdateNotification.php b/src/Notifications/UserUpdateNotification.php new file mode 100644 index 0000000..e8c22f0 --- /dev/null +++ b/src/Notifications/UserUpdateNotification.php @@ -0,0 +1,68 @@ +_id = Objects::property($notificationData, 'ID'); + $notification->_created = Objects::property($notificationData, 'Created'); + $notification->_username = Objects::property($notificationData, 'Username'); + $notification->_attributes = []; + foreach(Objects::property($notificationData, 'Attributes', []) as $attr) + { + $notification->addAttribute(Objects::property($attr, 'Key'), Objects::property($attr, 'Value')); + } + return $notification; + } + + public function addAttribute($key, $value) + { + $this->_attributes[$key] = new UserAttribute($key, $value); + return $this; + } + + /** + * @return mixed + */ + public function getId() + { + return $this->_id; + } + + /** + * @return mixed + */ + public function getCreated() + { + return $this->_created; + } + + /** + * @return mixed + */ + public function getUsername() + { + return $this->_username; + } + + /** + * @return UserAttribute[] + */ + public function getAttributes() + { + return $this->_attributes; + } +}