Skip to content

Commit 0a217c8

Browse files
committed
refactor: combine post_max_size methods and add default parameter handling in IncomingRequest
1 parent 2af2aa4 commit 0a217c8

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

‎system/HTTP/IncomingRequest.php‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,14 @@ public function __construct($config, ?URI $uri = null, $body = 'php://input', ?U
167167
$this->detectLocale($config);
168168
}
169169

170-
private function getPostMaxSize(): int
171-
{
172-
return $this->parsePostMaxSize((string) ini_get('post_max_size'));
173-
}
174-
175170
/**
176171
* Converts the `post_max_size` ini value to bytes.
177172
*
178173
* A value of 0 or less means unlimited.
179174
*/
180-
private function parsePostMaxSize(string $postMaxSize): int
175+
private function getPostMaxSize(?string $postMaxSize = null): int
181176
{
182-
$bytes = ini_parse_quantity($postMaxSize);
177+
$bytes = ini_parse_quantity($postMaxSize ?? (string) ini_get('post_max_size'));
183178

184179
return $bytes <= 0 ? PHP_INT_MAX : $bytes;
185180
}

‎tests/system/HTTP/IncomingRequestTest.php‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,21 +1081,23 @@ public function testSetPath(): void
10811081
$this->assertSame('foobar', $request->getPath());
10821082
}
10831083

1084-
#[DataProvider('provideParsePostMaxSize')]
1085-
public function testParsePostMaxSize(string $value, int $expected): void
1084+
#[DataProvider('provideGetPostMaxSize')]
1085+
public function testGetPostMaxSize(string $value, int $expected): void
10861086
{
1087-
$parsePostMaxSize = $this->getPrivateMethodInvoker($this->request, 'parsePostMaxSize');
1087+
$getPostMaxSize = $this->getPrivateMethodInvoker($this->request, 'getPostMaxSize');
10881088

1089-
$this->assertSame($expected, $parsePostMaxSize($value));
1089+
$this->assertSame($expected, $getPostMaxSize($value));
10901090
}
10911091

10921092
/**
10931093
* @return iterable<array{string, int}>
10941094
*/
1095-
public static function provideParsePostMaxSize(): iterable
1095+
public static function provideGetPostMaxSize(): iterable
10961096
{
10971097
yield 'zero means unlimited' => ['0', PHP_INT_MAX];
10981098

1099+
yield 'zero with suffix means unlimited' => ['0K', PHP_INT_MAX];
1100+
10991101
yield 'negative means unlimited' => ['-1', PHP_INT_MAX];
11001102

11011103
yield 'gigabytes' => ['1G', 1024 ** 3];
@@ -1119,6 +1121,16 @@ public static function provideParsePostMaxSize(): iterable
11191121
yield 'bytes' => ['12345', 12345];
11201122
}
11211123

1124+
public function testGetPostMaxSizeDefault(): void
1125+
{
1126+
$getPostMaxSize = $this->getPrivateMethodInvoker($this->request, 'getPostMaxSize');
1127+
1128+
$bytes = ini_parse_quantity((string) ini_get('post_max_size'));
1129+
$expected = $bytes <= 0 ? PHP_INT_MAX : $bytes;
1130+
1131+
$this->assertSame($expected, $getPostMaxSize());
1132+
}
1133+
11221134
public function testGetIPAddressNormal(): void
11231135
{
11241136
$expected = '123.123.123.123';

0 commit comments

Comments
 (0)