Skip to content

Commit 17549d7

Browse files
committed
refactor: remove deprecated Filters auto-discovery
1 parent f0648c6 commit 17549d7

12 files changed

Lines changed: 34 additions & 158 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: 19 additions & 36 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)
@@ -205,47 +204,31 @@ When working with modules, it can be a problem if the routes in the application
205204

206205
### Filters
207206

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

210-
!!! note "Note"
211-
This feature is deprecated. Use [Registrars](configuration.md#registrars) instead, like the following:
212-
213-
```php
214-
<?php
209+
```php
210+
<?php
215211

216-
namespace CodeIgniter\Shield\Config;
212+
namespace CodeIgniter\Shield\Config;
217213

218-
use CodeIgniter\Shield\Filters\SessionAuth;
219-
use CodeIgniter\Shield\Filters\TokenAuth;
214+
use CodeIgniter\Shield\Filters\SessionAuth;
215+
use CodeIgniter\Shield\Filters\TokenAuth;
220216

221-
class Registrar
217+
class Registrar
218+
{
219+
/**
220+
* Registers the Shield filters.
221+
*/
222+
public static function Filters(): array
222223
{
223-
/**
224-
* Registers the Shield filters.
225-
*/
226-
public static function Filters(): array
227-
{
228-
return [
229-
'aliases' => [
230-
'session' => SessionAuth::class,
231-
'tokens' => TokenAuth::class,
232-
],
233-
];
234-
}
224+
return [
225+
'aliases' => [
226+
'session' => SessionAuth::class,
227+
'tokens' => TokenAuth::class,
228+
],
229+
];
235230
}
236-
```
237-
238-
By default, [filters](../incoming/filters.md) are automatically scanned for within modules. This can be turned off in the **Modules** config file, described above.
239-
240-
!!! note "Note"
241-
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.
242-
243-
In the module's **Config/Filters.php** file, you need to define the aliases of the filters you use:
244-
245-
```php
246-
<?php
247-
248-
$filters->aliases['menus'] = \App\Filters\MenusFilter::class;
231+
}
249232
```
250233

251234
### 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)