user_guide_src/source/changelogs/v4.3.0.rst
Version 4.3.0 #############
Release Date: January 10, 2023
4.3.0 release of CodeIgniter4
.. contents:: :local: :depth: 3
Highlights
sclubricants <https://github.com/sclubricants>).
See Query Builder.sclubricants <https://github.com/sclubricants>).
See Forge.exceptions-when-database-errors-occur.BREAKING
.. _exceptions-when-database-errors-occur:
The exceptions thrown by the database connection classes have been changed to CodeIgniter\Database\Exceptions\DatabaseException. Previously, different database drivers threw different exception classes, but these have been unified into DatabaseException.
The exceptions thrown by the execute() method of Prepared Queries have been changed to DatabaseException. Previously, different database drivers might throw different exception classes or did not throw exceptions, but these have been unified into DatabaseException.
During transactions, exceptions are not thrown by default even if DBDebug is true.
DBDebug and CI_DEBUG Changes
Config\Database::$default['DBDebug']
and Config\Database::$tests['DBDebug'] has been changed to true by default. With these
settings, an exception is always thrown when a database error occurs. Previously, it is false
only in the production environment.DatabaseException thrown in BaseBuilder is thrown if $DBDebug is true.
Previously, it is thrown if CI_DEBUG is true.BaseConnection::$DBDebug has been changed to true.DBDebug now means whether or not to throw an exception when an error occurs.
Although unrelated to debugging, the name has not been changed.DBDebug is true, even if a query error occurs, exceptions
are not thrown by default. Previously, if a query error occurs, all the queries
will be rolled backed, and an exception will be thrown, so :ref:transactions-managing-errors or
:ref:transactions-manual-transactions won't work.Model, DatabaseException is thrown even if
CI_DEBUG is false. Previously, it is thrown if CI_DEBUG is true.Previously, CodeIgniter's Exception Handler used the Exception code as the HTTP status code in some cases, and calculated the Exit code based on the Exception code. However there should be no logical connection with Exception code and HTTP Status Code or Exit code.
500 and set Exit code to the constant EXIT_ERROR (= 1) by default.HTTPExceptionInterface or HasExitCodeInterface in your Exception class. See :ref:error-specify-http-status-code and :ref:error-specify-exit-code.For example, the Exit code has been changed like the following:
ConfigException occurs, the Exit code is EXIT_CONFIG (= 3) instead of 12.CastException occurs, the Exit code is EXIT_CONFIG (= 3) instead of 9.DatabaseException occurs, the Exit code is EXIT_DATABASE (= 8) instead of 17... _v430-time-fix:
The following methods of the :doc:Time <../libraries/time> class had bugs that changed the state of the current object. To fix these bugs, the Time class has been fixed:
- ``add()``
- ``modify()``
- ``setDate()``
- ``setISODate()``
- ``setTime()``
- ``sub()``
Time class extends DateTimeImmutable and is completely immutable.TimeLegacy class has been added for backward compatibility, which behaves the same as the unmodified Time class.script_tag() and :php:func:safe_mailto() no longer output type="text/javascript" in <script> tag.spark file has been changed due to a change in the processing of Spark commands.CITestStreamFilter::$buffer = '' no longer causes the filter to be registered to listen for streams. Now there
is a CITestStreamFilter::registration() method for this. See :ref:upgrade-430-stream-filter for details.InvalidArgumentException that is a kind of LogicException in BaseBuilder::_whereIn() is not suppressed by the configuration. Previously if CI_DEBUG was false, the exception was suppressed.BaseConnection::getForeignKeyData() <metadata-getforeignkeydata> has been changed.CodeIgniter\Database\BasePreparedQuery class returns now a bool value for write-type queries instead of the Result class object.Model::update() method now raises a DatabaseException if it generates an SQL
statement without a WHERE clause; Model does not support operations that update all records.RouteCollection::resetRoutes() resets Auto-Discovery of Routes. Previously once discovered, RouteCollection never discover Routes files again even if RouteCollection::resetRoutes() is called... _v430-interface-changes:
.. note:: As long as you have not extended the relevant CodeIgniter core classes or implemented these interfaces, all these changes are backward compatible and require no intervention.
OutgoingRequestInterface that represents an outgoing request.OutgoingRequest class that implements OutgoingRequestInterface.RequestInterface extends OutgoingRequestInterface.CURLRequest extends OutgoingRequest.Request extends OutgoingRequest.getProtocolVersion(), getBody(), hasHeader() and getHeaderLine() method in MessageInterface.ResponseInterface extends MessageInterface.ResponseInterface::getCSP() (and Response::getCSP()), ResponseInterface::getReasonPhrase() and ResponseInterface::getCookieStore() methods.CodeIgniter\Database\ResultInterface::getNumRows() method.Validation Changes_... _v430-validation-changes:
ValidationInterface ^^^^^^^^^^^^^^^^^^^
ValidationInterface has been changed to eliminate the mismatch between ValidationInterface and the Validation class.
The third parameter $dbGroup for ValidationInterface::run() has been added.
The following methods are added to the interface:
ValidationInterface::setRule()ValidationInterface::getRules()ValidationInterface::getRuleGroup()ValidationInterface::setRuleGroup()ValidationInterface::loadRuleGroup()ValidationInterface::hasError()ValidationInterface::listErrors()ValidationInterface::showError()Validation ^^^^^^^^^^
The return value of Validation::loadRuleGroup() has been changed from null to [] when the $group is empty.
CodeIgniter\Database\BasePreparedQuery::close() and CodeIgniter\Database\PreparedQueryInterface have been changed to bool (previously untyped).CodeIgniter\Database\Database::loadForge() has been changed to Forge.CodeIgniter\Database\Database::loadUtils() has been changed to BaseUtils.$column has changed in Table::dropForeignKey() to $foreignName.$index of BaseBuilder::updateBatch() has changed to $constraints. It now accepts types array, string, or RawSql. Extending classes should likewise change types.$set parameter of BaseBuilder::insertBatch() and BaseBuilder::updateBatch() now accepts an object of a single row of data.BaseBuilder::_updateBatch()
$values has changed to $keys.$index has changed to $values. The parameter type also has changed to array.The method signature of Forge::dropKey() has changed. An additional optional parameter $prefixKeyName has been added.
The method signature of Forge::addKey() has changed. An additional optional parameter $keyName has been added.
The method signature of Forge::addPrimaryKey() has changed. An additional optional parameter $keyName has been added.
The method signature of Forge::addUniqueKey() has changed. An additional optional parameter $keyName has been added.
The following method has an additional $asQuery parameter. When set to true the method returns a stand alone SQL query.
CodeIgniter\Database\Forge::_processPrimaryKeys()In addition to the added $asQuery parameter above the following methods also now return an array.
CodeIgniter\Database\Forge::_processIndexes()CodeIgniter\Database\Forge::_processForeignKeys()API: The return type of API\ResponseTrait::failServerError() has been changed to ResponseInterface.
The following methods have been changed to accept ResponseInterface as a parameter instead of Response.
Debug\Exceptions::__construct()Services::exceptions()Request: The $index parameter of IncomingRequest::getJsonVar() now accepts an array, string or null value.
Enhancements
The call handler for Spark commands from the CodeIgniter\CodeIgniter class has been extracted. This will reduce the cost of console calls.
Added spark filter:check command to check the filters for a route. See :ref:Controller Filters <spark-filter-check> for the details.
Added spark make:cell command to create a new Cell file and its view. See :ref:generating-cell-via-command for the details.
Now spark routes command shows route names. See :ref:URI Routing <routing-spark-routes>.
Now spark routes command can sort the output by Handler.
See :ref:routing-spark-routes-sort-by-handler.
Help information for a spark command can now be accessed using the --help option (e.g. php spark serve --help)
Added methods CLI::promptByMultipleKeys() to support multiple value in input, unlike promptByKey(). See :ref:prompt-by-multiple-keys for details.
HTTP/3 is now considered a valid protocol.
StreamFilterTrait to make it easier to work with capturing data from STDOUT and STDERR streams. See :ref:testing-cli-output.testing-cli-output.PhpStreamWrapper to make it easier to work with setting data to php://stdin. See :ref:testing-cli-input.benchmark-timer-record to measure performance in a callable. Also enhanced common function timer() to accept optional callable.$useExactComparison is added to TestLogger::didLog() which sets whether log messages are checked verbatim. This defaults to true.CIUnitTestCase::assertLogContains() which compares log messages by parts instead of the whole of the message.upsert() and upsertBatch() methods to QueryBuilder. See :ref:upsert-data.deleteBatch() method to QueryBuilder. See :ref:delete-batch.when() and whenNot() methods to conditionally add clauses to the query. See :ref:BaseBuilder::when() <db-builder-when> for details.Builder::updateBatch(). See :ref:update-batch for the details.BaseBuilder::setQueryAsData() which allows insertBatch(), updateBatch(), upsertBatch(), deleteBatch() from a query. See :ref:insert-batch-data.Forge::processIndexes() allowing the creation of indexes on an existing table. See :ref:db-forge-adding-keys-to-a-table for the details.Forge::addKey(), Forge::addPrimaryKey(), and Forge::addUniqueKey()Forge::dropPrimaryKey() allows dropping the primary key on a table. See :ref:dropping-a-primary-key.Forge::dropKey() to allow dropping unique indexes. This required the DROP CONSTRAINT SQL command.CodeIgniter\\Database\\Forge::addForeignKey() now includes a name parameter to set foreign key names manually. This is not supported in SQLite3.DEFAULT constraint when using :ref:Forge::dropColumn() <db-forge-dropColumn>.busyTimeout to set timeout when a table is locked.BaseConnection::escape() now excludes the RawSql data type. This allows passing SQL strings into data.BaseConnection::getForeignKeyData() <metadata-getforeignkeydata>. All DBMS returns the same structure.BaseConnection::getIndexData() <db-metadata-getindexdata> now can return pseudo index named PRIMARY for AUTOINCREMENT column, and each returned index data has type property.BasePreparedQuery::close() now deallocates the prepared statement in all DBMS. Previously, they were not deallocated in Postgre, SQLSRV and OCI8. See :ref:database-queries-stmt-close.BaseConnection::transException() to throw exceptinons during transactions.
See :ref:transactions-throwing-exceptionsBaseModel::insertBatch() and BaseModel::updateBatch() methods. See :ref:model-events-callbacks.Model::allowEmptyInserts() method to insert empty data. See :ref:Using CodeIgniter's Model <model-allow-empty-inserts>entities-property-casting class IntBoolCast for Entity.replace(), addLineAfter() and addLineBefore() to modify files in Publisher. See :ref:Publisher <publisher-modifying-files> for details.encryption-compatible-with-ci3.CURLRequest <curlrequest-version>.validation_errors(), :php:func:validation_list_errors() and :php:func:validation_show_error() to display Validation Errors.route_to() if you pass a locale value as the last parameter.request() and :php:func:response() functions.decamelize() function to convert camelCase to snake_case.is_windows() global function to detect Windows platforms.Creation of void HTML elements like <input> can be configured to exclude or not the solidus character
(/) before the right angle bracket (>) by setting the $html5 property in
app/Config/DocTypes.php. If you set it to true, HTML5 compatible tags without / like
will be output.
The following items are affected:
br tagnl2br filterinput taglogging_deprecation_warnings for details.CODEIGNITER_SCREAM_DEPRECATIONS to a truthy value.Config\Logger::$threshold is now, by default, environment-specific. For production environment, default threshold is still 4 but changed to 9 for other environments... _v430-multiple-domain-support:
Config\App::$allowedHostnames to set hostnames other than the hostname in the baseURL.Config\App::$allowedHostnames, URL-related functions such as :php:func:base_url(), :php:func:current_url(), :php:func:site_url() will return the URL with the hostname set in Config\App::$allowedHostnames if the current URL matches.$routes->useSupportedLocalesOnly(true) so that the Router returns 404 Not Found if the locale in the URL is not supported in Config\App::$supportedLocales. See :ref:Localization <localization-in-routes>$routes->view() method to return the view directly. See :ref:View Routes <view-routes>.View Cells <app-cells>.Controlled Cells that provide more structure and flexibility to your View Cells. See :ref:View Cells <controlled-cells> for details.validation-using-closure-rule for details.Code Modules <modules-specify-composer-packages>.Config\Session class to handle session configuration.$request->getRawInputVar() method to return a specified variable from raw stream. See :ref:Retrieving Raw data <incomingrequest-retrieving-raw-data>.$request->is() method to query the request type.
See :ref:Determining Request Type <incomingrequest-is>.Message Changes
CLI.generator.className.cell and CLI.generator.viewName.cell.Changes
Config classes have been typed.Upgrading <upgrade_430_config> for information on changing the default values.CodeIgniter\CodeIgniter no longer handles Spark commands.CodeIgniter::isSparked() method has been removed.CodeIgniter\CLI\CommandRunner class has been removed due to a change in Spark commands processing.system/Config/Routes.php has been removed.app/Config/Routes.php has been changed. Removed include of system routes configuration file.Deprecations
RouteCollection::localizeRoute() is deprecated.RouteCollection::fillRouteParams() is deprecated. Use RouteCollection::buildReverseRoute() instead.BaseBuilder::setUpdateBatch() and BaseBuilder::setInsertBatch() are deprecated. Use BaseBuilder::setData() instead.Response::$CSP is deprecated. It will be protected. Use Response::getCSP() instead.CodeIgniter::$path and CodeIgniter::setPath() are deprecated. No longer used.IncomingRequest::$uri is deprecated. It will be protected. Use IncomingRequest::getUri() instead.IncomingRequest::$config is deprecated. It will be protected.CLI::isWindows() is deprecated. Use is_windows() instead.Config\App session properties in favor of the new session config class Config\Session.Bugs Fixed
Prepared Queries were returning a Result object instead of a bool value for write-type queries.IncomingRequest::getVar() or IncomingRequest::getJsonVar() methods.IncomingRequest::getVar() or IncomingRequest::getJsonVar() methods.upgrade-430-honeypot-and-csp.See the repo's
CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>_
for a complete list of bugs fixed.