Page MenuHomeDevCentral

D871.id2270.diff
No OneTemporary

D871.id2270.diff

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
@@ -48,7 +48,7 @@
*/
protected function logRequest (array $extraContextualData = []) : void {
Log::info('[Gate] New payload.', [
- 'service' => static::SERVICE_NAME,
+ 'service' => $this->getServiceName(),
'door' => $this->door,
] + $extraContextualData);
}
@@ -62,7 +62,7 @@
*/
protected function initializeReport () : void {
if (Features::isEnabled('ActionsReport')) {
- Report::attachToGate(static::SERVICE_NAME, $this->door);
+ Report::attachToGate($this->getServiceName(), $this->door);
}
}
@@ -92,7 +92,7 @@
* @return \Nasqueron\Notifications\Config\Services\Service|null The service information is found; otherwise, null.
*/
public function getService () : ?Service {
- return Services::findServiceByDoor(static::SERVICE_NAME, $this->door);
+ return Services::findServiceByDoor($this->getServiceName(), $this->door);
}
/**
@@ -117,4 +117,12 @@
return "";
}
+ ///
+ /// Helper methods
+ ///
+
+ private 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,85 @@
+<?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
+ );
+ }
+
+ ///
+ /// Payload processing
+ ///
+
+ protected function onPayload () {
+ $this->initializeReport();
+
+ Event::fire(new NotificationEvent($this->payload));
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 23:08 (20 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2263443
Default Alt Text
D871.id2270.diff (3 KB)

Event Timeline