PHP code example of alcalyn / serializable-api-response
1. Go to this page and download the library: Download alcalyn/serializable-api-response library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alcalyn / serializable-api-response example snippets
php
use Symfony\Component\HttpKernel\KernelEvents;
use Alcalyn\SerializableApiResponse\ApiResponseFilter;
// Register reponse filter as a service
$this['acme.listener.api_response_filter'] = function () {
$serializer = $this['serializer']; // Assuming your serializer service has this name
return new ApiResponseFilter($serializer);
};
// Listen Kernel response to convert ApiResponse with raw object to Symfony Response with serialized data
$this->on(KernelEvents::VIEW, function ($event) {
$this['acme.listener.api_response_filter']->onKernelView($event);
});