diff --git a/src/Symfony/Bundle/FrameworkBundle/Client.php b/src/Symfony/Bundle/FrameworkBundle/Client.php index 181964976903b..c3e61293b21a2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Client.php +++ b/src/Symfony/Bundle/FrameworkBundle/Client.php @@ -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. @@ -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); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 4466b260ff5a6..463d2aa1df685 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -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']); diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php b/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php index f07c994a5d713..960ff1bbb1fce 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php @@ -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. @@ -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) { @@ -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') + ); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml index 674e28f1c98a0..fa477ba4e4f84 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml @@ -10,6 +10,7 @@ Symfony\Component\Filesystem\Filesystem Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer + Symfony\Component\HttpFoundation\Factory\RequestFactory Symfony\Component\HttpKernel\Config\FileLocator Symfony\Component\HttpKernel\UriSigner @@ -42,6 +43,8 @@ --> + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml index 4e609a06e5d95..816f82198c125 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml @@ -18,6 +18,7 @@ %test.client.parameters% + diff --git a/src/Symfony/Component/HttpFoundation/Factory/RequestFactory.php b/src/Symfony/Component/HttpFoundation/Factory/RequestFactory.php new file mode 100644 index 0000000000000..17f96ae6b4953 --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/Factory/RequestFactory.php @@ -0,0 +1,29 @@ + + * + * 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 + */ +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); + } +} diff --git a/src/Symfony/Component/HttpFoundation/Factory/RequestFactoryInterface.php b/src/Symfony/Component/HttpFoundation/Factory/RequestFactoryInterface.php new file mode 100644 index 0000000000000..dbd074bf0f021 --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/Factory/RequestFactoryInterface.php @@ -0,0 +1,35 @@ + + * + * 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 + */ +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); +} diff --git a/src/Symfony/Component/HttpKernel/Client.php b/src/Symfony/Component/HttpKernel/Client.php index bb427b35af22d..d453de8c39d50 100644 --- a/src/Symfony/Component/HttpKernel/Client.php +++ b/src/Symfony/Component/HttpKernel/Client.php @@ -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; /** @@ -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); @@ -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())); diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Esi.php b/src/Symfony/Component/HttpKernel/HttpCache/Esi.php index 455b3dcce968b..6253f1987cc3c 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/Esi.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/Esi.php @@ -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. @@ -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(); } /** @@ -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); diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Store.php b/src/Symfony/Component/HttpKernel/HttpCache/Store.php index a1cda1fd27095..14a99d7f06b0a 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/Store.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/Store.php @@ -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). @@ -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(); } @@ -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; diff --git a/src/Symfony/Component/HttpKernel/Tests/Request/RequestFactoryTest.php b/src/Symfony/Component/HttpKernel/Tests/Request/RequestFactoryTest.php new file mode 100644 index 0000000000000..341c008a6ed8d --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Tests/Request/RequestFactoryTest.php @@ -0,0 +1,28 @@ + + * + * 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') + ); + } +}