Skip to content

Commit e588cd6

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into develop
2 parents 1639f88 + 764cd55 commit e588cd6

File tree

13 files changed

+106
-260
lines changed

13 files changed

+106
-260
lines changed

phpstan-bootstrap.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
require __DIR__ . '/system/util_bootstrap.php';
44

5-
if (! defined('OCI_COMMIT_ON_SUCCESS')) {
6-
define('OCI_COMMIT_ON_SUCCESS', 32);
5+
defined('OCI_COMMIT_ON_SUCCESS') || define('OCI_COMMIT_ON_SUCCESS', 32);
6+
7+
foreach ([
8+
'app/Config',
9+
] as $directory) {
10+
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
11+
12+
/** @var SplFileInfo $file */
13+
foreach ($iterator as $file) {
14+
if ($file->isFile() && $file->getExtension() === 'php') {
15+
require_once $file->getRealPath();
16+
}
17+
}
718
}

rector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
])
7272
// do you need to include constants, class aliases or custom autoloader? files listed will be executed
7373
->withBootstrapFiles([
74-
__DIR__ . '/system/util_bootstrap.php',
74+
__DIR__ . '/phpstan-bootstrap.php',
7575
])
7676
->withPHPStanConfigs([
7777
__DIR__ . '/phpstan.neon.dist',

system/Boot.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,8 @@ protected static function initializeConsole(): Console
373373
$console = new Console();
374374

375375
// Show basic information before we do anything else.
376-
// @phpstan-ignore-next-line
377376
if (is_int($suppress = array_search('--no-header', $_SERVER['argv'], true))) {
378-
unset($_SERVER['argv'][$suppress]); // @phpstan-ignore-line
377+
unset($_SERVER['argv'][$suppress]);
379378
$suppress = true;
380379
}
381380

system/Database/BaseConnection.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,7 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s
652652
$query->setDuration($startTime, $startTime);
653653

654654
// This will trigger a rollback if transactions are being used
655-
if ($this->transDepth !== 0) {
656-
$this->transStatus = false;
657-
}
655+
$this->handleTransStatus();
658656

659657
if (
660658
$this->DBDebug
@@ -904,6 +902,18 @@ public function resetTransStatus(): static
904902
return $this;
905903
}
906904

905+
/**
906+
* Handle transaction status when a query fails
907+
*
908+
* @internal This method is for internal database component use only
909+
*/
910+
public function handleTransStatus(): void
911+
{
912+
if ($this->transDepth !== 0) {
913+
$this->transStatus = false;
914+
}
915+
}
916+
907917
/**
908918
* Begin Transaction
909919
*/

system/Database/BasePreparedQuery.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ public function execute(...$data)
134134
$query->setDuration($startTime, $startTime);
135135

136136
// This will trigger a rollback if transactions are being used
137-
if ($this->db->transDepth !== 0) {
138-
$this->db->transStatus = false;
139-
}
137+
$this->db->handleTransStatus();
140138

141139
if ($this->db->DBDebug) {
142140
// We call this function in order to roll-back queries

system/HTTP/URI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public function getAuthority(bool $ignorePort = false): string
376376
}
377377

378378
// Don't add port if it's a standard port for this scheme
379-
if ((int) $this->port !== 0 && ! $ignorePort && $this->port !== $this->defaultPorts[$this->scheme]) {
379+
if ((int) $this->port !== 0 && ! $ignorePort && $this->port !== ($this->defaultPorts[$this->scheme] ?? null)) {
380380
$authority .= ':' . $this->port;
381381
}
382382

tests/system/Database/Live/PreparedQueryTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,44 @@ public function testInsertBinaryData(): void
304304

305305
$this->assertSame(strlen($fileContent), strlen($file));
306306
}
307+
308+
public function testHandleTransStatusMarksTransactionFailedDuringTransaction(): void
309+
{
310+
$this->db->transStart();
311+
312+
// Verify we're in a transaction
313+
$this->assertSame(1, $this->db->transDepth);
314+
315+
// Prepare a query that will fail (duplicate key)
316+
$this->query = $this->db->prepare(static fn ($db) => $db->table('without_auto_increment')->insert([
317+
'key' => 'a',
318+
'value' => 'b',
319+
]));
320+
321+
$this->disableDBDebug();
322+
323+
$this->assertTrue($this->query->execute('test_key', 'test_value'));
324+
$this->assertTrue($this->db->transStatus());
325+
326+
$this->seeInDatabase($this->db->DBPrefix . 'without_auto_increment', [
327+
'key' => 'test_key',
328+
'value' => 'test_value'
329+
]);
330+
331+
$this->assertFalse($this->query->execute('test_key', 'different_value'));
332+
$this->assertFalse($this->db->transStatus());
333+
334+
$this->enableDBDebug();
335+
336+
// Complete the transaction - should rollback due to failed status
337+
$this->assertFalse($this->db->transComplete());
338+
339+
// Verify the first insert was rolled back
340+
$this->dontSeeInDatabase($this->db->DBPrefix . 'without_auto_increment', [
341+
'key' => 'test_key',
342+
'value' => 'test_value'
343+
]);
344+
345+
$this->db->resetTransStatus();
346+
}
307347
}

tests/system/HTTP/URITest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,22 @@ public static function provideAuthorityReturnsExceptedValues(): iterable
622622
'http://[email protected]:3000/bar',
623623
624624
],
625+
'rtsp-with-port' => [
626+
'rtsp://localhost:1234/stream',
627+
'localhost:1234',
628+
],
629+
'rtsp-no-port' => [
630+
'rtsp://localhost/stream',
631+
'localhost',
632+
],
633+
'custom-scheme-with-port' => [
634+
'myscheme://server:9999/resource',
635+
'server:9999',
636+
],
637+
'custom-scheme-no-port' => [
638+
'myscheme://server/resource',
639+
'server',
640+
],
625641
];
626642
}
627643

