Permalink
Browse files

optimize duplication of Request objects

  • Loading branch information...
1 parent 06e2c01 commit 5d87d83a10ebf001c1609f626d27300479aba308 @subsven subsven committed with fabpot Feb 8, 2011
Showing with 56 additions and 16 deletions.
  1. +28 −8 src/Symfony/Component/HttpFoundation/Request.php
  2. +28 −8 src/Symfony/Component/HttpKernel/bootstrap.php
View
36 src/Symfony/Component/HttpFoundation/Request.php
@@ -223,14 +223,34 @@ static public function create($uri, $method = 'GET', $parameters = array(), $coo
public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
{
$dup = clone $this;
- $dup->initialize(
- null !== $query ? $query : $this->query->all(),
- null !== $request ? $request : $this->request->all(),
- null !== $attributes ? $attributes : $this->attributes->all(),
- null !== $cookies ? $cookies : $this->cookies->all(),
- null !== $files ? $files : $this->files->all(),
- null !== $server ? $server : $this->server->all()
- );
+ if ($query !== null) {
+ $dup->query = new ParameterBag($query);
+ }
+ if ($request !== null) {
+ $dup->request = new ParameterBag($request);
+ }
+ if ($attributes !== null) {
+ $dup->attributes = new ParameterBag($attributes);
+ }
+ if ($cookies !== null) {
+ $dup->cookies = new ParameterBag($cookies);
+ }
+ if ($files !== null) {
+ $dup->files = new FileBag($files);
+ }
+ if ($server !== null) {
+ $dup->server = new ServerBag($server);
+ $dup->headers = new HeaderBag($dup->server->getHeaders());
+ }
+ $this->languages = null;
+ $this->charsets = null;
+ $this->acceptableContentTypes = null;
+ $this->pathInfo = null;
+ $this->requestUri = null;
+ $this->baseUrl = null;
+ $this->basePath = null;
+ $this->method = null;
+ $this->format = null;
return $dup;
}
View
36 src/Symfony/Component/HttpKernel/bootstrap.php
@@ -1243,14 +1243,34 @@ static public function create($uri, $method = 'GET', $parameters = array(), $coo
public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
{
$dup = clone $this;
- $dup->initialize(
- null !== $query ? $query : $this->query->all(),
- null !== $request ? $request : $this->request->all(),
- null !== $attributes ? $attributes : $this->attributes->all(),
- null !== $cookies ? $cookies : $this->cookies->all(),
- null !== $files ? $files : $this->files->all(),
- null !== $server ? $server : $this->server->all()
- );
+ if ($query !== null) {
+ $dup->query = new ParameterBag($query);
+ }
+ if ($request !== null) {
+ $dup->request = new ParameterBag($request);
+ }
+ if ($attributes !== null) {
+ $dup->attributes = new ParameterBag($attributes);
+ }
+ if ($cookies !== null) {
+ $dup->cookies = new ParameterBag($cookies);
+ }
+ if ($files !== null) {
+ $dup->files = new FileBag($files);
+ }
+ if ($server !== null) {
+ $dup->server = new ServerBag($server);
+ $dup->headers = new HeaderBag($dup->server->getHeaders());
+ }
+ $this->languages = null;
+ $this->charsets = null;
+ $this->acceptableContentTypes = null;
+ $this->pathInfo = null;
+ $this->requestUri = null;
+ $this->baseUrl = null;
+ $this->basePath = null;
+ $this->method = null;
+ $this->format = null;
return $dup;
}
public function __clone()

0 comments on commit 5d87d83

Please sign in to comment.