Skip to content

Commit e392123

Browse files
committed
Release v4.3.6
1 parent b41bca4 commit e392123

29 files changed

+280
-188
lines changed

system/Autoloader/FileLocator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ public function __construct(Autoloader $autoloader)
3333
* Attempts to locate a file by examining the name for a namespace
3434
* and looking through the PSR-4 namespaced files that we know about.
3535
*
36-
* @param string $file The namespaced file to locate
37-
* @param string|null $folder The folder within the namespace that we should look for the file.
36+
* @param string $file The relative file path or namespaced file to
37+
* locate. If not namespaced, search in the app
38+
* folder.
39+
* @param string|null $folder The folder within the namespace that we should
40+
* look for the file. If $file does not contain
41+
* this value, it will be appended to the namespace
42+
* folder.
3843
* @param string $ext The file extension the file should have.
3944
*
4045
* @return false|string The path to the file, or false if not found.

system/CodeIgniter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CodeIgniter
4747
/**
4848
* The current version of CodeIgniter Framework
4949
*/
50-
public const CI_VERSION = '4.3.5';
50+
public const CI_VERSION = '4.3.6';
5151

5252
/**
5353
* App startup time.
@@ -310,8 +310,6 @@ private function configureKint(): void
310310
* makes all of the pieces work together.
311311
*
312312
* @return ResponseInterface|void
313-
*
314-
* @throws RedirectException
315313
*/
316314
public function run(?RouteCollectionInterface $routes = null, bool $returnResponse = false)
317315
{

system/Common.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,7 @@ function is_windows(?bool $mock = null): bool
744744
$mocked = $mock;
745745
}
746746

747-
if (isset($mocked)) {
748-
return $mocked;
749-
}
750-
751-
return DIRECTORY_SEPARATOR === '\\';
747+
return $mocked ?? DIRECTORY_SEPARATOR === '\\';
752748
}
753749
}
754750

system/Config/BaseConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function __construct()
8686
/**
8787
* Initialization an environment-specific configuration setting
8888
*
89-
* @param mixed $property
89+
* @param array|bool|float|int|string|null $property
9090
*
9191
* @return void
9292
*/

system/Config/Factories.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* instantiation checks.
2525
*
2626
* @method static BaseConfig|null config(...$arguments)
27+
* @method static Model|null models(string $name, array $options = [], ?ConnectionInterface &$conn = null)
2728
*/
2829
class Factories
2930
{
@@ -69,23 +70,6 @@ class Factories
6970
*/
7071
protected static $instances = [];
7172

72-
/**
73-
* This method is only to prevent PHPStan error.
74-
* If we have a solution, we can remove this method.
75-
* See https://github.com/codeigniter4/CodeIgniter4/pull/5358
76-
*
77-
* @template T of Model
78-
*
79-
* @phpstan-param class-string<T> $name
80-
*
81-
* @return Model
82-
* @phpstan-return T
83-
*/
84-
public static function models(string $name, array $options = [], ?ConnectionInterface &$conn = null)
85-
{
86-
return self::__callStatic('models', [$name, $options, $conn]);
87-
}
88-
8973
/**
9074
* Loads instances based on the method component name. Either
9175
* creates a new instance or returns an existing shared instance.

system/Database/BaseBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
19971997
}
19981998

19991999
if (isset($this->QBOptions['setQueryAsData'])) {
2000-
$data = $this->QBOptions['setQueryAsData'];
2000+
$data = $this->QBOptions['setQueryAsData'] . "\n";
20012001
} else {
20022002
$data = 'VALUES ' . implode(', ', $this->formatValues($values)) . "\n";
20032003
}

system/Database/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Config extends BaseConfig
3737
protected static $factory;
3838

3939
/**
40-
* Creates the default
40+
* Returns the database connection
4141
*
4242
* @param array|BaseConnection|string|null $group The name of the connection group to use,
4343
* or an array of configuration settings.

system/Database/Database.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Database Connection Factory
1818
*
19-
* Creates and returns an instance of the appropriate DatabaseConnection
19+
* Creates and returns an instance of the appropriate Database Connection.
2020
*/
2121
class Database
2222
{
@@ -32,8 +32,7 @@ class Database
3232
protected $connections = [];
3333

3434
/**
35-
* Parses the connection binds and returns an instance of the driver
36-
* ready to go.
35+
* Parses the connection binds and creates a Database Connection instance.
3736
*
3837
* @return BaseConnection
3938
*
@@ -83,7 +82,7 @@ public function loadUtils(ConnectionInterface $db): BaseUtils
8382
}
8483

8584
/**
86-
* Parse universal DSN string
85+
* Parses universal DSN string
8786
*
8887
* @throws InvalidArgumentException
8988
*/
@@ -121,21 +120,20 @@ protected function parseDSN(array $params): array
121120
}
122121

123122
/**
124-
* Initialize database driver.
123+
* Creates a database object.
125124
*
126125
* @param string $driver Driver name. FQCN can be used.
127-
* @param array|object $argument
126+
* @param string $class 'Connection'|'Forge'|'Utils'
127+
* @param array|object $argument The constructor parameter.
128128
*
129129
* @return BaseConnection|BaseUtils|Forge
130130
*/
131131
protected function initDriver(string $driver, string $class, $argument): object
132132
{
133-
$class = $driver . '\\' . $class;
133+
$classname = (strpos($driver, '\\') === false)
134+
? "CodeIgniter\\Database\\{$driver}\\{$class}"
135+
: $driver . '\\' . $class;
134136

135-
if (strpos($driver, '\\') === false) {
136-
$class = "CodeIgniter\\Database\\{$class}";
137-
}
138-
139-
return new $class($argument);
137+
return new $classname($argument);
140138
}
141139
}

