Filters.php 3.3 KB

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