Skip to content
Open
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
15 changes: 9 additions & 6 deletions system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ public static function csp(?CSPConfig $config = null, bool $getShared = true)
* The CURL Request class acts as a simple HTTP client for interacting
* with other servers, typically through APIs.
*
* @todo v4.8.0 Remove $config parameter since unused
*
* @return CURLRequest
*/
public static function curlrequest(array $options = [], ?ResponseInterface $response = null, ?App $config = null, bool $getShared = true)
Expand All @@ -207,7 +209,7 @@ public static function curlrequest(array $options = [], ?ResponseInterface $resp
}

$config ??= config(App::class);
$response ??= new Response($config);
$response ??= new Response();

return new CURLRequest(
$config,
Expand Down Expand Up @@ -576,6 +578,8 @@ public static function incomingrequest(?App $config = null, bool $getShared = tr
/**
* The Response class models an HTTP response.
*
* @todo v4.8.0 Remove $config parameter since unused
*
* @return ResponseInterface
*/
public static function response(?App $config = null, bool $getShared = true)
Expand All @@ -584,14 +588,14 @@ public static function response(?App $config = null, bool $getShared = true)
return static::getSharedInstance('response', $config);
}

$config ??= config(App::class);

return new Response($config);
return new Response();
}

/**
* The Redirect class provides nice way of working with redirects.
*
* @todo v4.8.0 Remove $config parameter since unused
*
* @return RedirectResponse
*/
public static function redirectresponse(?App $config = null, bool $getShared = true)
Expand All @@ -600,8 +604,7 @@ public static function redirectresponse(?App $config = null, bool $getShared = t
return static::getSharedInstance('redirectresponse', $config);
}

$config ??= config(App::class);
$response = new RedirectResponse($config);
$response = new RedirectResponse();
$response->setProtocolVersion(AppServices::get('request')->getProtocolVersion());

