mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 11:12:16 +00:00
Changed name of IpBlockAccess to IpRestrictAccess & updated documentation.
This commit is contained in:
@@ -1373,16 +1373,19 @@ This behavior can be easily disabled by setting `SimpleRouter::enableMultiRouteR
|
|||||||
|
|
||||||
## Restrict access to IP
|
## Restrict access to IP
|
||||||
|
|
||||||
You can white- and blacklist access to IP's using the build in `IpBlockAccess` middleware.
|
You can white- and blacklist access to IP's using the build in `IpRestrictAccess` middleware.
|
||||||
|
|
||||||
Create your own Middleware and extend the `IpBlockAccess` class.
|
Create your own custom Middleware and extend the `IpRestrictAccess` class.
|
||||||
|
|
||||||
|
The `IpRestrictAccess` class contains two properties `ipBlacklist` and `ipWhitelist` that can be added
|
||||||
|
to your middleware to change which IP's has blocked or allowed access.
|
||||||
|
|
||||||
You can use `*` to restrict access to a range of ips.
|
You can use `*` to restrict access to a range of ips.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use \Pecee\Http\Middleware\IpBlockAccess;
|
use \Pecee\Http\Middleware\IpRestrictAccess;
|
||||||
|
|
||||||
class IpBlockMiddleware extends IpBlockAccess {
|
class IpBlockerMiddleware extends IpRestrictAccess {
|
||||||
|
|
||||||
protected $ipBlacklist = [
|
protected $ipBlacklist = [
|
||||||
'5.5.5.5',
|
'5.5.5.5',
|
||||||
@@ -1396,6 +1399,8 @@ class IpBlockMiddleware extends IpBlockAccess {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can the middleware to multiple routes by adding your [middleware to a groups](#middleware).
|
||||||
|
|
||||||
## Url rewriting
|
## Url rewriting
|
||||||
|
|
||||||
### Changing current route
|
### Changing current route
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ namespace Pecee\Http\Middleware;
|
|||||||
use Pecee\Http\Request;
|
use Pecee\Http\Request;
|
||||||
use Pecee\SimpleRouter\Exceptions\HttpException;
|
use Pecee\SimpleRouter\Exceptions\HttpException;
|
||||||
|
|
||||||
abstract class IpBlockAccess implements IMiddleware
|
abstract class IpRestrictAccess implements IMiddleware
|
||||||
{
|
{
|
||||||
protected $ipBlacklist = [];
|
protected $ipBlacklist = [];
|
||||||
protected $ipWhitelist = [];
|
protected $ipWhitelist = [];
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'Dummy/DummyController.php';
|
require_once 'Dummy/DummyController.php';
|
||||||
require_once 'Dummy/Middleware/IpBlockMiddleware.php';
|
require_once 'Dummy/Middleware/IpRestrictMiddleware.php';
|
||||||
|
|
||||||
class CustomMiddlewareTest extends \PHPUnit\Framework\TestCase
|
class CustomMiddlewareTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
@@ -16,7 +16,7 @@ class CustomMiddlewareTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$_SERVER['remote-addr'] = '5.5.5.5';
|
$_SERVER['remote-addr'] = '5.5.5.5';
|
||||||
|
|
||||||
TestRouter::group(['middleware' => IpBlockMiddleware::class], function() {
|
TestRouter::group(['middleware' => IpRestrictMiddleware::class], function() {
|
||||||
TestRouter::get('/fail', 'DummyController@method1');
|
TestRouter::get('/fail', 'DummyController@method1');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ class CustomMiddlewareTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
TestRouter::router()->reset();
|
TestRouter::router()->reset();
|
||||||
|
|
||||||
TestRouter::group(['middleware' => IpBlockMiddleware::class], function() {
|
TestRouter::group(['middleware' => IpRestrictMiddleware::class], function() {
|
||||||
TestRouter::get('/fail', 'DummyController@method1');
|
TestRouter::get('/fail', 'DummyController@method1');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ class CustomMiddlewareTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
TestRouter::router()->reset();
|
TestRouter::router()->reset();
|
||||||
|
|
||||||
TestRouter::group(['middleware' => IpBlockMiddleware::class], function() {
|
TestRouter::group(['middleware' => IpRestrictMiddleware::class], function() {
|
||||||
TestRouter::get('/success', 'DummyController@method1');
|
TestRouter::get('/success', 'DummyController@method1');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ class CustomMiddlewareTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
TestRouter::router()->reset();
|
TestRouter::router()->reset();
|
||||||
|
|
||||||
TestRouter::group(['middleware' => IpBlockMiddleware::class], function() {
|
TestRouter::group(['middleware' => IpRestrictMiddleware::class], function() {
|
||||||
TestRouter::get('/success', 'DummyController@method1');
|
TestRouter::get('/success', 'DummyController@method1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class IpBlockMiddleware extends \Pecee\Http\Middleware\IpBlockAccess {
|
class IpRestrictMiddleware extends \Pecee\Http\Middleware\IpRestrictAccess {
|
||||||
|
|
||||||
protected $ipBlacklist = [
|
protected $ipBlacklist = [
|
||||||
'5.5.5.5',
|
'5.5.5.5',
|
||||||
Reference in New Issue
Block a user