magein/utils
最新稳定版本:v4.0.0
Composer 安装命令:
composer require magein/utils
包简介
常用的一些工具类
README 文档
README
简介
php 一些常用的扩展
自动化测试
项目跟目录下执行
./vendor/bin/phpunit
类说明
Console.php
use magein\utils\Console;
Console::error('失败');
Console::success('成功');
Console::warning('警告');
Console::white('政策');
Console::red('红色');
Console::blue('蓝色');
Console::green('绿色');
Console::yellow('黄色');
DateFormatter.php
use magein\utils\DateFormatter;
DateFormatter::now();
DateFormatter::unixtime('2025-06-18 14:55:31');
DateFormatter::date('2025-06-18 14:55:31');
DateFormatter::time('2025-06-18 14:55:31');
DateFormatter::datetime('1750230185');
DateFormatter::today();
DateFormatter::yesterday();
DateFormatter::dayRange();
DateFormatter::tomorrow();
// 上周
DateFormatter::lastWeek();
// 前几天的数据 不包含今天
DateFormatter::prevDay();
// 近几天的数据 包含今天
DateFormatter::lastDay();
BrowserAgent.php
use magein\utils\BrowserAgent;
BrowserAgent::random();
BrowserAgent::android();
// 返回一个数组包含user-agent参数
BrowserAgent::header();
Validator.php
常用的验证类
use magein\utils\Validator;
Validator::phone();
Validator::email();
Validator::qq();
Validator::idCard();
Validator::url();
Validator::http();
Validator::https();
Validator::ip();
Validator::ipv4();
Validator::ipv6();
Validator::image();
Validator::chinese();
Result.php
用于方法的返回值
Faker.php
用于生成数据
use magein\utils\Faker;
Faker::email();
Faker::phone();
Faker::text();
Faker::phone();
Faker::name();
Faker::title();
Location.php
规范经纬度取值,仅仅是规范不同地图取值经纬度前后的问题,腾讯地址返回维度在前,高德返回经度在前
仅仅适用与中国范围内的经纬度
use magein\utils\Location;
$number = '39.5420,116.2529';
$location = Location::init($number);
// 经度在前的字符串
$location->toString();
$location->toArray();
// 返回带键的数组通过 longitude和latitude
$location->toArray(false);
// 获取经度
$location->getLongitude();
// 获取维度
$location->getLatitude();
Http.php
使用需要安装GuzzleHttp
composer require guzzlehttp/guzzle:^7.6
$http = new \magein\utils\Http;
// 要添加到请求的查询字符串的关联数组或查询字符串
$http->get($url,$params=[]);
// 用来发送一个 application/x-www-form-urlencoded POST请求
$http->formParams($url,$params);
// 设置请求的主体为 multipart/form-data 表单
$http->multipartFormData($url,$params);
$http->json($url,$params,'post');
$http->body($url,$params,'put');
Tree.php
$tree = new \magein\utils\Tree($data);
$data=$tree->transfer();
// 设置主键ID
$tree->setPrimary('id');
// 设置父级索引 默认parent_id
$tree->setParentId('pid');
// 设置子集索引 默认child
$tree->setChild('children');
// 数据结构转化成一维数组
$tree->floor($url,$params);
// 设置请求的主体为 multipart/form-data 表单
magein/utils 适用场景与选型建议
magein/utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 121 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「utils」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 magein/utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 magein/utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 magein/utils 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
n2n test utils
A collection of enhancements and utilities for the Silverstripe UserForms module
Collections of small tools for MongoDB.
Reusable utilities library for Lacus Solutions' packages (type description, HTML escaping, random sequences)
Utils
统计信息
- 总下载量: 121
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-01