Skip to content

Commit 21a0878

Browse files
committed
rebase
1 parent 452fd20 commit 21a0878

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

‎system/Test/Mock/MockCache.php‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use CodeIgniter\Cache\Handlers\BaseHandler;
1919
use CodeIgniter\Cache\LockStoreInterface;
2020
use CodeIgniter\Cache\LockStoreProviderInterface;
21+
use CodeIgniter\Exceptions\InvalidArgumentException;
2122
use CodeIgniter\I18n\Time;
2223
use PHPUnit\Framework\Assert;
2324
use ReflectionFunction;
@@ -84,9 +85,22 @@ public function remember(string $key, callable|int $ttl, Closure $callback): mix
8485
$value = $callback();
8586

8687
if (is_callable($ttl)) {
87-
$ttl = (new ReflectionFunction($ttl(...)))->getNumberOfParameters() > 0
88-
? $ttl($value)
89-
: $ttl();
88+
$ttlClosure = Closure::fromCallable($ttl);
89+
$rf = new ReflectionFunction($ttlClosure);
90+
$params = $rf->getNumberOfRequiredParameters();
91+
92+
if ($params === 0) {
93+
/** @var Closure(): int $ttlClosure */
94+
$ttl = $ttlClosure();
95+
} elseif ($params === 1) {
96+
/** @var Closure(mixed): int $ttlClosure */
97+
$ttl = $ttlClosure($value);
98+
} else {
99+
throw new InvalidArgumentException(sprintf(
100+
'Argument #2 ($ttl) must accept 0 or 1 parameter, %d given.',
101+
$params,
102+
));
103+
}
90104
}
91105

92106
$this->save($key, $value, $ttl);

‎user_guide_src/source/changelogs/v4.8.0.rst‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ Interface Changes
4343
**NOTE:** If you've implemented your own classes that implement these interfaces from scratch, you will need to
4444
update your implementations to include the new methods or method changes to ensure compatibility.
4545

46-
- **Database:** ``CodeIgniter\Database\ConnectionInterface`` now requires the ``afterCommit()``, ``afterRollback()``, ``inTransaction()``, and ``transaction()`` methods.
46+
- **Cache:** ``CodeIgniter\Cache\CacheInterface::remember()`` now accepts a TTL callable. All built-in cache handlers inherit this method via ``BaseHandler``, so no changes are required for them.
47+
- **Database:** ``CodeIgniter\Database\ConnectionInterface`` now requires the ``afterCommit()``, ``afterRollback()``, and ``transaction()`` methods.
4748
- **Logging:** ``CodeIgniter\Log\Handlers\HandlerInterface::handle()`` now requires a third parameter ``array $context = []``. Any custom log handler that overrides ``handle()`` - whether implementing ``HandlerInterface`` directly or extending a built-in handler class - must add the parameter to its ``handle()`` method signature.
4849
- **Security:** The ``SecurityInterface``'s ``verify()`` method now has a native return type of ``static``.
49-
- **Cache:** ``CodeIgniter\Cache\CacheInterface::remember()`` now accepts a TTL callable. All built-in cache handlers inherit this method via ``BaseHandler``, so no changes are required for them.
5050

5151
Method Signature Changes
5252
========================
@@ -203,14 +203,11 @@ Database
203203

204204
- Added ``afterCommit()`` and ``afterRollback()`` transaction callbacks to database connections. These callbacks run after the outermost transaction commits or rolls back. See :ref:`transactions-transaction-callbacks`.
205205
- Added the ``transaction()`` method to database connections to run a callback inside a transaction. See :ref:`transactions-closure`.
206-
- Added ``inTransaction()`` to database connections to check whether the connection is inside an active CodeIgniter-managed transaction. See :ref:`transactions-checking-transaction-state`.
207206
- Added ``trustServerCertificate`` option to ``SQLSRV`` database connections in ``Config\Database``. Set it to ``true`` to trust the server certificate without CA validation when using encrypted connections.
208207

209208
Query Builder
210209
-------------
211210

212-
- Added ``whereColumn()`` and ``orWhereColumn()`` to compare one column to another column while protecting identifiers by default. See :ref:`query-builder-where-column`.
213-
214211
Forge
215212
-----
216213

@@ -234,7 +231,7 @@ Libraries
234231
- **Cache:** Added support for TTL callables in the ``remember()`` method of cache handlers. This allows you to specify a callable that returns a TTL value, which can be useful for dynamic TTL.
235232
- **Context**: This new feature allows you to easily set and retrieve normal or hidden contextual data for the current request. See :ref:`Context <context>` for details.
236233
- **Images:**: Added support for the AVIF file format.
237-
- **Locks:** Added :doc:`Atomic Locks </libraries/locks>` for owner-aware, cross-process mutual exclusion backed by supported cache handlers: **File**, **Redis**, **Predis**, and **Memcached**. Memcached support has driver-specific release limitations because Memcached has no atomic compare-and-delete command.
234+
- **Locks:** Added :doc:`Atomic Locks </libraries/locks>` for owner-aware, cross-process mutual exclusion backed by supported cache handlers.
238235
- **Logging:** Log handlers now receive the full context array as a third argument to ``handle()``. When ``$logGlobalContext`` is enabled, the CI global context is available under the ``HandlerInterface::GLOBAL_CONTEXT_KEY`` key. Built-in handlers append it to the log output; custom handlers can use it for structured logging.
239236
- **Logging:** Added :ref:`per-call context logging <logging-per-call-context>` with three new ``Config\Logger`` options (``$logContext``, ``$logContextTrace``, ``$logContextUsedKeys``). Per PSR-3, a ``Throwable`` in the ``exception`` context key is automatically normalized to a meaningful array. All options default to ``false``.
240237

@@ -284,9 +281,6 @@ Others
284281
Message Changes
285282
***************
286283

287-
- Added new language key:
288-
- ``Cache.unsupportedLockStore`` (``CacheException::forUnsupportedLockStore()``)
289-
290284
- Removed deprecated language keys tied to removed exception constructors:
291285
- ``Core.missingExtension`` (``FrameworkException::forMissingExtension()``)
292286
- ``HTTP.cannotSetCache`` (``DownloadException::forCannotSetCache()``)

0 commit comments

Comments
 (0)