Skip to content

Commit 7a8cad9

Browse files
committed
refactor: remove deprecated Filters auto-discovery
1 parent 84d84d3 commit 7a8cad9

13 files changed

Lines changed: 37 additions & 163 deletions

File tree

‎app/Config/Modules.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class Modules extends BaseModules
7474
*/
7575
public $aliases = [
7676
'events',
77-
'filters',
7877
'registrars',
7978
'routes',
8079
'services',

‎docs/changelogs/v4.8.0.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ Release Date: Unreleased
176176
- `CodeIgniter\Filters\Filters::$arguments` (deprecated since v4.6.0)
177177
- `CodeIgniter\Filters\Filters::$argumentsClass` (deprecated since v4.6.0)
178178
- `CodeIgniter\Filters\Filters::getArguments()` (deprecated since v4.6.0)
179+
- `CodeIgniter\Filters\Filters::discoverFilters()` and the auto-discovery of **Config/Filters.php** files (deprecated since v4.4.2)
180+
- `CodeIgniter\Filters\Filters::$modules` and the `$modules` constructor parameter, which were only used by the auto-discovery
179181

180182
- **HTTP:** Removed the following deprecated properties and methods:
181183
- `CodeIgniter\HTTP\Message::getHeaders()` (deprecated since v4.0.5)

‎docs/general/modules.md‎

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class Autoload extends AutoloadConfig
9696
Many times, you will need to specify the full namespace to files you want to include, but CodeIgniter can be configured to make integrating modules into your applications simpler by automatically discovering many different file types, including:
9797

9898
- [Events](../extending/events.md)
99-
- [Filters](../incoming/filters.md)
10099
- [Registrars](configuration.md#registrars)
101100
- [Route files](../incoming/routing.md)
102101
- [Services](../concepts/services.md)
@@ -211,51 +210,33 @@ When working with modules, it can be a problem if the routes in the application
211210

212211
### Filters
213212

214-
!!! danger "Deprecated since version 4.4.2"
213+
Modules register their [filters](../incoming/filters.md) through a [Registrar](configuration.md#registrars), like the following:
215214

216-
!!! note "Note"
217-
This feature is deprecated. Use [Registrars](configuration.md#registrars) instead, like the following:
218-
219-
```php
220-
<?php
215+
```php
216+
<?php
221217

222-
namespace CodeIgniter\Shield\Config;
218+
namespace CodeIgniter\Shield\Config;
223219

224-
use CodeIgniter\Shield\Filters\SessionAuth;
225-
use CodeIgniter\Shield\Filters\TokenAuth;
220+
use CodeIgniter\Shield\Filters\SessionAuth;
221+
use CodeIgniter\Shield\Filters\TokenAuth;
226222

227-
class Registrar
223+
class Registrar
224+
{
225+
/**
226+
* Registers the Shield filters.
227+
*
228+
* @return array<string, array<string, string>>
229+
*/
230+
public static function Filters(): array
228231
{
229-
/**
230-
* Registers the Shield filters.
231-
*
232-
* @return array<string, array<string, string>>
233-
*/
234-
public static function Filters(): array
235-
{
236-
return [
237-
'aliases' => [
238-
'session' => SessionAuth::class,
239-
'tokens' => TokenAuth::class,
240-
],
241-
];
242-
}
232+
return [
233+
'aliases' => [
234+
'session' => SessionAuth::class,
235+
'tokens' => TokenAuth::class,
236+
],
237+
];
243238
}
244-
```
245-
246-
By default, [filters](../incoming/filters.md) are automatically scanned for within modules. This can be turned off in the **Modules** config file, described above.
247-
248-
!!! note "Note"
249-
Since the files are being included into the current scope, the `$filters` instance is already defined for you. It will cause errors if you attempt to redefine that class.
250-
251-
In the module's **Config/Filters.php** file, you need to define the aliases of the filters you use:
252-
253-
```php
254-
<?php
255-
256-
use App\Filters\MenusFilter;
257-
258-
$filters->aliases['menus'] = MenusFilter::class;
239+
}
259240
```
260241

261242
### Controllers

‎docs/installation/upgrade_480.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ The following files received significant changes (including deprecations or visu
169169
- **app/Config/Mimes.php**
170170
- `Config\Mimes::$mimes` added a new key `md` for Markdown files.
171171

172+
- **app/Config/Modules.php**
173+
- `Config\Modules::$aliases` no longer lists `filters`, since the auto-discovery of Filters was removed.
174+
172175
- **app/Config/Routing.php**
173176
- `Config\Routing::$placeholderSamples` was added to provide sample values for custom route placeholders so the `spark routes` command can resolve their filters.
174177

‎psalm-autoload.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
'tests/_support/View/Views',
1515
];
1616
$excludeFiles = [
17-
'tests/_support/Config/Filters.php',
1817
'tests/_support/Config/Routes.php',
1918
];
2019

‎psalm-baseline.xml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@
5656
<code><![CDATA[$message]]></code>
5757
</NoValue>
5858
</file>
59-
<file src="tests/_support/Config/Filters.php">
60-
<UndefinedGlobalVariable>
61-
<code><![CDATA[$filters]]></code>
62-
</UndefinedGlobalVariable>
63-
</file>
6459
<file src="tests/_support/Config/Routes.php">
6560
<UndefinedGlobalVariable>
6661
<code><![CDATA[$routes]]></code>

‎system/Filters/Filters.php‎

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use CodeIgniter\HTTP\ResponseInterface;
2020
use Config\Feature;
2121
use Config\Filters as FiltersConfig;
22-
use Config\Modules;
2322

2423
class Filters
2524
{
@@ -44,13 +43,6 @@ class Filters
4443
*/
4544
protected $response;
4645

47-
/**
48-
* The Config\Modules instance
49-
*
50-
* @var Modules
51-
*/
52-
protected $modules;
53-
5446
/**
5547
* Whether we've done initial processing on the filter lists.
5648
*
@@ -122,49 +114,11 @@ class Filters
122114
/**
123115
* @param FiltersConfig $config
124116
*/
125-
public function __construct($config, RequestInterface $request, ResponseInterface $response, ?Modules $modules = null)
117+
public function __construct($config, RequestInterface $request, ResponseInterface $response)
126118
{
127119
$this->config = $config;
128120
$this->request = &$request;
129121
$this->setResponse($response);
130-
131-
$this->modules = $modules instanceof Modules ? $modules : new Modules();
132-
133-
if ($this->modules->shouldDiscover('filters')) {
134-
$this->discoverFilters();
135-
}
136-
}
137-
138-
/**
139-
* If discoverFilters is enabled in Config then system will try to
140-
* auto-discover custom filters files in namespaces and allow access to
141-
* the config object via the variable $filters as with the routes file.
142-
*
143-
* Sample:
144-
* $filters->aliases['custom-auth'] = \Acme\Blob\Filters\BlobAuth::class;
145-
*
146-
* @deprecated 4.4.2 Use Registrar instead.
147-
*/
148-
private function discoverFilters(): void
149-
{
150-
$locator = service('locator');
151-
152-
// for access by custom filters
153-
$filters = $this->config;
154-
155-
$files = $locator->search('Config/Filters.php');
156-
157-
foreach ($files as $file) {
158-
// The $file may not be a class file.
159-
$className = $locator->getClassname($file);
160-
161-
// Don't include our main Filter config again...
162-
if ($className === FiltersConfig::class || $className === BaseFiltersConfig::class) {
163-
continue;
164-
}
165-
166-
include $file;
167-
}
168122
}
169123

170124
/**

‎system/Test/FilterTestTrait.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ trait FilterTestTrait
5757

5858
/**
5959
* The Filters configuration to use.
60-
* Extracted for access to aliases
61-
* during Filters::discoverFilters().
60+
* Extracted for access to aliases.
6261
*
6362
* @var FiltersConfig|null
6463
*/

‎tests/_support/Config/Filters.php‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎tests/system/CodeIgniterTest.php‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,17 @@ public function testRegisterSameFilterTwiceWithDifferentArgument(): void
345345
$router = service('router', $routes, service('incomingrequest'));
346346
Services::injectMock('router', $router);
347347

348-
/** @var FiltersConfig $filterConfig */
349-
$filterConfig = config('Filters');
350-
$filterConfig->filters = [
348+
$filters = config('Filters');
349+
350+
$filters->aliases['test-customfilter'] = Customfilter::class;
351+
352+
$filters->filters = [
351353
// Set filter with argument.
352354
'test-customfilter:arg1' => [
353355
'before' => ['pages/*'],
354356
],
355357
];
356-
service('filters', $filterConfig);
358+
service('filters', $filters);
357359

358360
ob_start();
359361
$this->codeigniter->run();

0 commit comments

Comments
 (0)