From 8535954a903bf0bc1a3d4406fa3a4c34c6f00c00 Mon Sep 17 00:00:00 2001 From: Barry Brands Date: Mon, 23 Jan 2023 16:19:54 +0100 Subject: [PATCH 1/3] Return response from action after throwing event --- .../Service}/RequestService.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) rename {Service => ActionHandler/Service}/RequestService.php (98%) diff --git a/Service/RequestService.php b/ActionHandler/Service/RequestService.php similarity index 98% rename from Service/RequestService.php rename to ActionHandler/Service/RequestService.php index 03b4b61f..0c0a85f6 100644 --- a/Service/RequestService.php +++ b/ActionHandler/Service/RequestService.php @@ -122,11 +122,11 @@ public function getId(array $object) } elseif (isset($this->data['query']['id'])) { return $this->data['query']['id']; } elseif (isset($this->data['path']['id'])) { - return$this->data['path']['id']; + return $this->data['path']['id']; } elseif (isset($this->data['path']['{uuid}'])) { return $this->data['path']['{uuid}']; } elseif (isset($this->data['query']['uuid'])) { - return$this->data['query']['uuid']; + return $this->data['query']['uuid']; } elseif (isset($this->content['id'])) { // the id might also be passed trough the object itself return $this->content['id']; } elseif (isset($this->content['uuid'])) { @@ -264,7 +264,7 @@ public function proxyHandler(array $data, array $configuration): Response // Get clean query paramters without all the symfony shizzle $query = $this->realRequestQueryAll($this->data['method']); - $this->data['path'] = '/'.$data['path']['{route}']; + $this->data['path'] = '/' . $data['path']['{route}']; // Make a guzzle call to the source bassed on the incomming call $result = $this->callService->call( @@ -394,7 +394,7 @@ public function requestHandler(array $data, array $configuration): Response // If we do not have an object we throw an 404 if (!$result) { return new Response($this->serializer->serialize([ - 'message' => 'Could not find an object with id '.$this->id, + 'message' => 'Could not find an object with id ' . $this->id, 'type' => 'Bad Request', 'path' => implode(', ', $allowedSchemas['name']), 'data' => ['id' => $this->id], @@ -536,14 +536,17 @@ public function requestHandler(array $data, array $configuration): Response default: break; - return new Response('Unkown method'.$this->data['method'], '404'); + return new Response('Unkown method' . $this->data['method'], '404'); } $this->entityManager->flush(); + if (isset($eventType) && isset($this->object)) { $event = new ActionEvent($eventType, ['response' => $this->object->toArray(), 'entity' => $this->object->getEntity()->getId()->toString()]); $this->eventDispatcher->dispatch($event, $event->getType()); + $eventData = $event->getData(); + isset($eventData['response']) && $result = $eventData['response']; } $this->handleMetadataSelf($result, $metadataSelf); From e48fb1eca4a06f973e8a3f73068ec7f66c4093c5 Mon Sep 17 00:00:00 2001 From: Barry Brands Date: Mon, 23 Jan 2023 16:20:15 +0100 Subject: [PATCH 2/3] error prevention --- {Service => ActionHandler/Service}/CacheService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename {Service => ActionHandler/Service}/CacheService.php (99%) diff --git a/Service/CacheService.php b/ActionHandler/Service/CacheService.php similarity index 99% rename from Service/CacheService.php rename to ActionHandler/Service/CacheService.php index d33f1e7a..db6ec137 100644 --- a/Service/CacheService.php +++ b/ActionHandler/Service/CacheService.php @@ -171,7 +171,7 @@ private function removeDataFromCache(\MongoDB\Collection $collection, string $ty $endpoints = $collection->find()->toArray(); foreach ($endpoints as $endpoint) { if (!$this->entityManager->find($type, $endpoint['id'])) { - $this->io->writeln("removing {$endpoint['id']} from cache"); + isset($this->io) && $this->io->writeln("removing {$endpoint['id']} from cache"); $collection->findOneAndDelete(['id' => $endpoint['id']]); } } From 451c4f7478fe63297704f3f92e9534262e38c0b6 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 23 Jan 2023 15:23:59 +0000 Subject: [PATCH 3/3] Apply fixes from StyleCI --- ActionHandler/Service/RequestService.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ActionHandler/Service/RequestService.php b/ActionHandler/Service/RequestService.php index 0c0a85f6..0fc5e47e 100644 --- a/ActionHandler/Service/RequestService.php +++ b/ActionHandler/Service/RequestService.php @@ -264,7 +264,7 @@ public function proxyHandler(array $data, array $configuration): Response // Get clean query paramters without all the symfony shizzle $query = $this->realRequestQueryAll($this->data['method']); - $this->data['path'] = '/' . $data['path']['{route}']; + $this->data['path'] = '/'.$data['path']['{route}']; // Make a guzzle call to the source bassed on the incomming call $result = $this->callService->call( @@ -394,7 +394,7 @@ public function requestHandler(array $data, array $configuration): Response // If we do not have an object we throw an 404 if (!$result) { return new Response($this->serializer->serialize([ - 'message' => 'Could not find an object with id ' . $this->id, + 'message' => 'Could not find an object with id '.$this->id, 'type' => 'Bad Request', 'path' => implode(', ', $allowedSchemas['name']), 'data' => ['id' => $this->id], @@ -536,12 +536,11 @@ public function requestHandler(array $data, array $configuration): Response default: break; - return new Response('Unkown method' . $this->data['method'], '404'); + return new Response('Unkown method'.$this->data['method'], '404'); } $this->entityManager->flush(); - if (isset($eventType) && isset($this->object)) { $event = new ActionEvent($eventType, ['response' => $this->object->toArray(), 'entity' => $this->object->getEntity()->getId()->toString()]); $this->eventDispatcher->dispatch($event, $event->getType());