定制 darsyn/ip 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

darsyn/ip

最新稳定版本:6.0.0

Composer 安装命令:

composer require darsyn/ip

包简介

An immutable IP Address value object that provides several different notations, including helper functions.

README 文档

README

IP is an immutable value object for (both version 4 and 6) IP addresses. Several helper methods are provided for ranges, broadcast and network addresses, subnet masks, whether an IP is a certain type (defined by RFC's), etc.

This project aims for simplicity of use and any contribution towards that goal - whether a bug report, modifications to the codebase, or an improvement to the accuracy or readability of the documentation - are always welcome.

Documentation

Full documentation is available in the docs/ folder.

Compatibility

This library has extensive test coverage using PHPUnit on PHP versions: 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3 and 8.4.

Versions 5.x.x of this library are compatible with PHP versions 5.6 to 8.3 (and will continue to receive bug fixes).

Versions 6.x.x of this library are compatible with PHP versions 7.1 and above, and will receive continued support for future versions of PHP (also accepting proposed new features).

Static analysis is performed with PHPStan at max level on PHP 8.4, using core, bleeding edge, and deprecation rules.

The Doctrine features for this library have been split off into their own package, darsyn/ip-doctrine.

Brief Example

  • There are three main classes: IPv4, IPv6, and Multi (for both version 4 and 6 addresses).
  • Objects are created using a static factory method IpInterface::factory() instead of the constructor to speed up internal processes.
  • When using Multi, the default strategy for representing version 4 addresses internally is IPv4-mapped.
<?php declare(strict_types=1);

use Darsyn\IP\Exception;
use Darsyn\IP\Version\IPv4;

try {
    $ip = IPv4::factory('192.168.0.1');
} catch (Exception\InvalidIpAddressException $e) {
    exit('The IP address supplied is invalid!');
}

$companyNetwork = IPv4::factory('216.58.198.174');
if (!$ip->inRange($companyNetwork, 25)) {
    throw new \Exception('Request not from a known company IP address.');
}

// Is it coming from the local network?
if (!$ip->isPrivateUse()) {
    record_visit($ip->getBinary(), $_SERVER['HTTP_USER_AGENT']);
}

Code of Conduct

This project includes and adheres to the Contributor Covenant as a Code of Conduct.

License

Please see the separate license file included in this repository for a full copy of the MIT license, which this project is licensed under.

Authors

If you make a contribution (submit a pull request), don't forget to add your name here!

统计信息

  • 总下载量: 1.87M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 261
  • 点击次数: 1
  • 依赖项目数: 17
  • 推荐数: 0

GitHub 信息

  • Stars: 260
  • Watchers: 9
  • Forks: 21
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-22