You are here

public function SessionTestController::traceHandler in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php \Drupal\session_test\Controller\SessionTestController::traceHandler()
  2. 9 core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php \Drupal\session_test\Controller\SessionTestController::traceHandler()

Returns the trace recorded by test proxy session handlers as JSON.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The incoming request.

Return value

\Symfony\Component\HttpFoundation\JsonResponse The response.

1 string reference to 'SessionTestController::traceHandler'
session_test.routing.yml in core/modules/system/tests/modules/session_test/session_test.routing.yml
core/modules/system/tests/modules/session_test/session_test.routing.yml

File

core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php, line 152

Class

SessionTestController
Controller providing page callbacks for the action admin interface.

Namespace

Drupal\session_test\Controller

Code

public function traceHandler(Request $request) {

  // Start a session if necessary, set a value and then save and close it.
  $request
    ->getSession()
    ->start();
  if (empty($_SESSION['trace-handler'])) {
    $_SESSION['trace-handler'] = 1;
  }
  else {
    $_SESSION['trace-handler']++;
  }
  $request
    ->getSession()
    ->save();

  // Collect traces and return them in JSON format.
  $trace = \Drupal::service('session_test.session_handler_proxy_trace')
    ->getArrayCopy();
  return new JsonResponse($trace);
}