Closed vylink closed 5 years ago
Probably response and exception decorators. We will maybe add some events to Application class, but not now.
Related to #105
use Apitte\Core\UI\Controller\IController;
use Apitte\Core\UI\Controller\Lifecycle\AfterAction;
use Apitte\Core\UI\Controller\Lifecycle\BeforeAction;
class ExampleController implements IController, BeforeAction, AfterAction
{
public function before(ApiRequest $request): ApiRequest
{
// some initialization
}
public function endpoint(ApiRequest $request, ApiResponse $response): ApiResponse
{
return $response
->withStatus(ApiResponse::S200_OK);
}
public function after(ApiRequest $request, ApiResponse $response): ApiResponse
{
// cleanup, close database connection
}
}
@vylink I was thinking about that for a while. Do you have an use-case where you really need endpoint-specific before and after methods? Because I think this is what middlewares should do
I would like to close database connection after each request. What will be the best approach? Where I can do that? Any idea?