Esi\IPQuery - A PHP library for ipquery.io, a free and performant ip address API.
Important
WIP: This library is not yet finished. Not recommended for production.
- PHP >= 8.3
- Composer
- And library(ies) that provide(s):
- PSR-7 HTTP Message implementation
- PSR-17 HTTP Factory implementation
- PSR-18 HTTP Client implementation
This library is decoupled from any HTTP messaging client by using PSR-7, PSR-17, and PSR-18.
You can install the package via composer:
# First, install the base package
composer require esi/ipquery-php
# Then install your preferred PSR implementations.
# Example 1: Using Symfony components
composer require symfony/http-client:^7.0 symfony/psr-http-message-bridge:^7.0 nyholm/psr7:^1.0
# Example 2: Using Guzzle
composer require guzzlehttp/guzzle:^7.0
# There are other libraries and numerous combinations. The important thing is that a PSR-7, PSR-17, and PSR-18 implementation is provided.This library makes use of php-http/http-discovery. This means that the Builder will default to
any discoverable PSR-7, PSR-17, and PSR-18 libraries that are installed.
php-http/http-discovery also supports auto-installation if no libraries implementing the above PSR standards are found. This is accomplished by having the following
in composer.json:
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}use Esi\IPQuery\Client;
use Esi\IPQuery\Api\IP;
$ipApi = new IP(new Client());
var_dump($ipApi->sendRequest(['1.1.1.1', '8.8.8.8']));You can customize the HTTP client by providing a Esi\IPQuery\HttpClient\Builder instance to the Esi\IPQuery\Client constructor.
For example, to set a custom user agent:
use Esi\IPQuery\Client;
use Esi\IPQuery\HttpClient\Builder;
use Http\Client\Common\Plugin\HeaderSetPlugin;
$builder = (new Builder())
->addPlugin(new HeaderSetPlugin([
'User-Agent' => 'My super cool user agent',
]));
$client = new Client($builder);Or using a specific library for the PSR implementations, instead of what is found by php-http/http-discovery:
use Esi\IPQuery\Client;
use Esi\IPQuery\HttpClient\Builder;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;
$factory = new HttpFactory();
$ipApi = new IP(new Client(new Builder(new GuzzleClient(), $factory, $factory, $factory)));
var_dump($ipApi->sendRequest(['1.1.1.1', '8.8.8.8']));See CONTRIBUTING.
Bugs and feature requests are tracked on GitHub.
See backward-compatibility.md for more information on Backwards Compatibility.
See the CHANGELOG for more information on what has changed recently.
See the LICENSE for more information on the license that applies to this project.
See SECURITY for more information on the security disclosure process.


