Filters.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace Config;
  3. use App\Filters\AuthAdminFilter;
  4. use App\Filters\AuthFilter;
  5. use App\Filters\AuthRedirect;
  6. use CodeIgniter\Config\Filters as BaseFilters;
  7. use CodeIgniter\Filters\Cors;
  8. use CodeIgniter\Filters\CSRF;
  9. use CodeIgniter\Filters\DebugToolbar;
  10. use CodeIgniter\Filters\ForceHTTPS;
  11. use CodeIgniter\Filters\Honeypot;
  12. use CodeIgniter\Filters\InvalidChars;
  13. use CodeIgniter\Filters\PageCache;
  14. use CodeIgniter\Filters\PerformanceMetrics;
  15. use CodeIgniter\Filters\SecureHeaders;
  16. class Filters extends BaseFilters
  17. {
  18. /**
  19. * Configures aliases for Filter classes to
  20. * make reading things nicer and simpler.
  21. *
  22. * @var array<string, class-string|list<class-string>>
  23. *
  24. * [filter_name => classname]
  25. * or [filter_name => [classname1, classname2, ...]]
  26. */
  27. public array $aliases = [
  28. 'csrf' => CSRF::class,
  29. 'toolbar' => DebugToolbar::class,
  30. 'honeypot' => Honeypot::class,
  31. 'invalidchars' => InvalidChars::class,
  32. 'secureheaders' => SecureHeaders::class,
  33. 'cors' => Cors::class,
  34. 'forcehttps' => ForceHTTPS::class,
  35. 'pagecache' => PageCache::class,
  36. 'performance' => PerformanceMetrics::class,
  37. 'auth-redirect' => AuthRedirect::class,
  38. 'auth' => AuthFilter::class,
  39. 'auth-admin' => AuthAdminFilter::class,
  40. ];
  41. /**
  42. * List of special required filters.
  43. *
  44. * The filters listed here are special. They are applied before and after
  45. * other kinds of filters, and always applied even if a route does not exist.
  46. *
  47. * Filters set by default provide framework functionality. If removed,
  48. * those functions will no longer work.
  49. *
  50. * @see https://codeigniter.com/user_guide/incoming/filters.html#provided-filters
  51. *
  52. * @var array{before: list<string>, after: list<string>}
  53. */
  54. public array $required = [
  55. 'before' => [
  56. 'forcehttps', // Force Global Secure Requests
  57. 'pagecache', // Web Page Caching
  58. ],
  59. 'after' => [
  60. 'pagecache', // Web Page Caching
  61. 'performance', // Performance Metrics
  62. 'toolbar', // Debug Toolbar
  63. ],
  64. ];
  65. /**
  66. * List of filter aliases that are always
  67. * applied before and after every request.
  68. *
  69. * @var array<string, array<string, array<string, string>>>|array<string, list<string>>
  70. */
  71. public array $globals = [
  72. 'before' => [
  73. // 'honeypot',
  74. 'honeypot',
  75. // 'csrf',
  76. 'csrf',
  77. // 'invalidchars',
  78. ],
  79. 'after' => [
  80. // 'honeypot',
  81. 'honeypot',
  82. // 'secureheaders',
  83. ],
  84. ];
  85. /**
  86. * List of filter aliases that works on a
  87. * particular HTTP method (GET, POST, etc.).
  88. *
  89. * Example:
  90. * 'POST' => ['foo', 'bar']
  91. *
  92. * If you use this, you should disable auto-routing because auto-routing
  93. * permits any HTTP method to access a controller. Accessing the controller
  94. * with a method you don't expect could bypass the filter.
  95. *
  96. * @var array<string, list<string>>
  97. */
  98. public array $methods = [];
  99. /**
  100. * List of filter aliases that should run on any
  101. * before or after URI patterns.
  102. *
  103. * Example:
  104. * 'isLoggedIn' => ['before' => ['account/*', 'profiles/*']]
  105. *
  106. * @var array<string, array<string, list<string>>>
  107. */
  108. public array $filters = [];
  109. }