Skip to content

Commit

Permalink
custom endpoint handler keep instance
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Dec 24, 2024
1 parent 7b8f812 commit c4fdb35
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Service/ServiceEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ function (Payload $message) {

// Setup the response
$response = "";
$handler = $this->endpointHandler;

switch ($this->endpointHandler) {
case is_subclass_of($this->endpointHandler, EndpointHandler::class):
switch (true) {
case is_string($handler) && is_subclass_of($handler, EndpointHandler::class):
// Instantiate the endpointHandler
$handler = new $this->endpointHandler();

$handler = new $handler();
$response = $handler->handle($message);
break;
case is_callable($this->endpointHandler):
$response = call_user_func($this->endpointHandler, $message);
case is_callable($handler):
$response = call_user_func($handler, $message);
break;
case $this->endpointHandler instanceof EndpointHandler:
$response = $this->endpointHandler->handle($message);
case $handler instanceof EndpointHandler:
$response = $handler->handle($message);
break;
default:
throw new \LogicException("The provided endpoint handler is not a supported type.");
Expand Down

0 comments on commit c4fdb35

Please sign in to comment.