Files
opensourcepos/app/Config/Events.php
objecttothis de531e20c6 Migrations
- Delete old CI3 file
- Correct format of Migrations file datetime
2024-06-15 17:19:15 +02:00

62 lines
1.9 KiB
PHP

<?php
namespace Config;
use App\Events\Load_config;
use CodeIgniter\Events\Events;
use CodeIgniter\Exceptions\FrameworkException;
/*
* --------------------------------------------------------------------
* Application Events
* --------------------------------------------------------------------
* Events allow you to tap into the execution of the program without
* modifying or extending core files. This file provides a central
* location to define your events, though they can always be added
* at run-time, also, if needed.
*
* You create code that can execute by subscribing to events with
* the 'on()' method. This accepts any form of callable, including
* Closures, that will be executed when the event is triggered.
*
* Example:
* Events::on('create', [$myInstance, 'myMethod']);
*/
Events::on('pre_system', function ()
{
if (ENVIRONMENT !== 'testing')
{
if (ini_get('zlib.output_compression'))
{
throw FrameworkException::forEnabledZlibOutputCompression();
}
while (ob_get_level() > 0)
{
ob_end_flush();
}
ob_start(static function ($buffer){ return $buffer; });
}
/*
* --------------------------------------------------------------------
* Debug Toolbar Listeners.
* --------------------------------------------------------------------
* If you delete, they will no longer be collected.
*/
if (CI_DEBUG && !is_cli())
{
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
Services::toolbar()->respond();
}
});
$config = new Load_config(); //TODO: Not 100% sure this is the best way to do this, but without instantiating the class, the event engine tries to run the function as if it were static.
Events::on('post_controller_constructor', [$config, 'load_config']);
Events::on('post_controller', ['\App\Events\Db_log', 'db_log_queries']);
Events::on('pre_controller', ['\App\Events\Method', 'validate_method']);