How to display the symfony profiler for API request made in the browser?

前端 未结 5 1084
-上瘾入骨i
-上瘾入骨i 2021-02-02 08:15

I\'m developing a REST api with Symfony2 + FOSRest bundle.

I would like to know if there is any way for a call to the api in dev mode (app_dev.php) from the

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-02 08:45

    I use my WithProfilerTrait which applies the toolbar only if you navigate to the URL in the browser and skips the change, if it's an ajax request.

    // in Controller:
    return $this->withProfiler($response, $request->isXmlHttpRequest());
    
    trait WithProfilerTrait
    {
        protected function withProfiler(Response $response, bool $skip = false): Response
        {
            if ($skip === true) {
                return $response;
            }
    
            $wrappedContent = '
    ' . $response->getContent() . '
    '; $response->headers->set('Content-Type', 'html'); return $response->setContent($wrappedContent); } }

提交回复
热议问题