You can customize serializer for change input and output format. For example:
<?php
namespace AgentSIB\JsonRpcBundle\Server;
use AgentSIB\JsonRpc\JsonRpcException;
use AgentSIB\JsonRpc\Serializers\JsonRpcSerializerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class SymfonyJsonRpcSerializer implements JsonRpcSerializerInterface
{
/**
* [@inheritdoc](https://github.com/inheritdoc)
*/
public function parseRequest ($request)
{
if ($request instanceof Request) {
return [@json_decode](https://github.com/json_decode)($request->getContent(), false, 32);
}
throw new JsonRpcException(JsonRpcException::ERROR_PARSE_ERROR);
}
/**
* [@inheritdoc](https://github.com/inheritdoc)
*/
public function serializeResponse ($response)
{
return new JsonResponse($response);
}
}
As well, you can use additional checks. For example:
// ...
public function parseRequest ($request)
{
if (!$this->checkSignature($request->getContent())) {
throw new JsonRpcException(JsonRpcException::ERROR_INVALID_REQUEST);
}
if ($request instanceof Request) {
return [@json_decode](https://github.com/json_decode)($request->getContent(), false, 32);
}
throw new JsonRpcException(JsonRpcException::ERROR_PARSE_ERROR);
}
// ...
And something more...
How can I help you explore Laravel packages today?