for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Yoanm\JsonRpcServer\App\Serialization;
use Yoanm\JsonRpcServer\Domain\Model\JsonRpcCallResponse;
/**
* Class JsonRpcCallResponseNormalizer
*/
class JsonRpcCallResponseNormalizer
{
/** @var JsonRpcResponseNormalizer */
private $responseNormalizer;
* @param JsonRpcResponseNormalizer $responseNormalizer
public function __construct(JsonRpcResponseNormalizer $responseNormalizer)
$this->responseNormalizer = $responseNormalizer;
}
* @param JsonRpcCallResponse $jsonRpcCallResponse
*
* @return array|null
public function normalize(JsonRpcCallResponse $jsonRpcCallResponse) : ?array
$resultList = [];
foreach ($jsonRpcCallResponse->getResponseList() as $response) {
// Notifications must not have a response, even if they are on error
if (!$response->isNotification()) {
$resultList[] = $this->responseNormalizer->normalize($response);
// if no result, it means It was either :
// - a batch call with only notifications
// - a notification request
// => return null response in all cases
if (0 === count($resultList)) {
return null;
// In case it's not a batch, return the first (lonely) result
if (!$jsonRpcCallResponse->isBatch()) {
return array_shift($resultList);
return $resultList;