Skip to content

Commit

Permalink
Refactor base controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusklocke committed Jan 12, 2025
1 parent eb010cf commit d7ce372
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/Infrastructure/API/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,13 @@ public function __construct(ResponseFactoryInterface $responseFactory)

public function handle(ServerRequestInterface $request): ResponseInterface
{
switch ($request->getMethod()) {
case 'GET':
return $this->get($request);
case 'POST':
return $this->post($request);
case 'DELETE':
return $this->delete($request);
}
throw new HttpMethodNotAllowedException($request);
}

public function get(ServerRequestInterface $request): ResponseInterface
{
throw new HttpMethodNotAllowedException($request);
}
$method = strtolower($request->getMethod());

public function post(ServerRequestInterface $request): ResponseInterface
{
throw new HttpMethodNotAllowedException($request);
}
if (!method_exists($this, $method)) {
throw new HttpMethodNotAllowedException($request);
}

public function delete(ServerRequestInterface $request): ResponseInterface
{
throw new HttpMethodNotAllowedException($request);
return $this->$method($request);
}

/**
Expand Down

0 comments on commit d7ce372

Please sign in to comment.