/** * Returns the routing traces associated to the given request. * * @param RequestDataCollector $request * @param string $method * * @return array */ private function getTraces(RequestDataCollector $request, $method) { $traceRequest = Request::create($request->getPathInfo(), $request->getRequestServer(true)->get('REQUEST_METHOD'), array(), $request->getRequestCookies(true)->all(), array(), $request->getRequestServer(true)->all()); $context = $this->matcher->getContext(); $context->setMethod($method); $matcher = new TraceableUrlMatcher($this->routes, $context); return $matcher->getTracesForRequest($traceRequest); }
public function testKernelResponseDoesNotStartSession() { $kernel = $this->getMock(HttpKernelInterface::class); $request = new Request(); $session = new Session(new MockArraySessionStorage()); $request->setSession($session); $response = new Response(); $c = new RequestDataCollector(); $c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response)); $this->assertFalse($session->isStarted()); }
/** * {@inheritdoc} */ public function collect(Request $request, Response $response, \Exception $exception = NULL) { parent::collect($request, $response, $exception); $controller = $this->controllerResolver->getController($request); $this->data['controller'] = $this->getMethodData($controller[0], $controller[1]); $this->data['access_check'] = $this->accessCheck; }
/** * {@inheritdoc} */ public function collect(Request $request, Response $response, \Exception $exception = null) { parent::collect($request, $response, $exception); if ($parentRequestAttributes = $request->attributes->get('_forwarded')) { if ($parentRequestAttributes instanceof ParameterBag) { $parentRequestAttributes->set('_forward_token', $response->headers->get('x-debug-token')); } } if ($request->attributes->has('_forward_controller')) { $this->data['forward'] = array('token' => $request->attributes->get('_forward_token'), 'controller' => $this->parseController($request->attributes->get('_forward_controller'))); } }
public function collect(Request $request, Response $response, \Exception $exception = null) { parent::collect($request, $response, $exception); $controller = explode('::', $request->get('_controller')); if (count($controller) !== 2) { return; } $class = new \ReflectionClass($controller[0]); $reflectionMethod = $class->getMethod($controller[1]); $annotation = $this->annotationReader->getMethodAnnotation($reflectionMethod, '\\Rezzza\\SecurityBundle\\Controller\\Annotations\\ObfuscateRequest'); if ($annotation) { $this->data = $this->obfuscator->obfuscate($this->data, $annotation->getObfuscatedPatterns()); } }
/** * {@inheritdoc} */ public function collect(Request $request, Response $response, \Exception $exception = null) { parent::collect($request, $response, $exception); $this->data['controller'] = 'n/a'; if (isset($this->controllers[$request])) { $controller = $this->controllers[$request]; if (is_array($controller)) { $r = new \ReflectionMethod($controller[0], $controller[1]); $this->data['controller'] = array('class' => get_class($controller[0]), 'method' => $controller[1], 'file' => $r->getFilename(), 'line' => $r->getStartLine()); } elseif ($controller instanceof \Closure) { $this->data['controller'] = 'Closure'; } else { $this->data['controller'] = (string) $controller ?: 'n/a'; } unset($this->controllers[$request]); } }
public function testCollect() { $c = new RequestDataCollector(); $c->collect($this->createRequest(), $this->createResponse()); $attributes = $c->getRequestAttributes(); $this->assertSame('request', $c->getName()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\HeaderBag', $c->getRequestHeaders()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestServer()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestCookies()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $attributes); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestRequest()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestQuery()); $this->assertSame('html', $c->getFormat()); $this->assertSame('foobar', $c->getRoute()); $this->assertSame(array('name' => 'foo'), $c->getRouteParams()); $this->assertSame(array(), $c->getSessionAttributes()); $this->assertSame('en', $c->getLocale()); $this->assertRegExp('/Resource\\(stream#\\d+\\)/', $attributes->get('resource')); $this->assertSame('Object(stdClass)', $attributes->get('object')); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\HeaderBag', $c->getResponseHeaders()); $this->assertSame('OK', $c->getStatusText()); $this->assertSame(200, $c->getStatusCode()); $this->assertSame('application/json', $c->getContentType()); }
/** * @dataProvider provider */ public function testCollect(Request $request, Response $response) { $c = new RequestDataCollector(); $c->collect($request, $response); $this->assertSame('request', $c->getName()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\HeaderBag', $c->getRequestHeaders()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestServer()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestCookies()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestAttributes()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestRequest()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\ParameterBag', $c->getRequestQuery()); $this->assertEquals('html', $c->getFormat()); $this->assertEquals(array(), $c->getSessionAttributes()); $this->assertEquals('en', $c->getLocale()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\HeaderBag', $c->getResponseHeaders()); $this->assertEquals('OK', $c->getStatusText()); $this->assertEquals(200, $c->getStatusCode()); $this->assertEquals('application/json', $c->getContentType()); }
public function testItIgnoresInvalidCallables() { $request = $this->createRequestWithSession(); $response = new RedirectResponse('/'); $c = new RequestDataCollector(); $c->collect($request, $response); $this->assertSame('n/a', $c->getController()); }
/** * {@inheritdoc} */ public function collect(Request $request, Response $response, \Exception $exception = null) { parent::collect($request, $response, $exception); $this->data['route'] = $request->attributes->get('_route'); }