oligus / jad

JSON Api to Doctrine
MIT License
23 stars 6 forks source link

Standalone example #45

Open archudzik opened 3 years ago

archudzik commented 3 years ago

Description

Hi Oli, kudos for a job well done! I have a question regarding standalone usage. Let's assume that I have my router that takes Symfony\Component\HttpFoundation\Request and returns Symfony\Component\HttpFoundation\Response. Can you please tell me how can I can achieve something like that:

<?php

use Jad\Jad;
use Jad\Map\AnnotationsMapper;
use Jad\Request\JsonApiRequest;
use Jad\Request\Parameters;
use Jad\Response\JsonApiResponse;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class JsonApiRouter
{
    public function __invoke(Request $request): Response
    {
        $parameters = new Parameters();
        $parameters->setArguments($request->query->all());

        $mapper = new AnnotationsMapper($this->getEm());

        $jsonApiRequest = new JsonApiRequest($request, $parameters);
        $jsonApiRequest->setPathPrefix('/json');

        $response = new JsonApiResponse($jsonApiRequest, $mapper);

        return $response->getRawResponse(); // this is what I miss :)
    }
}
oligus commented 3 years ago

Hi, thank you for reaching out, sorry for late reply. This is not available at this time but basically what you want is the the document json encoded I guess. If you are up for it, a PR would be appreciated, otherwise I can look at it later.

Thanx!