Skip to content

Commit 910cfdf

Browse files
committed
refactor: remove deprecations in Filters
1 parent 52011ea commit 910cfdf

File tree

6 files changed

+9
-176
lines changed

6 files changed

+9
-176
lines changed

system/Filters/Filters.php

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,6 @@ class Filters
125125
protected array $filterClassInstances = [];
126126

127127
/**
128-
* Any arguments to be passed to filters.
129-
*
130-
* @var array<string, list<string>|null> [name => params]
131-
*
132-
* @deprecated 4.6.0 No longer used.
133-
*/
134-
protected $arguments = [];
135-
136-
/**
137-
* Any arguments to be passed to filtersClass.
138-
*
139-
* @var array<class-string, list<string>|null> [classname => arguments]
140-
*
141-
* @deprecated 4.6.0 No longer used.
142-
*/
143-
protected $argumentsClass = [];
144-
145-
/**
146-
* Constructor.
147-
*
148128
* @param FiltersConfig $config
149129
*/
150130
public function __construct($config, RequestInterface $request, ResponseInterface $response, ?Modules $modules = null)
@@ -154,42 +134,6 @@ public function __construct($config, RequestInterface $request, ResponseInterfac
154134
$this->setResponse($response);
155135

156136
$this->modules = $modules instanceof Modules ? $modules : new Modules();
157-
158-
if ($this->modules->shouldDiscover('filters')) {
159-
$this->discoverFilters();
160-
}
161-
}
162-
163-
/**
164-
* If discoverFilters is enabled in Config then system will try to
165-
* auto-discover custom filters files in namespaces and allow access to
166-
* the config object via the variable $filters as with the routes file.
167-
*
168-
* Sample:
169-
* $filters->aliases['custom-auth'] = \Acme\Blob\Filters\BlobAuth::class;
170-
*
171-
* @deprecated 4.4.2 Use Registrar instead.
172-
*/
173-
private function discoverFilters(): void
174-
{
175-
$locator = service('locator');
176-
177-
// for access by custom filters
178-
$filters = $this->config;
179-
180-
$files = $locator->search('Config/Filters.php');
181-
182-
foreach ($files as $file) {
183-
// The $file may not be a class file.
184-
$className = $locator->getClassname($file);
185-
186-
// Don't include our main Filter config again...
187-
if ($className === FiltersConfig::class || $className === BaseFiltersConfig::class) {
188-
continue;
189-
}
190-
191-
include $file;
192-
}
193137
}
194138

195139
/**
@@ -501,8 +445,6 @@ public function reset(): self
501445
{
502446
$this->initialized = false;
503447

504-
$this->arguments = $this->argumentsClass = [];
505-
506448
$this->filters = $this->filtersClass = [
507449
'before' => [],
508450
'after' => [],
@@ -644,18 +586,6 @@ public function enableFilters(array $filters, string $when = 'before')
644586
return $this;
645587
}
646588

647-
/**
648-
* Returns the arguments for a specified key, or all.
649-
*
650-
* @return array<string, string>|string
651-
*
652-
* @deprecated 4.6.0 Already does not work.
653-
*/
654-
public function getArguments(?string $key = null)
655-
{
656-
return ((string) $key === '') ? $this->arguments : $this->arguments[$key];
657-
}
658-
659589
// --------------------------------------------------------------------
660590
// Processors
661591
// --------------------------------------------------------------------
@@ -732,27 +662,9 @@ protected function processMethods()
732662

733663
$method = $this->request->getMethod();
734664

