Completed
Push — master ( 408f9e...048037 )
by Maxence
29:56
created
apps/cloud_federation_api/lib/Controller/OCMRequestController.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -26,62 +26,62 @@
 block discarded – undo
26 26
 use Psr\Log\LoggerInterface;
27 27
 
28 28
 class OCMRequestController extends Controller {
29
-	public function __construct(
30
-		string $appName,
31
-		IRequest $request,
32
-		private readonly IEventDispatcher $eventDispatcher,
33
-		private readonly IOCMDiscoveryService $ocmDiscoveryService,
34
-		private readonly LoggerInterface $logger,
35
-	) {
36
-		parent::__construct($appName, $request);
37
-	}
29
+    public function __construct(
30
+        string $appName,
31
+        IRequest $request,
32
+        private readonly IEventDispatcher $eventDispatcher,
33
+        private readonly IOCMDiscoveryService $ocmDiscoveryService,
34
+        private readonly LoggerInterface $logger,
35
+    ) {
36
+        parent::__construct($appName, $request);
37
+    }
38 38
 
39
-	/**
40
-	 * Method will catch any request done to /ocm/[...] and will broadcast an event.
41
-	 * The first parameter of the remaining subpath (post-/ocm/) is defined as
42
-	 * capability and should be used by listeners to filter incoming requests.
43
-	 *
44
-	 * @see OCMEndpointRequestEvent
45
-	 * @see OCMEndpointRequestEvent::getArgs
46
-	 *
47
-	 * @param string $ocmPath
48
-	 * @return Response
49
-	 * @throws OCMArgumentException
50
-	 */
51
-	#[NoCSRFRequired]
52
-	#[PublicPage]
53
-	#[BruteForceProtection(action: 'receiveOcmRequest')]
54
-	public function manageOCMRequests(string $ocmPath): Response {
55
-		if (!mb_check_encoding($ocmPath, 'UTF-8')) {
56
-			throw new OCMArgumentException('path is not UTF-8');
57
-		}
39
+    /**
40
+     * Method will catch any request done to /ocm/[...] and will broadcast an event.
41
+     * The first parameter of the remaining subpath (post-/ocm/) is defined as
42
+     * capability and should be used by listeners to filter incoming requests.
43
+     *
44
+     * @see OCMEndpointRequestEvent
45
+     * @see OCMEndpointRequestEvent::getArgs
46
+     *
47
+     * @param string $ocmPath
48
+     * @return Response
49
+     * @throws OCMArgumentException
50
+     */
51
+    #[NoCSRFRequired]
52
+    #[PublicPage]
53
+    #[BruteForceProtection(action: 'receiveOcmRequest')]
54
+    public function manageOCMRequests(string $ocmPath): Response {
55
+        if (!mb_check_encoding($ocmPath, 'UTF-8')) {
56
+            throw new OCMArgumentException('path is not UTF-8');
57
+        }
58 58
 
59
-		try {
60
-			// if request is signed and well signed, no exceptions are thrown
61
-			// if request is not signed and host is known for not supporting signed request, no exceptions are thrown
62
-			$signedRequest = $this->ocmDiscoveryService->getIncomingSignedRequest();
63
-		} catch (IncomingRequestException $e) {
64
-			$this->logger->warning('incoming ocm request exception', ['exception' => $e]);
65
-			return new JSONResponse(['message' => $e->getMessage(), 'validationErrors' => []], Http::STATUS_BAD_REQUEST);
66
-		}
59
+        try {
60
+            // if request is signed and well signed, no exceptions are thrown
61
+            // if request is not signed and host is known for not supporting signed request, no exceptions are thrown
62
+            $signedRequest = $this->ocmDiscoveryService->getIncomingSignedRequest();
63
+        } catch (IncomingRequestException $e) {
64
+            $this->logger->warning('incoming ocm request exception', ['exception' => $e]);
65
+            return new JSONResponse(['message' => $e->getMessage(), 'validationErrors' => []], Http::STATUS_BAD_REQUEST);
66
+        }
67 67
 
68
-		// assuming that ocm request contains a json array
69
-		$payload = $signedRequest?->getBody() ?? file_get_contents('php://input');
70
-		try {
71
-			$payload = ($payload) ? json_decode($payload, true, 512, JSON_THROW_ON_ERROR) : null;
72
-		} catch (JsonException $e) {
73
-			$this->logger->debug('json decode error', ['exception' => $e]);
74
-			$payload = null;
75
-		}
68
+        // assuming that ocm request contains a json array
69
+        $payload = $signedRequest?->getBody() ?? file_get_contents('php://input');
70
+        try {
71
+            $payload = ($payload) ? json_decode($payload, true, 512, JSON_THROW_ON_ERROR) : null;
72
+        } catch (JsonException $e) {
73
+            $this->logger->debug('json decode error', ['exception' => $e]);
74
+            $payload = null;
75
+        }
76 76
 
77
-		$event = new OCMEndpointRequestEvent(
78
-			$this->request->getMethod(),
79
-			preg_replace('@/+@', '/', $ocmPath),
80
-			$payload,
81
-			$signedRequest?->getOrigin()
82
-		);
83
-		$this->eventDispatcher->dispatchTyped($event);
77
+        $event = new OCMEndpointRequestEvent(
78
+            $this->request->getMethod(),
79
+            preg_replace('@/+@', '/', $ocmPath),
80
+            $payload,
81
+            $signedRequest?->getOrigin()
82
+        );
83
+        $this->eventDispatcher->dispatchTyped($event);
84 84
 
85
-		return $event->getResponse() ?? new Response(Http::STATUS_NOT_FOUND);
86
-	}
85
+        return $event->getResponse() ?? new Response(Http::STATUS_NOT_FOUND);
86
+    }
87 87
 }
Please login to merge, or discard this patch.