Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f6a9530
Added Context class
patel-vansh Feb 18, 2026
30cdc19
Added some convenient methods
patel-vansh Feb 18, 2026
a166678
Enhance logger to properly include global context
patel-vansh Feb 18, 2026
43c2d52
Add unit tests for Context class functionality
patel-vansh Feb 18, 2026
b0d5848
Added tests for global context logging behaviour
patel-vansh Feb 18, 2026
f62d577
cs-fix
patel-vansh Feb 18, 2026
2e4ca31
Add docs
patel-vansh Feb 19, 2026
da3a843
Merge remote-tracking branch 'upstream/4.8' into feat/context
patel-vansh Feb 21, 2026
b055119
add context() helper function
patel-vansh Feb 21, 2026
c60b9f9
cs-fix and fixing static analysis problems
patel-vansh Feb 21, 2026
66fd4ae
Some doc fixing
patel-vansh Feb 21, 2026
daf6d6b
Fix rst errors.
patel-vansh Feb 21, 2026
1136fa0
Apply suggested changes
patel-vansh Feb 22, 2026
07f895e
Set $logGlobalContext to false by default
patel-vansh Feb 23, 2026
7bf481a
Add docs for helper method
patel-vansh Feb 23, 2026
5a6fbca
cs-fix
patel-vansh Feb 23, 2026
2f11d7c
Fix the doc issue
patel-vansh Feb 23, 2026
bf7ed1b
Merge remote-tracking branch 'upstream/4.8' into feat/context
patel-vansh Feb 24, 2026
f36449e
Applying code suggestions
patel-vansh Feb 24, 2026
4bd55ed
changed type from mixed|null to mixed
patel-vansh Feb 24, 2026
f066488
Added __serialize and __unserialize methods.
patel-vansh Feb 24, 2026
9f77ab8
Returning $default if $key is not present. And only calling ArrayHelp…
patel-vansh Feb 26, 2026
dc8ca2a
Remove contructor
patel-vansh Feb 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/Config/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ class Logger extends BaseConfig
*/
public string $dateFormat = 'Y-m-d H:i:s';

/**
* --------------------------------------------------------------------------
* Whether to log the global context
* --------------------------------------------------------------------------
*
* You can enable/disable logging of global context data, which comes from the
* `CodeIgniter\Context\Context` class. This data is automatically included in
* logs, and can be set using the `set()` method of the Context class. This is
* useful for including additional information in your logs, such as user IDs,
* request IDs, etc.
*
* **NOTE:** This **DOES NOT** include any data that has been marked as hidden
* using the `setHidden()` method of the Context class.
*/
public bool $logGlobalContext = false;

/**
* --------------------------------------------------------------------------
* Log Handlers
Expand Down
12 changes: 12 additions & 0 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use CodeIgniter\Cache\CacheInterface;
use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Config\Factories;
use CodeIgniter\Context\Context;
use CodeIgniter\Cookie\Cookie;
use CodeIgniter\Cookie\CookieStore;
use CodeIgniter\Cookie\Exceptions\CookieException;
Expand Down Expand Up @@ -212,6 +213,17 @@ function config(string $name, bool $getShared = true)
}
}

if (! function_exists('context')) {
/**
* Provides access to the Context object, which is used to store
* contextual data during a request that can be accessed globally.
*/
function context(): Context
{
return service('context');
}
}

if (! function_exists('cookie')) {
/**
* Simpler way to create a new Cookie instance.
Expand Down
13 changes: 13 additions & 0 deletions system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use CodeIgniter\Cache\ResponseCache;
use CodeIgniter\CLI\Commands;
use CodeIgniter\CodeIgniter;
use CodeIgniter\Context\Context;
use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Database\MigrationRunner;
use CodeIgniter\Debug\Exceptions;
Expand Down Expand Up @@ -868,4 +869,16 @@ public static function typography(bool $getShared = true)

return new Typography();
}

/**
* The Context class provides a way to store and retrieve static data throughout requests.
*/
public static function context(bool $getShared = true): Context
{
if ($getShared) {
return static::getSharedInstance('context');
}

return new Context();
}
}
Loading
Loading