735-
$found = false;
736-
737665
if (array_key_exists($method, $this->config->methods)) {
738-
$found = true;
739-
}
740-
// Checks lowercase HTTP method for backward compatibility.
741-
// @deprecated 4.5.0
742-
// @TODO remove this in the future.
743-
elseif (array_key_exists(strtolower($method), $this->config->methods)) {
744-
@trigger_error(
745-
'Setting lowercase HTTP method key "' . strtolower($method) . '" is deprecated.'
746-
. ' Use uppercase HTTP method like "' . strtoupper($method) . '".',
747-
E_USER_DEPRECATED,
748-
);
749-
750-
$found = true;
751-
$method = strtolower($method);
752-
}
753-
754-
if ($found) {
755666
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false;
667+
756668
if ($oldFilterOrder) {
757669
$this->filters['before'] = array_merge($this->filters['before'], $this->config->methods[$method]);
758670
} else {

tests/system/Filters/FiltersTest.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -443,46 +443,6 @@ public function testRunThrowsWithInvalidAlias(): void
443443
$filters->run($uri);
444444
}
445445

446-
public function testCustomFiltersLoad(): void
447-
{
448-
service('superglobals')->setServer('REQUEST_METHOD', 'GET');
449-
450-
$config = [
451-
'aliases' => [],
452-
'globals' => [
453-
'before' => ['test-customfilter'],
454-
'after' => [],
455-
],
456-
];
457-
$filtersConfig = $this->createConfigFromArray(FiltersConfig::class, $config);
458-
$filters = $this->createFilters($filtersConfig);
459-
460-
$uri = 'admin/foo/bar';
461-
$request = $filters->run($uri, 'before');
462-
463-
$this->assertSame('http://hellowworld.com', $request->getBody());
464-
465-
$this->resetServices();
466-
}
467-
468-
/**
469-
* @see https://github.com/codeigniter4/CodeIgniter4/issues/4720
470-
*/
471-
public function testAllCustomFiltersAreDiscoveredInConstructor(): void
472-
{
473-
service('superglobals')->setServer('REQUEST_METHOD', 'GET');
474-
475-
$config = [
476-
'aliases' => [],
477-
'globals' => [],
478-
];
479-
$filtersConfig = $this->createConfigFromArray(FiltersConfig::class, $config);
480-
$filters = $this->createFilters($filtersConfig);
481-
482-
$configFilters = $this->getPrivateProperty($filters, 'config');
483-
$this->assertContains('test-customfilter', array_keys($configFilters->aliases));
484-
}
485-
486446
public function testRunThrowsWithInvalidClassType(): void
487447
{
488448
service('superglobals')->setServer('REQUEST_METHOD', 'GET');

user_guide_src/source/changelogs/v4.8.0.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ BREAKING
2323
Behavior Changes
2424
================
2525

26+
- **Filters:** The deprecated case-insensitive checking of HTTP methods in ``processMethods()`` has been removed.
27+
- **Filters:** The deprecated auto-discovery of custom filters has been removed. Custom filters must now be explicitly defined in Registrars.
28+
2629
Interface Changes
2730
=================
2831

@@ -43,6 +46,11 @@ Removed Deprecated Items
4346
- ``CodeIgniter\Debug\Exceptions::cleanPath()``
4447
- ``CodeIgniter\Debug\Exceptions::describeMemory()``
4548
- ``CodeIgniter\Debug\Exceptions::highlightFile()``
49+
- **Filters:** Removed the following properties and methods deprecated:
50+
- ``CodeIgniter\Filters\Filters::$arguments`` (deprecated since v4.6.0)
51+
- ``CodeIgniter\Filters\Filters::$argumentsClass`` (deprecated since v4.6.0)
52+
- ``CodeIgniter\Filters\Filters::getArguments()`` (deprecated since v4.6.0)
53+
- ``CodeIgniter\Filters\Filters::discoverFilters()`` (deprecated since v4.4.2)
4654

4755
************
4856
Enhancements

user_guide_src/source/general/modules.rst

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,28 +160,6 @@ the **Modules** config file, described above.
160160
When working with modules, it can be a problem if the routes in the application contain wildcards.
161161
In that case, see :ref:`routing-priority`.
162162

163-
.. _modules-filters:
164-
165-
Filters
166-
=======
167-
168-
.. deprecated:: 4.4.2
169-
170-
.. note:: This feature is deprecated. Use :ref:`registrars` instead like the
171-
following:
172-
173-
.. literalinclude:: modules/015.php
174-
175-
By default, :doc:`filters <../incoming/filters>` are automatically scanned for within modules.
176-
It can be turned off in the **Modules** config file, described above.
177-
178-
.. note:: Since the files are being included into the current scope, the ``$filters`` instance is already defined for you.
179-
It will cause errors if you attempt to redefine that class.
180-
181-
In the module's **Config/Filters.php** file, you need to define the aliases of the filters you use:
182-
183-
.. literalinclude:: modules/005.php
184-
185163
Controllers
186164
===========
187165

user_guide_src/source/general/modules/005.php

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

user_guide_src/source/general/modules/015.php

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

0 commit comments

Comments
 (0)