Ai
2 Star 0 Fork 1

zms/hyperf-casts

forked from zlf/app-hyperf-casts 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
IpCasts.php 889 Bytes
一键复制 编辑 原始数据 按行查看 历史
zms 提交于 2025-03-13 23:48 +08:00 . 3/13
<?php
declare(strict_types=1);
namespace Zms\HyperfCasts;
use Hyperf\Contract\CastsAttributes;
/**
* IP储存转换器,转换为二进制地址
* Class ArrjoinCasts
* @package Core\Casts
*/
class IpCasts implements CastsAttributes
{
/**
* 获取结果
*/
public function get($model, $key, $value, $attributes)
{
if (gettype($value) === 'string' && strlen($value) > 0) {
return inet_ntop($value) ?: '0.0.0.0';
}
return '0.0.0.0';
}
/**
* 设置数据
*/
public function set($model, $key, $value, $attributes)
{
if (filter_var($value, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) {
return inet_pton($value);
} elseif (filter_var($value, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
return inet_pton($value);
}
return inet_pton('0.0.0.0');
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zms-code/hyperf-casts.git
git@gitee.com:zms-code/hyperf-casts.git
zms-code
hyperf-casts
hyperf-casts
master

搜索帮助