Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Permit HttpFoundation\Request class override #7461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions 5 src/Symfony/Bundle/FrameworkBundle/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\BrowserKit\History;
use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\HttpFoundation\Factory\RequestFactoryInterface;

/**
* Client simulates a browser and makes requests to a Kernel object.
Expand All @@ -33,9 +34,9 @@ class Client extends BaseClient
/**
* @inheritdoc
*/
public function __construct(KernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null)
public function __construct(KernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null, RequestFactoryInterface $requestFactory = null)
{
parent::__construct($kernel, $server, $history, $cookieJar);
parent::__construct($kernel, $server, $history, $cookieJar, $requestFactory);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function load(array $configs, ContainerBuilder $container)
}

$container->setParameter('kernel.http_method_override', $config['http_method_override']);

$container->setParameter('kernel.trusted_proxies', $config['trusted_proxies']);
$container->setParameter('kernel.default_locale', $config['default_locale']);

Expand Down
10 changes: 7 additions & 3 deletions 10 src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\HttpKernel\HttpCache\Store;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Factory\RequestFactoryInterface;

/**
* Manages HTTP cache objects in a Container.
Expand All @@ -32,7 +33,7 @@ abstract class HttpCache extends BaseHttpCache
* Constructor.
*
* @param HttpKernelInterface $kernel An HttpKernelInterface instance
* @param string $cacheDir The cache directory (default used if null)
* @param string|null $cacheDir The cache directory (default used if null)
*/
public function __construct(HttpKernelInterface $kernel, $cacheDir = null)
{
Expand Down Expand Up @@ -72,11 +73,14 @@ protected function getOptions()

protected function createEsi()
{
return new Esi();
return new Esi($this->getKernel()->getContainer()->get('request_factory'));
}

protected function createStore()
{
return new Store($this->cacheDir ?: $this->kernel->getCacheDir().'/http_cache');
return new Store(
$this->cacheDir ?: $this->kernel->getCacheDir().'/http_cache',
$this->getKernel()->getContainer()->get('request_factory')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<parameter key="filesystem.class">Symfony\Component\Filesystem\Filesystem</parameter>
<parameter key="cache_warmer.class">Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate</parameter>
<parameter key="cache_clearer.class">Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer</parameter>
<parameter key="request_factory.class">Symfony\Component\HttpFoundation\Factory\RequestFactory</parameter>
<parameter key="file_locator.class">Symfony\Component\HttpKernel\Config\FileLocator</parameter>
<parameter key="uri_signer.class">Symfony\Component\HttpKernel\UriSigner</parameter>
</parameters>
Expand Down Expand Up @@ -42,6 +43,8 @@
-->
<service id="request" scope="request" synthetic="true" synchronized="true" />

<service id="request_factory" class="%request_factory.class%" />

<service id="service_container" synthetic="true" />

<service id="kernel" synthetic="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<argument>%test.client.parameters%</argument>
<argument type="service" id="test.client.history" />
<argument type="service" id="test.client.cookiejar" />
<argument type="service" id="request_factory" />
</service>

<service id="test.client.history" class="%test.client.history.class%" scope="prototype" />
Expand Down
29 changes: 29 additions & 0 deletions 29 src/Symfony/Component/HttpFoundation/Factory/RequestFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpFoundation\Factory;

use Symfony\Component\HttpFoundation\Factory\RequestFactoryInterface;
use Symfony\Component\HttpFoundation\Request;

/**
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class RequestFactory implements RequestFactoryInterface
{
/**
* {@inheritdoc}
*/
public function create($uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null)
{
return Request::create($uri, $method, $parameters, $cookies, $files, $server, $content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpFoundation\Factory;

use Symfony\Component\HttpFoundation\Request;

/**
* @author Jean-François Simon <contact@jfsimon.fr>
*/
interface RequestFactoryInterface
{
/**
* Creates a Request based on a given URI and configuration.
*
* @param string $uri The URI
* @param string $method The HTTP method
* @param array $parameters The query (GET) or request (POST) parameters
* @param array $cookies The request cookies ($_COOKIE)
* @param array $files The request files ($_FILES)
* @param array $server The server parameters ($_SERVER)
* @param string $content The raw body data
*
* @return Request
*/
public function create($uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null);
}
17 changes: 11 additions & 6 deletions 17 src/Symfony/Component/HttpKernel/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use Symfony\Component\BrowserKit\Cookie as DomCookie;
use Symfony\Component\BrowserKit\History;
use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\HttpFoundation\Factory\RequestFactory;
use Symfony\Component\HttpFoundation\Factory\RequestFactoryInterface;
use Symfony\Component\HttpKernel\TerminableInterface;

/**
Expand All @@ -32,18 +34,21 @@
class Client extends BaseClient
{
protected $kernel;
private $requestFactory;

/**
* Constructor.
*
* @param HttpKernelInterface $kernel An HttpKernel instance
* @param array $server The server parameters (equivalent of $_SERVER)
* @param History $history A History instance to store the browser history
* @param CookieJar $cookieJar A CookieJar instance to store the cookies
* @param HttpKernelInterface $kernel An HttpKernel instance
* @param array $server The server parameters (equivalent of $_SERVER)
* @param History $history A History instance to store the browser history
* @param CookieJar $cookieJar A CookieJar instance to store the cookies
* @param RequestFactoryInterface|null $requestFactory The class used to create a request (must extend 'Symfony\Component\HttpFoundation\Request')
*/
public function __construct(HttpKernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null)
public function __construct(HttpKernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null, RequestFactoryInterface $requestFactory = null)
{
$this->kernel = $kernel;
$this->requestFactory = $requestFactory ?: new RequestFactory();

parent::__construct($server, $history, $cookieJar);

Expand Down Expand Up @@ -127,7 +132,7 @@ protected function getScript($request)
*/
protected function filterRequest(DomRequest $request)
{
$httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
$httpRequest = $this->requestFactory->create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());

$httpRequest->files->replace($this->filterFiles($httpRequest->files->all()));

Expand Down
13 changes: 9 additions & 4 deletions 13 src/Symfony/Component/HttpKernel/HttpCache/Esi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Factory\RequestFactory;
use Symfony\Component\HttpFoundation\Factory\RequestFactoryInterface;

/**
* Esi implements the ESI capabilities to Request and Response instances.
Expand All @@ -29,16 +31,19 @@
class Esi
{
private $contentTypes;
private $requestFactory;

/**
* Constructor.
*
* @param array $contentTypes An array of content-type that should be parsed for ESI information.
* (default: text/html, text/xml, application/xhtml+xml, and application/xml)
* @param array $contentTypes An array of content-type that should be parsed for ESI information.
* (default: text/html, text/xml, application/xhtml+xml, and application/xml)
* @param \Symfony\Component\HttpFoundation\Factory\RequestFactoryInterface|null $requestFactory
*/
public function __construct(array $contentTypes = array('text/html', 'text/xml', 'application/xhtml+xml', 'application/xml'))
public function __construct(array $contentTypes = array('text/html', 'text/xml', 'application/xhtml+xml', 'application/xml'), RequestFactoryInterface $requestFactory = null)
{
$this->contentTypes = $contentTypes;
$this->requestFactory = $requestFactory ?: new RequestFactory();
}

/**
Expand Down Expand Up @@ -194,7 +199,7 @@ public function process(Request $request, Response $response)
*/
public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors)
{
$subRequest = Request::create($uri, 'get', array(), $cache->getRequest()->cookies->all(), array(), $cache->getRequest()->server->all());
$subRequest = $this->requestFactory->create($uri, 'get', array(), $cache->getRequest()->cookies->all(), array(), $cache->getRequest()->server->all());

try {
$response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
Expand Down
11 changes: 8 additions & 3 deletions 11 src/Symfony/Component/HttpKernel/HttpCache/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Factory\RequestFactory;
use Symfony\Component\HttpFoundation\Factory\RequestFactoryInterface;

/**
* Store implements all the logic for storing cache metadata (Request and Response headers).
Expand All @@ -27,18 +29,21 @@ class Store implements StoreInterface
protected $root;
private $keyCache;
private $locks;
private $requestFactory;

/**
* Constructor.
*
* @param string $root The path to the cache directory
* @param string $root The path to the cache directory
* @param RequestFactoryInterface|null $requestFactory
*/
public function __construct($root)
public function __construct($root, RequestFactoryInterface $requestFactory = null)
{
$this->root = $root;
if (!is_dir($this->root)) {
mkdir($this->root, 0777, true);
}
$this->requestFactory = $requestFactory ?: new RequestFactory();
$this->keyCache = new \SplObjectStorage();
$this->locks = array();
}
Expand Down Expand Up @@ -303,7 +308,7 @@ private function getMetadata($key)
*/
public function purge($url)
{
if (is_file($path = $this->getPath($this->getCacheKey(Request::create($url))))) {
if (is_file($path = $this->getPath($this->getCacheKey($this->requestFactory->create($url))))) {
unlink($path);

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpKernel\Tests\Request;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Factory\RequestFactory;

class RequestFactoryTest extends \PHPUnit_Framework_TestCase
{
public function testCreateRequest()
{
$factory = new RequestFactory();

$this->assertEquals(
Request::create('uri', 'method', array('parameter' => 'value'), array('cookie' => 'value'), array(), array('server' => 'value'), 'content'),
$factory->create('uri', 'method', array('parameter' => 'value'), array('cookie' => 'value'), array(), array('server' => 'value'), 'content')
);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.