Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3772337
D871.id2282.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D871.id2282.diff
View Options
diff --git a/app/Http/Controllers/Gate/GateController.php b/app/Http/Controllers/Gate/GateController.php
--- a/app/Http/Controllers/Gate/GateController.php
+++ b/app/Http/Controllers/Gate/GateController.php
@@ -117,4 +117,12 @@
return "";
}
+ ///
+ /// Helper methods
+ ///
+
+ protected function getServiceName () : string {
+ return static::SERVICE_NAME;
+ }
+
}
diff --git a/app/Http/Controllers/Gate/NotificationGateController.php b/app/Http/Controllers/Gate/NotificationGateController.php
new file mode 100644
--- /dev/null
+++ b/app/Http/Controllers/Gate/NotificationGateController.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace Nasqueron\Notifications\Http\Controllers\Gate;
+
+use Nasqueron\Notifications\Events\NotificationEvent;
+use Nasqueron\Notifications\Notifications\Notification;
+
+use Symfony\Component\HttpFoundation\Response;
+
+use Event;
+use Request;
+
+class NotificationGateController extends GateController {
+
+ ///
+ /// Private members
+ ///
+
+ /**
+ * The request content, as a structured data
+ *
+ * @var \stdClass
+ */
+ private $payload;
+
+ /**
+ * The request content
+ *
+ * @var string
+ */
+ private $rawRequestContent;
+
+ ///
+ /// Request processing
+ ///
+
+ /**
+ * Handles POST requests
+ *
+ * @param string $door The door, matching the project for this payload
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function onPost (string $door) : Response {
+ // Parses the request and check if it's legit
+
+ $this->door = $door;
+ $this->extractPayload();
+
+ // Process the request
+
+ $this->logRequest();
+ $this->onPayload();
+
+ // Output
+
+ return parent::renderReport();
+ }
+
+ /**
+ * Extracts payload from the request
+ */
+ protected function extractPayload () {
+ $request = Request::instance();
+ $this->rawRequestContent = $request->getContent();
+ $this->payload = $this->getNotification();
+ }
+
+ private function getNotification () : Notification {
+ $mapper = new \JsonMapper();
+ return $mapper->map(
+ json_decode($this->rawRequestContent),
+ new Notification
+ );
+ }
+
+ protected function getServiceName () : string {
+ return (string)$this->payload->service;
+ }
+
+ ///
+ /// Payload processing
+ ///
+
+ protected function onPayload () {
+ $this->initializeReport();
+
+ Event::fire(new NotificationEvent($this->payload));
+ }
+}
diff --git a/config/gate.php b/config/gate.php
--- a/config/gate.php
+++ b/config/gate.php
@@ -13,6 +13,10 @@
*/
'controllers' => [
+ // Native notifications
+ 'Notification',
+
+ // External services
'DockerHub',
'GitHub',
'Jenkins',
diff --git a/tests/data/config.json b/tests/data/config.json
--- a/tests/data/config.json
+++ b/tests/data/config.json
@@ -1,5 +1,6 @@
{
"gates": [
+ "Notification",
"DockerHub",
"GitHub",
"Jenkins",
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 03:40 (7 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2261697
Default Alt Text
D871.id2282.diff (3 KB)
Attached To
Mode
D871: Accept notifications in our native format
Attached
Detach File
Event Timeline
Log In to Comment