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
2 changes: 1 addition & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function setJSON($data)
protected function parseOptions(array $options)
{
if (array_key_exists('baseURI', $options)) {
$this->baseURI = $this->baseURI->setURI($options['baseURI']);
$this->baseURI = new URI($options['baseURI']);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also problematic. In the constructor, we call $uri->useRawQueryString(), which prevents the use of parse_str(). This is important because parse_str() would modify query parameters - for example, converting http://example.com/?foo.bar=baz into foo_bar=baz.

unset($options['baseURI']);
}

Expand Down
33 changes: 0 additions & 33 deletions system/HTTP/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,39 +60,6 @@ public function getBody()
return $this->body;
}

/**
* Returns an array containing all headers.
*
* @return array<string, Header> An array of the request headers
*
* @deprecated 4.0.5 Use Message::headers() to make room for PSR-7
*
* @TODO Incompatible return value with PSR-7
*
* @codeCoverageIgnore
*/
public function getHeaders(): array
{
return $this->headers();
}

/**
* Returns a single header object. If multiple headers with the same
* name exist, then will return an array of header objects.
*
* @return array|Header|null
*
* @deprecated 4.0.5 Use Message::header() to make room for PSR-7
*
* @TODO Incompatible return value with PSR-7
*
* @codeCoverageIgnore
*/
public function getHeader(string $name)
{
return $this->header($name);
}

/**
* Determines whether a header exists.
*/
Expand Down
16 changes: 0 additions & 16 deletions system/HTTP/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,6 @@ public function __construct($config = null)
}
}

/**
* Sets the request method. Used when spoofing the request.
*
* @return $this
*
* @deprecated 4.0.5 Use withMethod() instead for immutability
*
* @codeCoverageIgnore
*/
public function setMethod(string $method)
{
$this->method = $method;

return $this;
}

/**
* Returns an instance with the specified method.
*
Expand Down
31 changes: 5 additions & 26 deletions system/HTTP/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ trait RequestTrait

/**
* IP address of the current user.
*
* @var string
*
* @deprecated 4.0.5 Will become private in a future release
*/
protected $ipAddress = '';
private string $ipAddress = '';

/**
* Stores values we've retrieved from PHP globals.
Expand Down Expand Up @@ -78,11 +74,11 @@ public function getIPAddress(): string
);
}

$this->ipAddress = $this->getServer('REMOTE_ADDR');
$this->ipAddress = $this->getServer('REMOTE_ADDR') ?? '0.0.0.0';

// If this is a CLI request, $this->ipAddress is null.
if ($this->ipAddress === null) {
return $this->ipAddress = '0.0.0.0';
// If this is a CLI request, $this->ipAddress is '0.0.0.0'.
if ($this->ipAddress === '0.0.0.0') {
return $this->ipAddress;
}

// @TODO Extract all this IP address logic to another class.
Expand Down Expand Up @@ -206,23 +202,6 @@ public function getServer($index = null, $filter = null, $flags = null)
return $this->fetchGlobal('server', $index, $filter, $flags);
}

/**
* Fetch an item from the $_ENV array.
*
* @param array|string|null $index Index for item to be fetched from $_ENV
* @param int|null $filter A filter name to be applied
* @param array|int|null $flags
*
* @return mixed
*
* @deprecated 4.4.4 This method does not work from the beginning. Use `env()`.
*/
public function getEnv($index = null, $filter = null, $flags = null)
{
// @phpstan-ignore-next-line
return $this->fetchGlobal('env', $index, $filter, $flags);
}

/**
* Allows manually setting the value of PHP global, like $_GET, $_POST, etc.
*
Expand Down
57 changes: 9 additions & 48 deletions system/HTTP/SiteURI.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace CodeIgniter\HTTP;

use CodeIgniter\Exceptions\BadMethodCallException;
use CodeIgniter\Exceptions\ConfigException;
use CodeIgniter\HTTP\Exceptions\HTTPException;
use Config\App;
Expand Down Expand Up @@ -53,26 +52,10 @@ class SiteURI extends URI
* 1 => 'public',
* 2 => 'index.php',
* ];
*/
private array $baseSegments;

/**
* List of URI segments after indexPage.
*
* The word "URI Segments" originally means only the URI path part relative
* to the baseURL.
*
* If the URI is "http://localhost:8888/ci431/public/index.php/test?a=b",
* and the baseURL is "http://localhost:8888/ci431/public/", then:
* $segments = [
* 0 => 'test',
* ];
*
* @var array<int, string>
*
* @deprecated 4.4.0 This property will be private.
* @var list<string>
*/
protected $segments;
private array $baseSegments;

/**
* URI path relative to baseURL.
Expand Down Expand Up @@ -149,9 +132,9 @@ private function determineBaseURL(

// Update scheme
if ($scheme !== null && $scheme !== '') {
$uri->setScheme($scheme);
$uri = $uri->withScheme($scheme);
} elseif ($configApp->forceGlobalSecureRequests) {
$uri->setScheme('https');
$uri = $uri->withScheme('https');
}

// Update host
Expand Down Expand Up @@ -219,26 +202,10 @@ private function setBasePath(): void
}
}

/**
* @deprecated 4.4.0
*/
public function setBaseURL(string $baseURL): void
{
throw new BadMethodCallException('Cannot use this method.');
}

/**
* @deprecated 4.4.0
*/
public function setURI(?string $uri = null)
{
throw new BadMethodCallException('Cannot use this method.');
}

/**
* Returns the baseURL.
*
* @interal
* @internal
*/
public function getBaseURL(): string
{
Expand Down Expand Up @@ -298,23 +265,21 @@ private function setRoutePath(string $routePath): void
}

/**
* Converts path to segments
* @return list<string>
*/
private function convertToSegments(string $path): array
{
$tempPath = trim($path, '/');

return ($tempPath === '') ? [] : explode('/', $tempPath);
return $tempPath === '' ? [] : explode('/', $tempPath);
}

/**
* Sets the path portion of the URI based on segments.
*
* @return $this
*
* @deprecated 4.4.0 This method will be private.
*/
public function refreshPath()
protected function refreshPath(): self
{
$allSegments = array_merge($this->baseSegments, $this->segments);
$this->path = '/' . $this->filterPath(implode('/', $allSegments));
Expand Down Expand Up @@ -364,11 +329,7 @@ protected function applyParts(array $parts): void
$this->fragment = $parts['fragment'];
}

if (isset($parts['scheme'])) {
$this->setScheme(rtrim($parts['scheme'], ':/'));
} else {
$this->setScheme('http');
}
$this->scheme = $this->withScheme($parts['scheme'] ?? 'http')->getScheme();

if (isset($parts['port'])) {
// Valid port numbers are enforced by earlier parse_url or setPort()
Expand Down
Loading
Loading