return $response;
Expand Down
6 changes: 5 additions & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ class CURLRequest extends OutgoingRequest
* - timeout
* - any other request options to use as defaults.
*
* @todo v4.8.0 Remove $config parameter since unused
*
* @param array<string, mixed> $options
*
* @phpstan-ignore-next-line constructor.unusedParameter
*/
public function __construct(App $config, URI $uri, ?ResponseInterface $response = null, array $options = [])
{
Expand All @@ -125,7 +129,7 @@ public function __construct(App $config, URI $uri, ?ResponseInterface $response

parent::__construct(Method::GET, $uri);

$this->responseOrig = $response ?? new Response($config);
$this->responseOrig = $response ?? new Response();
// Remove the default Content-Type header.
$this->responseOrig->removeHeader('Content-Type');

Expand Down
6 changes: 1 addition & 5 deletions system/HTTP/DownloadResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use CodeIgniter\Exceptions\DownloadException;
use CodeIgniter\Files\File;
use Config\App;
use Config\Mimes;

/**
Expand Down Expand Up @@ -64,12 +63,9 @@ class DownloadResponse extends Response implements NonBufferedResponseInterface
*/
protected $statusCode = 200;

/**
* Constructor.
*/
public function __construct(string $filename, bool $setMime)
{
parent::__construct(config(App::class));
parent::__construct();

$this->filename = $filename;
$this->setMime = $setMime;
Expand Down
12 changes: 1 addition & 11 deletions system/HTTP/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use CodeIgniter\Cookie\Cookie;
use CodeIgniter\Cookie\CookieStore;
use CodeIgniter\HTTP\Exceptions\HTTPException;
use Config\App;
use Config\Cookie as CookieConfig;

/**
Expand Down Expand Up @@ -141,16 +140,7 @@ class Response extends Message implements ResponseInterface
*/
protected $pretend = false;

/**
* Constructor
*
* @param App $config
*
* @todo Recommend removing reliance on config injection
*
* @deprecated 4.5.0 The param $config is no longer used.
*/
public function __construct($config) // @phpstan-ignore-line
public function __construct()
{
// Default to a non-caching page.
// Also ensures that a Cache-control header exists.
Expand Down
3 changes: 1 addition & 2 deletions system/HTTP/SSEResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace CodeIgniter\HTTP;

use Closure;
use Config\App;
use JsonException;

/**
Expand All @@ -31,7 +30,7 @@ class SSEResponse extends Response implements NonBufferedResponseInterface
*/
public function __construct(private readonly Closure $callback)
{
parent::__construct(config(App::class));
parent::__construct();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/system/API/ResponseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function createRequestAndResponse(string $routePath = '', array $userHea
null,
new UserAgent(),
);
$this->response = new MockResponse($config);
$this->response = new MockResponse();
}

$headers = array_merge(['Accept' => 'text/html'], $userHeaders);
Expand Down Expand Up @@ -625,7 +625,7 @@ public function testFormatByRequestNegotiateIfFormatIsNotJsonOrXML(): void
$this->createCookieConfig();

$request = new MockIncomingRequest($config, new SiteURI($config), null, new UserAgent());
$response = new MockResponse($config);
$response = new MockResponse();

$controller = new class ($request, $response) {
use ResponseTrait;
Expand Down
38 changes: 19 additions & 19 deletions tests/system/Cache/ResponseCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testCachePageIncomingRequest(): void
{
$pageCache = $this->createResponseCache();

$response = new Response(new App());
$response = new Response();
$response->setHeader('ETag', 'abcd1234');
$response->setBody('The response body.');

Expand All @@ -97,37 +97,37 @@ public function testCachePageIncomingRequest(): void
));

// Check cache with a request with the same URI path.
$cachedResponse = $pageCache->get($this->createIncomingRequest('foo/bar'), new Response(new App()));
$cachedResponse = $pageCache->get($this->createIncomingRequest('foo/bar'), new Response());
$this->assertInstanceOf(ResponseInterface::class, $cachedResponse);
$this->assertSame('The response body.', $cachedResponse->getBody());
$this->assertSame('abcd1234', $cachedResponse->getHeaderLine('ETag'));

// Check cache with a request with the same URI path and different query string.
$cachedResponse = $pageCache->get(
$this->createIncomingRequest('foo/bar', ['foo' => 'bar', 'bar' => 'baz']),
new Response(new App()),
new Response(),
);
$this->assertInstanceOf(ResponseInterface::class, $cachedResponse);
$this->assertSame('The response body.', $cachedResponse->getBody());
$this->assertSame('abcd1234', $cachedResponse->getHeaderLine('ETag'));

// Check cache with another request with the different URI path.
$cachedResponse = $pageCache->get($this->createIncomingRequest('another'), new Response(new App()));
$cachedResponse = $pageCache->get($this->createIncomingRequest('another'), new Response());
$this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse);
}

public function testCachePageIncomingRequestWithStatus(): void
{
$pageCache = $this->createResponseCache();

$response = new Response(new App());
$response = new Response();
$response->setStatusCode(432, 'Foo Bar');
$response->setBody('The response body.');

$this->assertTrue($pageCache->make($this->createIncomingRequest('foo/bar'), $response));

// Check cached response status
$cachedResponse = $pageCache->get($this->createIncomingRequest('foo/bar'), new Response(new App()));
$cachedResponse = $pageCache->get($this->createIncomingRequest('foo/bar'), new Response());
$this->assertInstanceOf(ResponseInterface::class, $cachedResponse);
$this->assertSame(432, $cachedResponse->getStatusCode());
$this->assertSame('Foo Bar', $cachedResponse->getReasonPhrase());
Expand All @@ -143,7 +143,7 @@ public function testCachePageIncomingRequestWithCacheQueryString(): void

$request = $this->createIncomingRequest('foo/bar', ['foo' => 'bar', 'bar' => 'baz']);

$response = new Response(new App());
$response = new Response();
$response->setHeader('ETag', 'abcd1234');
$response->setBody('The response body.');

Expand All @@ -152,7 +152,7 @@ public function testCachePageIncomingRequestWithCacheQueryString(): void
// Check cache with a request with the same URI path and same query string.
$cachedResponse = $pageCache->get(
$this->createIncomingRequest('foo/bar', ['foo' => 'bar', 'bar' => 'baz']),
new Response(new App()),
new Response(),
);
$this->assertInstanceOf(ResponseInterface::class, $cachedResponse);
$this->assertSame('The response body.', $cachedResponse->getBody());
Expand All @@ -161,28 +161,28 @@ public function testCachePageIncomingRequestWithCacheQueryString(): void
// Check cache with a request with the same URI path and different query string.
$cachedResponse = $pageCache->get(
$this->createIncomingRequest('foo/bar', ['xfoo' => 'bar', 'bar' => 'baz']),
new Response(new App()),
new Response(),
);
$this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse);

// Check cache with another request with the different URI path.
$cachedResponse = $pageCache->get($this->createIncomingRequest('another'), new Response(new App()));
$cachedResponse = $pageCache->get($this->createIncomingRequest('another'), new Response());
$this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse);
}

