Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController::toolbarAction PHP Method

toolbarAction() public method

Renders the Web Debug Toolbar.
public toolbarAction ( string $token, string $position = null ) : Response
$token string The profiler token
$position string The toolbar position (bottom, normal, or null -- automatically guessed)
return Symfony\Component\HttpFoundation\Response A Response instance
    public function toolbarAction($token, $position = null)
    {
        $request = $this->container->get('request');

        if (null !== $session = $request->getSession()) {
            // keep current flashes for one more request
            $session->setFlashes($session->getFlashes());
        }

        if (null === $token) {
            return new Response();
        }

        $profiler = $this->container->get('profiler');
        $profiler->disable();

        if (!$profile = $profiler->loadProfile($token)) {
            return new Response();
        }

        if (null === $position) {
            $position = false === strpos($this->container->get('request')->headers->get('user-agent'), 'Mobile') ? 'fixed' : 'absolute';
        }

        $url = null;
        try {
            $url = $this->container->get('router')->generate('_profiler', array('token' => $token));
        } catch (\Exception $e) {
            // the profiler is not enabled
        }

        return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:toolbar.html.twig', array(
            'position'     => $position,
            'profile'      => $profile,
            'templates'    => $this->getTemplates($profiler),
            'profiler_url' => $url,
            'verbose'      => $this->container->get('web_profiler.debug_toolbar')->isVerbose()
        ));
    }

Usage Example

Ejemplo n.º 1
0
 public function testReturns404onTokenNotFound()
 {
     $urlGenerator = $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface');
     $twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
     $profiler = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Profiler\\Profiler')->disableOriginalConstructor()->getMock();
     $controller = new ProfilerController($urlGenerator, $profiler, $twig, array());
     $profiler->expects($this->exactly(2))->method('loadProfile')->will($this->returnCallback(function ($token) {
         if ('found' == $token) {
             return new Profile($token);
         }
     }));
     $response = $controller->toolbarAction(Request::create('/_wdt/found'), 'found');
     $this->assertEquals(200, $response->getStatusCode());
     $response = $controller->toolbarAction(Request::create('/_wdt/notFound'), 'notFound');
     $this->assertEquals(404, $response->getStatusCode());
 }
All Usage Examples Of Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController::toolbarAction