for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Yoanm\JsonRpcServer\App\Creator;
use Yoanm\JsonRpcServer\Domain\Exception\JsonRpcExceptionInterface;
use Yoanm\JsonRpcServer\Domain\Exception\JsonRpcInternalErrorException;
use Yoanm\JsonRpcServer\Domain\Model\JsonRpcRequest;
use Yoanm\JsonRpcServer\Domain\Model\JsonRpcResponse;
/**
* Class ResponseCreator
*/
class ResponseCreator
{
* @param JsonRpcRequest|null $fromRequest
*
* @return JsonRpcResponse
public function createEmptyResponse(JsonRpcRequest $fromRequest = null) : JsonRpcResponse
return null === $fromRequest
? new JsonRpcResponse()
: (
new JsonRpcResponse($fromRequest->getJsonRpc())
)
->setIsNotification($fromRequest->isNotification())
->setId($fromRequest->getId())
;
}
* @param mixed $result
public function createResultResponse($result, JsonRpcRequest $fromRequest = null) : JsonRpcResponse
return $this->createEmptyResponse($fromRequest)
->setResult($result);
* @param \Exception $exception
public function createErrorResponse(\Exception $exception, JsonRpcRequest $fromRequest = null) : JsonRpcResponse
->setIsNotification(false)
->setError(
$exception instanceof JsonRpcExceptionInterface
? $exception
: new JsonRpcInternalErrorException($exception)