| Code Coverage
| Lines | Functions and Methods | Classes and Traits
Total | 26.67% covered (danger) | 26.67% | 4 / 15 |  | n/a | 0 / 0 | CRAP |  | n/a | 0 / 0

1 | <?php
2 |
3 | namespace Config;
4 |
5 | use CodeIgniter\Events\Events;
6 | use CodeIgniter\Exceptions\FrameworkException;
7 | use CodeIgniter\HotReloader\HotReloader;
8 |
9 | /*
10 | * --------------------------------------------------------------------
11 | * Application Events
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.
17 | *
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.
21 | *
22 | * Example:
23 | * Events::on('create', [$myInstance, 'myMethod']);
24 | */
25 |
26 | Events::on('pre_system', static function (): void {
27 | if (ENVIRONMENT !== 'testing') {
28 | if (ini_get('zlib.output_compression')) {
29 | throw FrameworkException::forEnabledZlibOutputCompression();
30 | }
31 |
32 | while (ob_get_level() > 0) {
33 | ob_end_flush();
34 | }
35 |
36 | ob_start(static fn ($buffer) => $buffer);
37 | }
38 |
39 | /*
40 | * --------------------------------------------------------------------
41 | * Debug Toolbar Listeners.
42 | * --------------------------------------------------------------------
43 | * If you delete, they will no longer be collected.
44 | */
45 | if (CI_DEBUG && ! is_cli()) {
46 | Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
47 | service('toolbar')->respond();
48 | // Hot Reload route - for framework use on the hot reloader.
49 | if (ENVIRONMENT === 'development') {
50 | service('routes')->get('__hot-reload', static function (): void {
51 | (new HotReloader())->run();
52 | });
53 | }
54 | }
55 | });