@@ -1226,4 +1242,17 @@ public function testForceGlobalSecureRequestsAndNonHTTPProtocol(): void
12261242

12271243
$this->assertSame($expected, (string) $uri);
12281244
}
1245+
1246+
/**
1247+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/9604
1248+
*/
1249+
public function testAuthorityIncludesPortForCustomSchemes(): void
1250+
{
1251+
$url = 'rtsp://localhost:1234/stream';
1252+
$uri = new URI($url);
1253+
1254+
$this->assertSame('rtsp://localhost:1234/stream', (string) $uri);
1255+
$this->assertSame('localhost:1234', $uri->getAuthority());
1256+
$this->assertSame(1234, $uri->getPort());
1257+
}
12291258
}

user_guide_src/source/changelogs/v4.6.2.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ Bugs Fixed
3737

3838
- **Cache:** Fixed a bug where a corrupted or unreadable cache file could cause an unhandled exception in ``FileHandler::getItem()``.
3939
- **Database:** Fixed a bug where ``when()`` and ``whenNot()`` in ``ConditionalTrait`` incorrectly evaluated certain falsy values (such as ``[]``, ``0``, ``0.0``, and ``'0'``) as truthy, causing callbacks to be executed unexpectedly. These methods now cast the condition to a boolean using ``(bool)`` to ensure consistent behavior with PHP's native truthiness.
40+
- **Database:** Fixed encapsulation violation in ``BasePreparedQuery`` when accessing ``BaseConnection::transStatus`` protected property.
4041
- **Email:** Fixed a bug where ``Email::getHostname()`` failed to use ``$_SERVER['SERVER_ADDR']`` when ``$_SERVER['SERVER_NAME']`` was not set.
4142
- **Security:** Fixed a bug where the ``sanitize_filename()`` function from the Security helper would throw an error when used in CLI requests.
4243
- **Session:** Fixed a bug where using the ``DatabaseHandler`` with an unsupported database driver (such as ``SQLSRV``, ``OCI8``, or ``SQLite3``) did not throw an appropriate error.
44+
- **URI:** Fixed a bug in ``URI::getAuthority()`` where schemes without defined default ports (like ``rtsp://``) would cause issues due to missing array key handling.
4345

4446
See the repo's
4547
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

user_guide_src/source/installation/upgrade_460.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ Config
210210
- ``Config\Feature::$strictLocaleNegotiation`` has been added.
211211
- app/Config/Routing.php
212212
- ``Config\Routing::$translateUriToCamelCase`` has been changed to ``true``.
213+
- app/Config/Kint.php
214+
- ``Config\Kint::$richSort`` has been removed. Kint in v6 no longer uses ``AbstractRenderer::SORT_FULL``. Leaving this property in your code will cause a runtime error due to the undefined constant.
213215

214216
All Changes
215217
===========

0 commit comments

Comments
 (0)