@@ -7981,15 +7981,15 @@ public function __construct(Router $router, Responder $responder, array $propert
7981
7981
$ this ->reflection = $ reflection ;
7982
7982
}
7983
7983
7984
- private function callHandler ($ record , string $ operation , ReflectedTable $ table ) /*: object */
7984
+ private function callHandler (ServerRequestInterface $ request , $ record , string $ operation , ReflectedTable $ table ) /*: object */
7985
7985
{
7986
7986
$ context = (array ) $ record ;
7987
7987
$ columnNames = $ this ->getProperty ('columns ' , '' );
7988
7988
if ($ columnNames ) {
7989
7989
foreach (explode (', ' , $ columnNames ) as $ columnName ) {
7990
7990
if ($ table ->hasColumn ($ columnName )) {
7991
7991
if ($ operation == 'create ' ) {
7992
- $ context [$ columnName ] = $ _SERVER [ ' REMOTE_ADDR ' ] ;
7992
+ $ context [$ columnName ] = $ this -> getIpAddress ( $ request ) ;
7993
7993
} else {
7994
7994
unset($ context [$ columnName ]);
7995
7995
}
@@ -7999,6 +7999,18 @@ private function callHandler($record, string $operation, ReflectedTable $table)
7999
7999
return (object ) $ context ;
8000
8000
}
8001
8001
8002
+ private function getIpAddress (ServerRequestInterface $ request ): string
8003
+ {
8004
+ $ reverseProxy = $ this ->getProperty ('reverseProxy ' , '' );
8005
+ if ($ reverseProxy ) {
8006
+ $ ipAddress = array_pop ($ request ->getHeader ('X-Forwarded-For ' ));
8007
+ } else {
8008
+ $ serverParams = $ request ->getServerParams ();
8009
+ $ ipAddress = $ serverParams ['REMOTE_ADDR ' ] ?? '127.0.0.1 ' ;
8010
+ }
8011
+ return $ ipAddress ;
8012
+ }
8013
+
8002
8014
public function process (ServerRequestInterface $ request , RequestHandlerInterface $ next ): ResponseInterface
8003
8015
{
8004
8016
$ operation = RequestUtils::getOperation ($ request );
@@ -8012,10 +8024,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
8012
8024
$ table = $ this ->reflection ->getTable ($ tableName );
8013
8025
if (is_array ($ record )) {
8014
8026
foreach ($ record as &$ r ) {
8015
- $ r = $ this ->callHandler ($ r , $ operation , $ table );
8027
+ $ r = $ this ->callHandler ($ request , $ r , $ operation , $ table );
8016
8028
}
8017
8029
} else {
8018
- $ record = $ this ->callHandler ($ record , $ operation , $ table );
8030
+ $ record = $ this ->callHandler ($ request , $ record , $ operation , $ table );
8019
8031
}
8020
8032
$ request = $ request ->withParsedBody ($ record );
8021
8033
}
0 commit comments