createRequest() public method

Creates a Request.
public createRequest ( Request $request, string $path ) : Request
$request Symfony\Component\HttpFoundation\Request The current Request instance
$path string A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo))
return Symfony\Component\HttpFoundation\Request A Request instance
Ejemplo n.º 1
0
    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());
    }
Ejemplo n.º 2
0
 /**
  * {@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);
 }
Ejemplo n.º 3
0
 /**
  * {@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);
 }
Ejemplo n.º 4
0
 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());
 }
Ejemplo n.º 5
0
 /**
  * @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));
 }