peaky-blind3rs/ip-address-interface
最新稳定版本:1.0.0
Composer 安装命令:
composer require peaky-blind3rs/ip-address-interface
包简介
IP Address Interface
README 文档
README
This library offers a standard interface to implement IP Geolocation and Threat Intelligence API in your PHP projects. It offers developers a way to craft various IP data adapter classes for their unique project requirements.
Requirements
- PHP 8.2 or higher
- psr/http-message 1.1 or higher
Installation
The package can be installed via Composer. Run the following command:
composer require peaky-blind3rs/ip-address-interface
Usage
Using IPInfo Adapter
use PeakyBlind3rs\IpAddressInterface\Interface\Model\IpAddressInterface; use PeakyBlind3rs\IpAddressInterface\IPServiceFactory; $instance = IPServiceFactory::getInstance('ipinfo://nobody:your-api-token@ipinfo.io/?timeout=30'); $result = $instance->lookup('27.126.160.0'); if ($result instanceof IpAddressInterface) { // Request was successful, use getter methods to get data } else { // Requested Ended in Error and $result hold instance of \Psr\Http\Message\ResponseInterface }
Or if you want to use IPData Adapter
use PeakyBlind3rs\IpAddressInterface\Interface\Model\IpAddressInterface; use PeakyBlind3rs\IpAddressInterface\IPServiceFactory; $instance = IPServiceFactory::getInstance('ipdata://nobody:your-api-key@ipdata.co/?timeout=30'); $result = $instance->lookup('27.126.160.0'); if ($result instanceof IpAddressInterface) { // Request was successful, use getter methods to get data } else { // Requested Ended in Error and $result hold instance of \Psr\Http\Message\ResponseInterface }
If you want to use your own adapter, your adapter needs to implement \PeakyBlind3rs\IpAddressInterface\Interface\IpLookupInterface
namespace MyNamespace; class MyAdapter implements \PeakyBlind3rs\IpAddressInterface\Interface\IpLookupInterface { }
And then add your adapter to class map and use it
use MyNamespace\MyAdapter; use PeakyBlind3rs\IpAddressInterface\IPServiceFactory; use PeakyBlind3rs\IpAddressInterface\Interface\Model\IpAddressInterface; IPServiceFactory::classMaps([ 'myadapter' => MyAdapter::class ]); $instance = IPServiceFactory::getInstance('myadapter://nobody:your-api-key@myadapter-api.tld/?timeout=30'); $result = $instance->lookup('27.126.160.0'); if ($result instanceof IpAddressInterface) { // Request was successful, use getter methods to get data } else { // Requested Ended in Error and $result hold instance of \Psr\Http\Message\ResponseInterface }
Testing
To run the tests, execute:
composer test
Coding Standards
Check your code for PSR compliance:
composer cs-check
Static Analysis
Analyze your code statically:
composer static-analysis
License
This project is licensed under the MIT License. Refer to the LICENSE.md file for further details.
Contributing
Please consult the CONTRIBUTING.md file for more information.
Acknowledgements
- Thanks to the PHP community for providing the language we cherish.
- Thanks to Composer for handling the package dependencies effectively.
Contact
- Have any issues? Report them via the project issue tracker.
- Got some enhancements in mind? Feel free to create a pull request or open an issue.
Happy coding!
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-15