Version 1
[yaffs-website] / web / core / modules / system / tests / modules / system_test / src / Controller / PageCacheAcceptHeaderController.php
1 <?php
2
3 namespace Drupal\system_test\Controller;
4
5 use Drupal\Core\Cache\CacheableJsonResponse;
6 use Drupal\Core\Cache\CacheableResponse;
7 use Symfony\Component\HttpFoundation\Request;
8
9 /**
10  * Defines a controller to respond the page cache accept header test.
11  */
12 class PageCacheAcceptHeaderController {
13
14   /**
15    * Processes a request that will vary with Accept header.
16    *
17    * @param \Symfony\Component\HttpFoundation\Request $request
18    *   The current request object.
19    *
20    * @return mixed
21    */
22   public function content(Request $request) {
23     if ($request->getRequestFormat() === 'json') {
24       return new CacheableJsonResponse(['content' => 'oh hai this is json']);
25     }
26     else {
27       return new CacheableResponse("<p>oh hai this is html.</p>");
28     }
29   }
30
31 }