public function serialize($data, array $context = array())
{
$context['run_storage'] = $this->getRunStorage();
$context['project_list'] = $this->getProjectList();
$request = $this->application['request'];
$accepted = explode(',', $request->headers->get('Accept'));
foreach ($accepted as $accept) {
if ($format = $request->getFormat(trim($accept))) {
break;
}
}
if ($format === 'html') {
return $this->render('layout.html.twig');
}
if (!in_array($format, $expected = array('json', 'xml'))) {
throw new BadRequestHttpException(sprintf('Cannot serialize to format "%s". Expected %s', $format, implode(' or ', $expected)));
}
return new Response($this->application['serializer']->serialize($data, $format, $context), 200, array("Content-Type" => $request->getMimeType($format)));
}