5
use CodeIgniter\Events\Events;
6
use CodeIgniter\Exceptions\FrameworkException;
7
use CodeIgniter\HotReloader\HotReloader;
10
* --------------------------------------------------------------------
12
* --------------------------------------------------------------------
13
* Events allow you to tap into the execution of the program without
14
* modifying or extending core files. This file provides a central
15
* location to define your events, though they can always be added
16
* at run-time, also, if needed.
18
* You create code that can execute by subscribing to events with
19
* the 'on()' method. This accepts any form of callable, including
20
* Closures, that will be executed when the event is triggered.
23
* Events::on('create', [$myInstance, 'myMethod']);
26
Events::on('pre_system', static function (): void {
27
if (ENVIRONMENT !== 'testing') {
28
if (ini_get('zlib.output_compression')) {
29
throw FrameworkException::forEnabledZlibOutputCompression();
32
while (ob_get_level() > 0) {
36
ob_start(static fn ($buffer) => $buffer);
40
* --------------------------------------------------------------------
41
* Debug Toolbar Listeners.
42
* --------------------------------------------------------------------
43
* If you delete, they will no longer be collected.
45
if (CI_DEBUG && ! is_cli()) {
46
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
47
Services::toolbar()->respond();
48
// Hot Reload route - for framework use on the hot reloader.
49
if (ENVIRONMENT === 'development') {
50
Services::routes()->get('__hot-reload', static function (): void {
51
(new HotReloader())->run();