PHP Class Psr7Middlewares\Middleware\ClientIp

Inheritance: use trait Psr7Middlewares\Utils\AttributeTrait
ファイルを表示 Open project: oscarotero/psr7-middlewares Class Usage Examples

Public Methods

Method Description
__construct ( array $headers = null ) Constructor. Defines de trusted headers.
__invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface Execute the middleware.
getIp ( Psr\Http\Message\ServerRequestInterface $request ) : string | null Return the client ip.
getIps ( Psr\Http\Message\ServerRequestInterface $request ) : array | null Returns all ips found.
headers ( array $headers ) : self Configure the trusted headers.
remote ( boolean $remote = true ) : self To get the ip from a remote service.

Private Methods

Method Description
scanIps ( Psr\Http\Message\ServerRequestInterface $request ) : array Detect and return all ips found.

Method Details

__construct() public method

Constructor. Defines de trusted headers.
public __construct ( array $headers = null )
$headers array

__invoke() public method

Execute the middleware.
public __invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
$next callable
return Psr\Http\Message\ResponseInterface

getIp() public static method

Return the client ip.
public static getIp ( Psr\Http\Message\ServerRequestInterface $request ) : string | null
$request Psr\Http\Message\ServerRequestInterface
return string | null

getIps() public static method

Returns all ips found.
public static getIps ( Psr\Http\Message\ServerRequestInterface $request ) : array | null
$request Psr\Http\Message\ServerRequestInterface
return array | null

headers() public method

Configure the trusted headers.
public headers ( array $headers ) : self
$headers array
return self

remote() public method

Useful for testing purposes on localhost.
public remote ( boolean $remote = true ) : self
$remote boolean
return self