Download the PHP package germania-kg/client-location without Composer
On this page you can find all versions of the php package germania-kg/client-location. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download germania-kg/client-location
More information about germania-kg/client-location
Files in germania-kg/client-location
Package client-location
Short Description PSR-15 Middleware for storing client location
License MIT
Informations about the package client-location
Germania KG · ClientLocation
Installation
PSR-15 Middleware
The middleware checks the incoming ServerRequest for a client-ip
attribute. The client IP is passed to the factory callable which returns some location information. This client location is then stored in the ServerRequest as client-location
attribute.
If the client-ip
attribute is not set or empty, the middleware does nothing and passes on to the RequestHandler.
The ClientIpLocationMiddleware implements PSR-15 MiddlewareInterface. The constructor requires
- Factory callable which accepts the client's IP address and actually determines the client location. Proposal: Use the HttpClientLocationCreator below.
- PSR-3 Logger for errors.
- An optional PSR-3 error loglevel name can be added optionally. Default is
LogLevel::ERROR
Configuration
Both attribute names can be renamed. Here the defaults:
HttpClientLocationCreator
the HttpClientLocationCreator is a callable class which accepts the client IP and returns the client location. Its constructor requires an API endpoint, a PSR-18 HTTP client and a PSR-17 Request factory.
The API endpoint should contain a {{ip}}
template variable where the client IP is placed in.
Configuration
Set custom API response decoder
Per default, the response will be json_decoded as associative array. You can specify a custom response decoder:
Set default location to return when HTTP client throws exception:
Set PSR-3 Logger:
Issues
Development
Grab and go using one of these:
Unit tests
Either copy phpunit.xml.dist
to phpunit.xml
and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:
All versions of client-location with dependencies
psr/log Version ^1.1
psr/http-message Version ^1.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
psr/http-factory Version ^1.0
psr/http-client Version ^1.0