system/Database/Postgre/Connection.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,11 @@ public function connect(bool $persistent = false)
6464
$this->buildDSN();
6565
}
6666

67-
// Strip pgsql if exists
67+
// Convert DSN string
6868
if (mb_strpos($this->DSN, 'pgsql:') === 0) {
69-
$this->DSN = mb_substr($this->DSN, 6);
69+
$this->convertDSN();
7070
}
7171

72-
// Convert semicolons to spaces.
73-
$this->DSN = str_replace(';', ' ', $this->DSN);
74-
7572
$this->connID = $persistent === true ? pg_pconnect($this->DSN) : pg_connect($this->DSN);
7673

7774
if ($this->connID !== false) {
@@ -92,6 +89,44 @@ public function connect(bool $persistent = false)
9289
return $this->connID;
9390
}
9491

92+
/**
93+
* Converts the DSN with semicolon syntax.
94+
*/
95+
private function convertDSN()
96+
{
97+
// Strip pgsql
98+
$this->DSN = mb_substr($this->DSN, 6);
99+
100+
// Convert semicolons to spaces in DSN format like:
101+
// pgsql:host=localhost;port=5432;dbname=database_name
102+
// https://www.php.net/manual/en/function.pg-connect.php
103+
$allowedParams = ['host', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service'];
104+
105+
$parameters = explode(';', $this->DSN);
106+
107+
$output = '';
108+
$previousParameter = '';
109+
110+
foreach ($parameters as $parameter) {
111+
[$key, $value] = explode('=', $parameter, 2);
112+
if (in_array($key, $allowedParams, true)) {
113+
if ($previousParameter !== '') {
114+
if (array_search($key, $allowedParams, true) < array_search($previousParameter, $allowedParams, true)) {
115+
$output .= ';';
116+
} else {
117+
$output .= ' ';
118+
}
119+
}
120+
$output .= $parameter;
121+
$previousParameter = $key;
122+
} else {
123+
$output .= ';' . $parameter;
124+
}
125+
}
126+
127+
$this->DSN = $output;
128+
}
129+
95130
/**
96131
* Keep or establish the connection if no queries have been sent for
97132
* a length of time exceeding the server's idle timeout.

system/Encryption/Encryption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public static function createKey($length = 32)
149149
*
150150
* @param string $key Property name
151151
*
152-
* @return mixed
152+
* @return array|string|null
153153
*/
154154
public function __get($key)
155155
{

system/Encryption/Handlers/BaseHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected static function substr($str, $start, $length = null)
6161
*
6262
* @param string $key Property name
6363
*
64-
* @return mixed
64+
* @return array|bool|int|string|null
6565
*/
6666
public function __get($key)
6767
{

system/Entity/Entity.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public function cast(?bool $cast = null)
429429
*
430430
* @param array|bool|float|int|object|string|null $value
431431
*
432-
* @return $this
432+
* @return void
433433
*
434434
* @throws Exception
435435
*/
@@ -452,16 +452,14 @@ public function __set(string $key, $value = null)
452452
if (method_exists($this, $method)) {
453453
$this->{$method}($value);
454454

455-
return $this;
455+
return;
456456
}
457457

458458
// Otherwise, just the value. This allows for creation of new
459459
// class properties that are undefined, though they cannot be
460460
// saved. Useful for grabbing values through joins, assigning
461461
// relationships, etc.
462462
$this->attributes[$dbColumn] = $value;
463-
464-
return $this;
465463
}
466464

467465
/**

system/Exceptions/FrameworkException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function forMissingExtension(string $extension)
4646
'The framework needs the following extension(s) installed and loaded: %s.',
4747
$extension
4848
);
49-
// @codeCoverageIgnoreEnd
49+
// @codeCoverageIgnoreEnd
5050
} else {
5151
$message = lang('Core.missingExtension', [$extension]);
5252
}

system/HTTP/IncomingRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ public function setLocale(string $locale)
554554
*/
555555
public function getLocale(): string
556556
{
557-
return $this->locale ?? $this->defaultLocale;
557+
return $this->locale;
558558
}
559559

560560
/**

system/Images/Handlers/GDHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ protected function getImageResource(string $path, int $imageType)
354354
throw ImageException::forInvalidImageCreate(lang('Images.pngNotSupported'));
355355
}
356356

357-
return imagecreatefrompng($path);
357+
return @imagecreatefrompng($path);
358358

359359
case IMAGETYPE_WEBP:
360360
if (! function_exists('imagecreatefromwebp')) {

system/Model.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -800,11 +800,7 @@ public function __get(string $name)
800800
return parent::__get($name);
801801
}
802802

803-
if (isset($this->builder()->{$name})) {
804-
return $this->builder()->{$name};
805-
}
806-
807-
return null;
803+
return $this->builder()->{$name} ?? null;
808804
}
809805

810806
/**

system/Router/AutoRouter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function __construct(
8080
*
8181
* @return array [directory_name, controller_name, controller_method, params]
8282
*/
83-
public function getRoute(string $uri): array
83+
public function getRoute(string $uri, string $httpVerb): array
8484
{
8585
$segments = explode('/', $uri);
8686

system/Router/AutoRouterImproved.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ final class AutoRouterImproved implements AutoRouterInterface
5858
*/
5959
private bool $translateURIDashes;
6060

61-
/**
62-
* HTTP verb for the request.
63-
*/
64-
private string $httpVerb;
65-
6661
/**
6762
* The namespace for controllers.
6863
*/
@@ -74,15 +69,17 @@ final class AutoRouterImproved implements AutoRouterInterface
7469
private string $defaultController;
7570

7671
/**
77-
* The name of the default method
72+
* The name of the default method without HTTP verb prefix.
7873
*/
7974
private string $defaultMethod;
8075

8176
/**
8277
* @param class-string[] $protectedControllers
8378
* @param string $defaultController Short classname
79+
*
80+
* @deprecated $httpVerb is deprecated. No longer used.
8481
*/
85-
public function __construct(
82+
public function __construct(// @phpstan-ignore-line
8683
array $protectedControllers,
8784
string $namespace,
8885
string $defaultController,
@@ -93,22 +90,25 @@ public function __construct(
9390
$this->protectedControllers = $protectedControllers;
9491
$this->namespace = rtrim($namespace, '\\') . '\\';
9592
$this->translateURIDashes = $translateURIDashes;
96-
$this->httpVerb = $httpVerb;
9793
$this->defaultController = $defaultController;
98-
$this->defaultMethod = $httpVerb . ucfirst($defaultMethod);
94+
$this->defaultMethod = $defaultMethod;
9995

10096
// Set the default values
10197
$this->controller = $this->defaultController;
102-
$this->method = $this->defaultMethod;
10398
}
10499

105100
/**
106101
* Finds controller, method and params from the URI.
107102
*
108103
* @return array [directory_name, controller_name, controller_method, params]
109104
*/
110-
public function getRoute(string $uri): array
105+
public function getRoute(string $uri, string $httpVerb): array
111106
{
107+
$httpVerb = strtolower($httpVerb);
108+
109+
$defaultMethod = $httpVerb . ucfirst($this->defaultMethod);
110+
$this->method = $defaultMethod;
111+
112112
$segments = explode('/', $uri);
113113

114114
// WARNING: Directories get shifted out of the segments array.
@@ -144,10 +144,10 @@ public function getRoute(string $uri): array
144144
$methodSegment = $this->translateURIDashes(array_shift($nonDirSegments));
145145

146146
// Prefix HTTP verb
147-
$this->method = $this->httpVerb . ucfirst($methodSegment);
147+
$this->method = $httpVerb . ucfirst($methodSegment);
148148

149149
// Prevent access to default method path
150-
if (strtolower($this->method) === strtolower($this->defaultMethod)) {
150+
if (strtolower($this->method) === strtolower($defaultMethod)) {
151151
throw new PageNotFoundException(
152152
'Cannot access the default method "' . $this->method . '" with the method name URI path.'
153153
);

0 commit comments

Comments
 (0)