Skip to content
Draft
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/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ public function spoofRequestMethod()

// Only allows PUT, PATCH, DELETE
if (in_array($method, [Method::PUT, Method::PATCH, Method::DELETE], true)) {
$this->request = $this->request->setMethod($method);
$this->request = $this->request->withMethod($method);
}
}

Expand Down
12 changes: 4 additions & 8 deletions system/Commands/Utilities/Routes/FilterCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public function get(string $method, string $uri): array
return ['before' => [], 'after' => []];
}

$request = service('incomingrequest', null, false);
$request->setMethod($method);
$request = single_service('incomingrequest', null)->withMethod($method);

$router = $this->createRouter($request);
$filters = $this->createFilters($request);
Expand All @@ -77,8 +76,7 @@ public function getClasses(string $method, string $uri): array
return ['before' => [], 'after' => []];
}

$request = service('incomingrequest', null, false);
$request->setMethod($method);
$request = single_service('incomingrequest', null)->withMethod($method);

$router = $this->createRouter($request);
$filters = $this->createFilters($request);
Expand All @@ -95,8 +93,7 @@ public function getClasses(string $method, string $uri): array
*/
public function getRequiredFilters(): array
{
$request = service('incomingrequest', null, false);
$request->setMethod(Method::GET);
$request = single_service('incomingrequest', null)->withMethod(Method::GET);

$router = $this->createRouter($request);
$filters = $this->createFilters($request);
Expand All @@ -113,8 +110,7 @@ public function getRequiredFilters(): array
*/
public function getRequiredFilterClasses(): array
{
$request = service('incomingrequest', null, false);
$request->setMethod(Method::GET);
$request = single_service('incomingrequest', null)->withMethod(Method::GET);

$router = $this->createRouter($request);
$filters = $this->createFilters($request);
Expand Down
7 changes: 6 additions & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace CodeIgniter\HTTP;

use Closure;
use CodeIgniter\Exceptions\InvalidArgumentException;
use CodeIgniter\HTTP\Exceptions\HTTPException;
use Config\App;
Expand Down Expand Up @@ -313,7 +314,11 @@
protected function parseOptions(array $options)
{
if (array_key_exists('baseURI', $options)) {
$this->baseURI = $this->baseURI->setURI($options['baseURI']);
$this->baseURI = Closure::bind(
static fn (URI $uri): URI => $uri->setUri($options['baseURI']),

Check failure on line 318 in system/HTTP/CURLRequest.php

View workflow job for this annotation

GitHub Actions / Psalm Analysis (8.2)

InaccessibleMethod

system/HTTP/CURLRequest.php:318:52: InaccessibleMethod: Cannot access private method CodeIgniter\HTTP\URI::setUri from context CodeIgniter\HTTP\CURLRequest (see https://psalm.dev/003)
null,
URI::class,
)($this->baseURI);
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 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 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
17 changes: 2 additions & 15 deletions system/HTTP/OutgoingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,6 @@ public function getMethod(): string
return $this->method;
}

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

return $this;
}

/**
* Returns an instance with the specified method.
*
Expand All @@ -100,7 +86,8 @@ public function setMethod(string $method)
*/
public function withMethod($method)
{
$request = clone $this;
$request = clone $this;

$request->method = $method;

return $request;
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
17 changes: 0 additions & 17 deletions system/HTTP/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,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
107 changes: 13 additions & 94 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 @@ -43,37 +42,6 @@
*/
private readonly string $indexPage;

/**
* List of URI segments in baseURL and indexPage.
*
* If the URI is "http://localhost:8888/ci431/public/index.php/test?a=b",
* and the baseURL is "http://localhost:8888/ci431/public/", then:
* $baseSegments = [
* 0 => 'ci431',
* 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 This property will be private.
*/
protected $segments;

/**
* URI path relative to baseURL.
*
Expand Down Expand Up @@ -147,16 +115,14 @@

$uri = new URI($baseURL);

// 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
if ($host !== null) {
$uri->setHost($host);
$uri = $uri->setHost($host);
}

return $uri;
Expand Down Expand Up @@ -211,34 +177,12 @@
private function setBasePath(): void
{
$this->basePathWithoutIndexPage = $this->baseURL->getPath();

$this->baseSegments = $this->convertToSegments($this->basePathWithoutIndexPage);

if ($this->indexPage !== '') {
$this->baseSegments[] = $this->indexPage;
}
}

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

/**
* @deprecated
*/
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 @@ -300,46 +244,25 @@
/**
* Converts path to segments
*/
private function convertToSegments(string $path): array

Check failure on line 247 in system/HTTP/SiteURI.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Method CodeIgniter\HTTP\SiteURI::convertToSegments() return type has no value type specified in iterable type array.
{
$tempPath = trim($path, '/');

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

/**
* Sets the path portion of the URI based on segments.
*
* @return $this
*
* @deprecated This method will be private.
*/
public function refreshPath()
{
$allSegments = array_merge($this->baseSegments, $this->segments);
$this->path = '/' . $this->filterPath(implode('/', $allSegments));

if ($this->routePath === '/' && $this->path !== '/') {
$this->path .= '/';
}

$this->routePath = $this->filterPath(implode('/', $this->segments));

return $this;
}

/**
* Saves our parts from a parse_url() call.
*
* @param array{
* host?: string,
* user?: string,
* path?: string,
* query?: string,
* fragment?: string,
* scheme?: string,
* port?: int,
* pass?: string,
* host?: string,
* user?: string,
* path?: string,
* query?: string,
* fragment?: string,
* scheme?: string,
* port?: int,
* pass?: string,
* } $parts
*/
protected function applyParts(array $parts): void
Expand All @@ -364,11 +287,7 @@
$this->fragment = $parts['fragment'];
}

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

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