Lemon\RestBundle\Controller\IndexController::indexAction PHP Method

indexAction() public method

public indexAction ( Request $request ) : Response
$request Symfony\Component\HttpFoundation\Request
return Symfony\Component\HttpFoundation\Response
    public function indexAction(Request $request)
    {
        $format = $this->negotiator->getBestFormat($request->headers->get('Accept'));
        if ($format == 'html') {
            $format = 'json';
        }
        $data = array();
        foreach ($this->registry->all() as $definition) {
            $data[$definition->getName() . '_url'] = $this->router->generate('lemon_rest_list', array('resource' => $definition->getName()), RouterInterface::ABSOLUTE_URL);
        }
        $output = $this->serializer->serialize($data, $format);
        $response = new Response();
        $response->headers->set('Content-Type', $request->headers->get('Accept'));
        $response->setContent($output);
        return $response;
    }

Usage Example

 public function testIndex()
 {
     $request = $this->makeRequest('GET', '/', null);
     /** @var \Symfony\Component\HttpFoundation\Response $response */
     $response = $this->controller->indexAction($request);
     $data = json_decode($response->getContent());
     $this->assertNotEmpty($data);
     $this->assertEquals("http://localhost/person", $data->person_url);
     $this->assertEquals("http://localhost/footballTeam", $data->footballTeam_url);
 }