public function TestController::format in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/conneg_test/src/Controller/TestController.php \Drupal\conneg_test\Controller\TestController::format()
Returns different responses dependening on the request format.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request
Return value
\Symfony\Component\HttpFoundation\Response The response.
1 string reference to 'TestController::format'
- conneg_test.routing.yml in core/
modules/ system/ tests/ modules/ conneg_test/ conneg_test.routing.yml - core/modules/system/tests/modules/conneg_test/conneg_test.routing.yml
File
- core/
modules/ system/ tests/ modules/ conneg_test/ src/ Controller/ TestController.php, line 48 - Contains \Drupal\conneg_test\Controller\TestController.
Class
- TestController
- Test controller for content negotation tests.
Namespace
Drupal\conneg_test\ControllerCode
public function format(Request $request) {
switch ($request
->getRequestFormat()) {
case 'json':
return new JsonResponse([
'some' => 'data',
]);
case 'xml':
return new Response('<xml></xml>', Response::HTTP_OK, [
'Content-Type' => 'application/xml',
]);
default:
return new Response($request
->getRequestFormat());
}
}