Skip to content

Commit

Permalink
Release v4.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jun 17, 2023
1 parent b41bca4 commit e392123
Show file tree
Hide file tree
Showing 29 changed files with 280 additions and 188 deletions.
9 changes: 7 additions & 2 deletions system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ public function __construct(Autoloader $autoloader)
* Attempts to locate a file by examining the name for a namespace
* and looking through the PSR-4 namespaced files that we know about.
*
* @param string $file The namespaced file to locate
* @param string|null $folder The folder within the namespace that we should look for the file.
* @param string $file The relative file path or namespaced file to
* locate. If not namespaced, search in the app
* folder.
* @param string|null $folder The folder within the namespace that we should
* look for the file. If $file does not contain
* this value, it will be appended to the namespace
* folder.
* @param string $ext The file extension the file should have.
*
* @return false|string The path to the file, or false if not found.
Expand Down
4 changes: 1 addition & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CodeIgniter
/**
* The current version of CodeIgniter Framework
*/
public const CI_VERSION = '4.3.5';
public const CI_VERSION = '4.3.6';

/**
* App startup time.
Expand Down Expand Up @@ -310,8 +310,6 @@ private function configureKint(): void
* makes all of the pieces work together.
*
* @return ResponseInterface|void
*
* @throws RedirectException
*/
public function run(?RouteCollectionInterface $routes = null, bool $returnResponse = false)
{
Expand Down
6 changes: 1 addition & 5 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,11 +744,7 @@ function is_windows(?bool $mock = null): bool
$mocked = $mock;
}

if (isset($mocked)) {
return $mocked;
}

return DIRECTORY_SEPARATOR === '\\';
return $mocked ?? DIRECTORY_SEPARATOR === '\\';
}
}

Expand Down
2 changes: 1 addition & 1 deletion system/Config/BaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function __construct()
/**
* Initialization an environment-specific configuration setting
*
* @param mixed $property
* @param array|bool|float|int|string|null $property
*
* @return void
*/
Expand Down
18 changes: 1 addition & 17 deletions system/Config/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* instantiation checks.
*
* @method static BaseConfig|null config(...$arguments)
* @method static Model|null models(string $name, array $options = [], ?ConnectionInterface &$conn = null)
*/
class Factories
{
Expand Down Expand Up @@ -69,23 +70,6 @@ class Factories
*/
protected static $instances = [];

/**
* This method is only to prevent PHPStan error.
* If we have a solution, we can remove this method.
* See https://github.com/codeigniter4/CodeIgniter4/pull/5358
*
* @template T of Model
*
* @phpstan-param class-string<T> $name
*
* @return Model
* @phpstan-return T
*/
public static function models(string $name, array $options = [], ?ConnectionInterface &$conn = null)
{
return self::__callStatic('models', [$name, $options, $conn]);
}

/**
* Loads instances based on the method component name. Either
* creates a new instance or returns an existing shared instance.
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
}

if (isset($this->QBOptions['setQueryAsData'])) {
$data = $this->QBOptions['setQueryAsData'];
$data = $this->QBOptions['setQueryAsData'] . "\n";
} else {
$data = 'VALUES ' . implode(', ', $this->formatValues($values)) . "\n";
}
Expand Down
2 changes: 1 addition & 1 deletion system/Database/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Config extends BaseConfig
protected static $factory;

/**
* Creates the default
* Returns the database connection
*
* @param array|BaseConnection|string|null $group The name of the connection group to use,
* or an array of configuration settings.
Expand Down
22 changes: 10 additions & 12 deletions system/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Database Connection Factory
*
* Creates and returns an instance of the appropriate DatabaseConnection
* Creates and returns an instance of the appropriate Database Connection.
*/
class Database
{
Expand All @@ -32,8 +32,7 @@ class Database
protected $connections = [];

/**
* Parses the connection binds and returns an instance of the driver
* ready to go.
* Parses the connection binds and creates a Database Connection instance.
*
* @return BaseConnection
*
Expand Down Expand Up @@ -83,7 +82,7 @@ public function loadUtils(ConnectionInterface $db): BaseUtils
}

/**
* Parse universal DSN string
* Parses universal DSN string
*
* @throws InvalidArgumentException
*/
Expand Down Expand Up @@ -121,21 +120,20 @@ protected function parseDSN(array $params): array
}

/**
* Initialize database driver.
* Creates a database object.
*
* @param string $driver Driver name. FQCN can be used.
* @param array|object $argument
* @param string $class 'Connection'|'Forge'|'Utils'
* @param array|object $argument The constructor parameter.
*
* @return BaseConnection|BaseUtils|Forge
*/
protected function initDriver(string $driver, string $class, $argument): object
{
$class = $driver . '\\' . $class;
$classname = (strpos($driver, '\\') === false)
? "CodeIgniter\\Database\\{$driver}\\{$class}"
: $driver . '\\' . $class;

if (strpos($driver, '\\') === false) {
$class = "CodeIgniter\\Database\\{$class}";
}

return new $class($argument);
return new $classname($argument);
}
}
45 changes: 40 additions & 5 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,11 @@ public function connect(bool $persistent = false)
$this->buildDSN();
}

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

// Convert semicolons to spaces.
$this->DSN = str_replace(';', ' ', $this->DSN);

$this->connID = $persistent === true ? pg_pconnect($this->DSN) : pg_connect($this->DSN);

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

