PHPackages                             germania-kg/client-location - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. germania-kg/client-location

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

germania-kg/client-location
===========================

PSR-15 Middleware for storing client location

1.1.7(4y ago)038MITPHPPHP ^7.3|^8.0

Since Dec 1Pushed 3y ago2 watchersCompare

[ Source](https://github.com/GermaniaKG/ClientLocation)[ Packagist](https://packagist.org/packages/germania-kg/client-location)[ RSS](/packages/germania-kg-client-location/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (13)Versions (12)Used By (0)

[![](https://camo.githubusercontent.com/cac3140c0c6e758f67a1ba689683ced67aa2d534e2187d6e03c5c721ffe3b976/68747470733a2f2f7374617469632e6765726d616e69612d6b672e636f6d2f6c6f676f732f67612d6c6f676f2d323031362d7765622e7376677a)](https://camo.githubusercontent.com/cac3140c0c6e758f67a1ba689683ced67aa2d534e2187d6e03c5c721ffe3b976/68747470733a2f2f7374617469632e6765726d616e69612d6b672e636f6d2f6c6f676f732f67612d6c6f676f2d323031362d7765622e7376677a)

---

Germania KG · ClientLocation
============================

[](#germania-kg---clientlocation)

[![Packagist](https://camo.githubusercontent.com/8a594fbbd2156499e526d148e0ab555423feba24bea110468c0bd3e253401bc3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6765726d616e69612d6b672f636c69656e742d6c6f636174696f6e2e7376673f7374796c653d666c6174)](https://packagist.org/packages/germania-kg/client-location)[![PHP version](https://camo.githubusercontent.com/bfc422a47db0a37e4df0890c47f5d64b0d7204be92e66e037996c0e511221bcd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6765726d616e69612d6b672f636c69656e742d6c6f636174696f6e2e737667)](https://packagist.org/packages/germania-kg/client-location)[![Build Status](https://camo.githubusercontent.com/3cad63ced21bf923512027e3e930fd1b0f79375f0b6dfaeee1eb6953d2c78cfd/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4765726d616e69614b472f436c69656e744c6f636174696f6e2e7376673f6c6162656c3d5472617669732532304349)](https://travis-ci.org/GermaniaKG/ClientLocation)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/cd630f017c13ca75d20bd44c56e7d270d9c520f5b40a2d980786d38f900fdfc0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4765726d616e69614b472f436c69656e744c6f636174696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/GermaniaKG/ClientLocation/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/097196c3ba13d8733cfe32bae8adfd43818a0b73d28945ea7e34cb0f778c5626/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4765726d616e69614b472f436c69656e744c6f636174696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/GermaniaKG/ClientLocation/?branch=master)[![Build Status](https://camo.githubusercontent.com/f4698186bd688ba18e4cf0bb8589bd880e56c5c6644ac3d3ef80a1aefe692c95/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4765726d616e69614b472f436c69656e744c6f636174696f6e2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/GermaniaKG/ClientLocation/build-status/master)

Installation
------------

[](#installation)

```
$ composer require germania-kg/client-location
```

PSR-15 Middleware
-----------------

[](#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](#HttpClientLocationCreator) below.
- **PSR-3 Logger** for errors.
- An optional **PSR-3 error loglevel name** can be added optionally. Default is `LogLevel::ERROR`

```