public function testCachePageIncomingRequestWithHttpMethods(): void
{
$pageCache = $this->createResponseCache();

$response = new Response(new App());
$response = new Response();
$response->setBody('The response body.');

$this->assertTrue($pageCache->make($this->createIncomingRequest('foo/bar'), $response));

// Check cache with a request with the same URI path and different HTTP method
$cachedResponse = $pageCache->get(
$this->createIncomingRequest('foo/bar')->withMethod('POST'),
new Response(new App()),
new Response(),
);
$this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse);
}
Expand All @@ -191,18 +191,18 @@ public function testCachePageCLIRequest(): void
{
$pageCache = $this->createResponseCache();

$response = new Response(new App());
$response = new Response();
$response->setBody('The response body.');

$this->assertTrue($pageCache->make($this->createCLIRequest(['foo', 'bar']), $response));

// Check cache with a request with the same params.
$cachedResponse = $pageCache->get($this->createCLIRequest(['foo', 'bar']), new Response(new App()));
$cachedResponse = $pageCache->get($this->createCLIRequest(['foo', 'bar']), new Response());
$this->assertInstanceOf(ResponseInterface::class, $cachedResponse);
$this->assertSame('The response body.', $cachedResponse->getBody());

// Check cache with another request with the different params.
$cachedResponse = $pageCache->get($this->createCLIRequest(['baz']), new Response(new App()));
$cachedResponse = $pageCache->get($this->createCLIRequest(['baz']), new Response());
$this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse);
}

Expand All @@ -217,7 +217,7 @@ public function testUnserializeError(): void

$request = $this->createIncomingRequest('foo/bar');

$response = new Response(new App());
$response = new Response();
$response->setHeader('ETag', 'abcd1234');
$response->setBody('The response body.');

Expand All @@ -229,7 +229,7 @@ public function testUnserializeError(): void
$mockCache->save($cacheKey, 'Invalid data');

// Check cache with a request with the same URI path.
$pageCache->get($request, new Response(new App()));
$pageCache->get($request, new Response());
}

public function testInvalidCacheError(): void
Expand All @@ -243,7 +243,7 @@ public function testInvalidCacheError(): void

$request = $this->createIncomingRequest('foo/bar');

$response = new Response(new App());
$response = new Response();
$response->setHeader('ETag', 'abcd1234');
$response->setBody('The response body.');

Expand All @@ -255,6 +255,6 @@ public function testInvalidCacheError(): void
$mockCache->save($cacheKey, serialize(['a' => '1']));

// Check cache with a request with the same URI path.
$pageCache->get($request, new Response(new App()));
$pageCache->get($request, new Response());
}
}
6 changes: 3 additions & 3 deletions tests/system/CommonFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public function testOldInput(): void
'zibble' => 'fritz',
]);

$response = new RedirectResponse(new App());
$response = new RedirectResponse();
$response->withInput();

$this->assertSame('bar', old('foo')); // regular parameter
Expand Down Expand Up @@ -482,7 +482,7 @@ public function testOldInputSerializeData(): void
'zibble' => serialize('fritz'),
]);

$response = new RedirectResponse(new App());
$response = new RedirectResponse();
$response->withInput();

// serialized parameters are only HTML-escaped.
Expand Down Expand Up @@ -522,7 +522,7 @@ public function testOldInputArray(): void
$superglobals->setGetArray([]);
$superglobals->setPostArray(['location' => $locations]);

$response = new RedirectResponse(new App());
$response = new RedirectResponse();
$response->withInput();

$this->assertSame($locations, old('location'));
Expand Down
Loading
Loading