/**
* Converts the DSN with semicolon syntax.
*/
private function convertDSN()
{
// Strip pgsql
$this->DSN = mb_substr($this->DSN, 6);

// Convert semicolons to spaces in DSN format like:
// pgsql:host=localhost;port=5432;dbname=database_name
// https://www.php.net/manual/en/function.pg-connect.php
$allowedParams = ['host', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service'];

$parameters = explode(';', $this->DSN);

$output = '';
$previousParameter = '';

foreach ($parameters as $parameter) {
[$key, $value] = explode('=', $parameter, 2);
if (in_array($key, $allowedParams, true)) {
if ($previousParameter !== '') {
if (array_search($key, $allowedParams, true) < array_search($previousParameter, $allowedParams, true)) {
$output .= ';';
} else {
$output .= ' ';
}
}
$output .= $parameter;
$previousParameter = $key;
} else {
$output .= ';' . $parameter;
}
}

$this->DSN = $output;
}

/**
* Keep or establish the connection if no queries have been sent for
* a length of time exceeding the server's idle timeout.
Expand Down
2 changes: 1 addition & 1 deletion system/Encryption/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static function createKey($length = 32)
*
* @param string $key Property name
*
* @return mixed
* @return array|string|null
*/
public function __get($key)
{
Expand Down
2 changes: 1 addition & 1 deletion system/Encryption/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected static function substr($str, $start, $length = null)
*
* @param string $key Property name
*
* @return mixed
* @return array|bool|int|string|null
*/
public function __get($key)
{
Expand Down
6 changes: 2 additions & 4 deletions system/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public function cast(?bool $cast = null)
*
* @param array|bool|float|int|object|string|null $value
*
* @return $this
* @return void
*
* @throws Exception
*/
Expand All @@ -452,16 +452,14 @@ public function __set(string $key, $value = null)
if (method_exists($this, $method)) {
$this->{$method}($value);

return $this;
return;
}

// Otherwise, just the value. This allows for creation of new
// class properties that are undefined, though they cannot be
// saved. Useful for grabbing values through joins, assigning
// relationships, etc.
$this->attributes[$dbColumn] = $value;

return $this;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Exceptions/FrameworkException.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function forMissingExtension(string $extension)
'The framework needs the following extension(s) installed and loaded: %s.',
$extension
);
// @codeCoverageIgnoreEnd
// @codeCoverageIgnoreEnd
} else {
$message = lang('Core.missingExtension', [$extension]);
}
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public function setLocale(string $locale)
*/
public function getLocale(): string
{
return $this->locale ?? $this->defaultLocale;
return $this->locale;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Images/Handlers/GDHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ protected function getImageResource(string $path, int $imageType)
throw ImageException::forInvalidImageCreate(lang('Images.pngNotSupported'));
}

return imagecreatefrompng($path);
return @imagecreatefrompng($path);

case IMAGETYPE_WEBP:
if (! function_exists('imagecreatefromwebp')) {
Expand Down
6 changes: 1 addition & 5 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,7 @@ public function __get(string $name)
return parent::__get($name);
}

if (isset($this->builder()->{$name})) {
return $this->builder()->{$name};
}

return null;
return $this->builder()->{$name} ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Router/AutoRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct(
*
* @return array [directory_name, controller_name, controller_method, params]
*/
public function getRoute(string $uri): array
public function getRoute(string $uri, string $httpVerb): array
{
$segments = explode('/', $uri);

Expand Down
26 changes: 13 additions & 13 deletions system/Router/AutoRouterImproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ final class AutoRouterImproved implements AutoRouterInterface
*/
private bool $translateURIDashes;

/**
* HTTP verb for the request.
*/
private string $httpVerb;

/**
* The namespace for controllers.
*/
Expand All @@ -74,15 +69,17 @@ final class AutoRouterImproved implements AutoRouterInterface
private string $defaultController;

/**
* The name of the default method
* The name of the default method without HTTP verb prefix.
*/
private string $defaultMethod;

/**
* @param class-string[] $protectedControllers
* @param string $defaultController Short classname
*
* @deprecated $httpVerb is deprecated. No longer used.
*/
public function __construct(
public function __construct(// @phpstan-ignore-line
array $protectedControllers,
string $namespace,
string $defaultController,
Expand All @@ -93,22 +90,25 @@ public function __construct(
$this->protectedControllers = $protectedControllers;
$this->namespace = rtrim($namespace, '\\') . '\\';
$this->translateURIDashes = $translateURIDashes;
$this->httpVerb = $httpVerb;
$this->defaultController = $defaultController;
$this->defaultMethod = $httpVerb . ucfirst($defaultMethod);
$this->defaultMethod = $defaultMethod;

// Set the default values
$this->controller = $this->defaultController;
$this->method = $this->defaultMethod;
}

/**
* Finds controller, method and params from the URI.
*
* @return array [directory_name, controller_name, controller_method, params]
*/
public function getRoute(string $uri): array
public function getRoute(string $uri, string $httpVerb): array
{
$httpVerb = strtolower($httpVerb);

$defaultMethod = $httpVerb . ucfirst($this->defaultMethod);
$this->method = $defaultMethod;

$segments = explode('/', $uri);

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

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

// Prevent access to default method path
if (strtolower($this->method) === strtolower($this->defaultMethod)) {
if (strtolower($this->method) === strtolower($defaultMethod)) {
throw new PageNotFoundException(
'Cannot access the default method "' . $this->method . '" with the method name URI path.'
);
Expand Down
Loading

0 comments on commit e392123

Please sign in to comment.