Creates a Request.
public createRequest ( |
||
$request | The current Request instance | |
$path | string | A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo)) |
return | A Request instance |
public function testCreateRequest() { $utils = new HttpUtils($this->getRouter()); // absolute path $request = $this->getRequest(); $request->server->set('Foo', 'bar'); $subRequest = $utils->createRequest($request, '/foobar'); $this->assertEquals('GET', $subRequest->getMethod()); $this->assertEquals('/foobar', $subRequest->getPathInfo()); $this->assertEquals('bar', $subRequest->server->get('Foo')); // route name $utils = new HttpUtils($router = $this->getMockBuilder('Symfony\Component\Routing\Router')->disableOriginalConstructor()->getMock()); $router ->expects($this->once()) ->method('generate') ->will($this->returnValue('/foo/bar')) ; $router ->expects($this->any()) ->method('getContext') ->will($this->returnValue($this->getMock('Symfony\Component\Routing\RequestContext'))) ; $subRequest = $utils->createRequest($this->getRequest(), 'foobar'); $this->assertEquals('/foo/bar', $subRequest->getPathInfo()); // absolute URL $subRequest = $utils->createRequest($this->getRequest(), 'http://symfony.com/'); $this->assertEquals('/', $subRequest->getPathInfo()); }
/** * {@inheritDoc} */ public function start(Request $request, AuthenticationException $authException = null) { // redirect to the login url if there are several resource owners if (null === $this->resourceOwner) { return $this->httpUtils->createRedirectResponse($request, $this->loginPath); } // otherwise start authentication $authorizationUrl = $this->resourceOwner->getAuthorizationUrl($this->httpUtils->createRequest($request, $this->checkPath)->getUri()); return $this->httpUtils->createRedirectResponse($request, $authorizationUrl); }
/** * {@inheritDoc} */ public function start(Request $request, AuthenticationException $authException = null) { if ($this->useForward) { $subRequest = $this->httpUtils->createRequest($request, $this->loginPath); $response = $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST); if (200 === $response->getStatusCode()) { $response->headers->set('X-Status-Code', 401); } return $response; } return $this->httpUtils->createRedirectResponse($request, $this->loginPath); }
public function testCreateRequest() { $utils = new HttpUtils($this->getUrlGenerator()); // absolute path $request = $this->getRequest(); $request->server->set('Foo', 'bar'); $subRequest = $utils->createRequest($request, '/foobar'); $this->assertEquals('GET', $subRequest->getMethod()); $this->assertEquals('/foobar', $subRequest->getPathInfo()); $this->assertEquals('bar', $subRequest->server->get('Foo')); // route name $subRequest = $utils->createRequest($this->getRequest(), 'foobar'); $this->assertEquals('/foo/bar', $subRequest->getPathInfo()); // absolute URL $subRequest = $utils->createRequest($this->getRequest(), 'http://symfony.com/'); $this->assertEquals('/', $subRequest->getPathInfo()); }
/** * @dataProvider provideSecurityContextAttributes */ public function testCreateRequestPassesSecurityContextAttributesToTheNewRequest($attribute) { $request = $this->getRequest(); $request->attributes->set($attribute, 'foo'); $utils = new HttpUtils($this->getUrlGenerator()); $subRequest = $utils->createRequest($request, '/foobar'); $this->assertSame('foo', $subRequest->attributes->get($attribute)); }