Skip to content

Commit 20b090b

Browse files
committed
fix: add logic to skip filters if not in HTTP
All filters do not make sense in CLI.
1 parent 74cce7a commit 20b090b

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/Filters/AuthRates.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace CodeIgniter\Shield\Filters;
66

77
use CodeIgniter\Filters\FilterInterface;
8+
use CodeIgniter\HTTP\IncomingRequest;
89
use CodeIgniter\HTTP\RedirectResponse;
910
use CodeIgniter\HTTP\RequestInterface;
1011
use CodeIgniter\HTTP\Response;
@@ -31,6 +32,10 @@ class AuthRates implements FilterInterface
3132
*/
3233
public function before(RequestInterface $request, $arguments = null)
3334
{
35+
if (! $request instanceof IncomingRequest) {
36+
return;
37+
}
38+
3439
$throttler = service('throttler');
3540

3641
// Restrict an IP address to no more than 10 requests

src/Filters/ChainAuth.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace CodeIgniter\Shield\Filters;
66

77
use CodeIgniter\Filters\FilterInterface;
8+
use CodeIgniter\HTTP\IncomingRequest;
89
use CodeIgniter\HTTP\RedirectResponse;
910
use CodeIgniter\HTTP\RequestInterface;
1011
use CodeIgniter\HTTP\Response;
@@ -35,6 +36,10 @@ class ChainAuth implements FilterInterface
3536
*/
3637
public function before(RequestInterface $request, $arguments = null)
3738
{
39+
if (! $request instanceof IncomingRequest) {
40+
return;
41+
}
42+
3843
helper('settings');
3944

4045
$chain = config('Auth')->authenticationChain;

src/Filters/SessionAuth.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace CodeIgniter\Shield\Filters;
66

77
use CodeIgniter\Filters\FilterInterface;
8+
use CodeIgniter\HTTP\IncomingRequest;
89
use CodeIgniter\HTTP\RedirectResponse;
910
use CodeIgniter\HTTP\RequestInterface;
1011
use CodeIgniter\HTTP\Response;
@@ -34,6 +35,10 @@ class SessionAuth implements FilterInterface
3435
*/
3536
public function before(RequestInterface $request, $arguments = null)
3637
{
38+
if (! $request instanceof IncomingRequest) {
39+
return;
40+
}
41+
3742
helper('setting');
3843

3944
/** @var Session $authenticator */

src/Filters/TokenAuth.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace CodeIgniter\Shield\Filters;
66

77
use CodeIgniter\Filters\FilterInterface;
8+
use CodeIgniter\HTTP\IncomingRequest;
89
use CodeIgniter\HTTP\RedirectResponse;
910
use CodeIgniter\HTTP\RequestInterface;
1011
use CodeIgniter\HTTP\Response;
@@ -34,6 +35,10 @@ class TokenAuth implements FilterInterface
3435
*/
3536
public function before(RequestInterface $request, $arguments = null)
3637
{
38+
if (! $request instanceof IncomingRequest) {
39+
return;
40+
}
41+
3742
helper('setting');
3843

3944
/** @var AccessTokens $authenticator */

0 commit comments

Comments
 (0)