use Symfony\Component\Routing\RequestContext; $context = new RequestContext(); $context->setBaseUrl('/myapp'); $context->setScheme('https'); // Accessing the Context instance $baseUrl = $context->getBaseUrl(); $scheme = $context->getScheme();
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\RequestStack; // Creating a new RequestStack instance $requestStack = new RequestStack(); // Adding a new Request to the stack $request = Request::createFromGlobals(); $requestStack->push($request); // Setting data to the Context instance $context = $requestStack->getMasterRequest()->attributes->get('_context'); $context['username'] = 'john.doe'; // Accessing the data in another request $previousRequest = $requestStack->getPreviousRequest(); $username = $previousRequest->attributes->get('_context')['username'];This example uses the Symfony\Component\HttpFoundation package library.