Events.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php namespace Config;
  2. use CodeIgniter\Events\Events;
  3. use CodeIgniter\Exceptions\FrameworkException;
  4. /*
  5. * --------------------------------------------------------------------
  6. * Application Events
  7. * --------------------------------------------------------------------
  8. * Events allow you to tap into the execution of the program without
  9. * modifying or extending core files. This file provides a central
  10. * location to define your events, though they can always be added
  11. * at run-time, also, if needed.
  12. *
  13. * You create code that can execute by subscribing to events with
  14. * the 'on()' method. This accepts any form of callable, including
  15. * Closures, that will be executed when the event is triggered.
  16. *
  17. * Example:
  18. * Events::on('create', [$myInstance, 'myMethod']);
  19. */
  20. Events::on('pre_system', function () {
  21. if (ENVIRONMENT !== 'testing')
  22. {
  23. if (ini_get('zlib.output_compression'))
  24. {
  25. throw FrameworkException::forEnabledZlibOutputCompression();
  26. }
  27. while (ob_get_level() > 0)
  28. {
  29. ob_end_flush();
  30. }
  31. ob_start(function ($buffer) {
  32. return $buffer;
  33. });
  34. }
  35. /*
  36. * --------------------------------------------------------------------
  37. * Debug Toolbar Listeners.
  38. * --------------------------------------------------------------------
  39. * If you delete, they will no longer be collected.
  40. */
  41. if (ENVIRONMENT !== 'production')
  42. {
  43. Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
  44. Services::toolbar()->respond();
  45. }
  46. });