/** * @param Request $request * @return 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; }
/** * @covers ::add() * @covers ::has() * @covers ::get() * @covers ::all() */ public function testAddClass() { $definition = new Definition('person', '\\Lemon\\RestBundle\\Tests\\Fixtures\\Person'); $registry = new Registry(); $registry->add($definition); $this->assertTrue($registry->has('person')); $this->assertEquals('\\Lemon\\RestBundle\\Tests\\Fixtures\\Person', $registry->get('person')->getClass()); $this->assertEquals(array('person' => $definition), $registry->all()); }