vipkwd/utils

PHP常用函数集合

3.2.8 2023-08-18 07:38 UTC

This package is auto-updated.

Last update: 2024-04-18 09:15:49 UTC


README

A PHP common toolkit.

功能

  • 常用PHP工具函数库

介绍

历经无数个项目沉淀的工具函数,有兴趣的可以一起来维护, 邮箱:service#vipkwd.com

环境

  • PHP 7.0+
  • composer

安装使用[Check it out on packagist.org]

composer require vipkwd/utils

Artisan Command: vipkwd

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd
vipkwd/utils 3.2.0
Usage:
  command [options] [arguments]
Options:
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  
Available commands:
  completion   Dump the shell completion script
  dump         Show the class list of Vipkwd/utils package
  help         Display help for a command
  list         List commands
 load
  load:assets  Install/update assetes for utils

[dump] 查看根空间类列表(默认)

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd dump
IdxNamespaceClassMethodTypeArgumentsEgComment
1Vipkwd\UtilsAlgorithm10:):):)经典排序/查找算法
2Vipkwd\UtilsAsync4:):):)PHP异步回调
3Vipkwd\UtilsCalendar9:):):)阴、阳历法
4Vipkwd\UtilsCallback11:):):)PHP callable tools
5Vipkwd\UtilsColor3:):):)Rgb/Hex颜色值处理
6Vipkwd\UtilsCrypt15:):):)#
7Vipkwd\UtilsDev8:):):)开发调试函数
8Vipkwd\UtilsExcel5:):):)Excel表格工具
9Vipkwd\UtilsFenci6:):):)中文分词组件
10Vipkwd\UtilsHttp6:):):)http请求
11Vipkwd\UtilsIdcard15:):):)证件号码(大陆/港/澳/台)
12Vipkwd\UtilsIp8:):):)#
13Vipkwd\UtilsPage3:):):)通用分页类
14Vipkwd\UtilsPosition12:):):)经纬度操作类
15Vipkwd\UtilsTools18:):):)常用工具集合
16Vipkwd\UtilsValidate32:):):)(regexp)验证类

[Class] 查看根空间类方法列表

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd dump color   
IdxNamespaceClassMethodTypeArgumentsEgComment
1Vipkwd\UtilsColorcolorHexFixstatic$color[√]16进制色值检测/修补
2Vipkwd\UtilsColorhex2rgbstatic$color[√]16进制色值转RGB数值
3Vipkwd\UtilsColorrgb2hexstatic$r=255, $g=255, $b=255[√]RGB数值转16进制色值

[ --Dir|-d ] 查看子空间列表

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd dump -d 
IdxDirNamespaceCli
1Db\Vipkwd\Utils\Dbphp vendor/bin/vipkwd dump Db
2Image\Vipkwd\Utils\Imagephp vendor/bin/vipkwd dump Image
3Libs\Vipkwd\Utils\Libsphp vendor/bin/vipkwd dump Libs
4MediumAI\Vipkwd\Utils\MediumAIphp vendor/bin/vipkwd dump MediumAI
5Mq\Vipkwd\Utils\Mqphp vendor/bin/vipkwd dump Mq
6System\Vipkwd\Utils\Systemphp vendor/bin/vipkwd dump System
7Type\Vipkwd\Utils\Typephp vendor/bin/vipkwd dump Type
8Wx\Vipkwd\Utils\Wxphp vendor/bin/vipkwd dump Wx

[ dump. ] 查看子空间类列表

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd dump Db 
IdxNamespaceClassMethodTypeArgumentsEgComment
1Vipkwd\Utils\DbMongo31:):):)Mongo
2Vipkwd\Utils\DbMysql36:):):)Mysql
3Vipkwd\Utils\DbRedis85:):):)Redis

[ dump. ] 查看子空间类方法列表

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd dump Db.mysql
IdxNamespaceClassMethodTypeArgumentsEgComment
1Vipkwd\Utils\DbMysqlinstancestatic$options[x]单例入口
2Vipkwd\Utils\DbMysqlactionpublic$callback[x]启动一个事务
3Vipkwd\Utils\DbMysqlavgpublic[x]获得某个列字段的平均值
4Vipkwd\Utils\DbMysqlbeginDebugpublic[x]开启调试模式
5Vipkwd\Utils\DbMysqlchunkpublic$limit=10, $callback, $stime=null[x]chunk分块操作数据
6Vipkwd\Utils\DbMysqlcountpublic[x]获取数据表中的行数
7Vipkwd\Utils\DbMysqldatapublic$data[x]设置操作目标数据
8Vipkwd\Utils\DbMysqldebugLogpublic[x]获取调试模式下SQL语句
9Vipkwd\Utils\DbMysqldeletepublic[x]删除表中条件内的数据
10Vipkwd\Utils\DbMysqlfieldpublic$fields="*"[x]配置查询字段
11Vipkwd\Utils\DbMysqlgetpublic[x]返回条件内的一行数据
12Vipkwd\Utils\DbMysqlgrouppublic$group[x]GROUP
13Vipkwd\Utils\DbMysqlhaspublic[x]检测条件内数据是否存在
14Vipkwd\Utils\DbMysqlhavingpublic$havingArr[x]having
15Vipkwd\Utils\DbMysqlinfopublic[x]获取数据库连接信息
16Vipkwd\Utils\DbMysqlinsertpublic$primaryKey=null[x]插入数据到表中
17Vipkwd\Utils\DbMysqlinsertAllpublic[x]批量插入数据到表中
18Vipkwd\Utils\DbMysqljoinpublic$join=[][x]配置链表关系
19Vipkwd\Utils\DbMysqllastpublic[x]获取最后一条查询语句
20Vipkwd\Utils\DbMysqllastInsertIdpublic[x]返回最后插入的行ID
21Vipkwd\Utils\DbMysqllimitpublic$limit=10, $offset=0[x]按偏移量获取limit条数记录
22Vipkwd\Utils\DbMysqllogpublic[x]获取前序所有SQL
23Vipkwd\Utils\DbMysqlmaxpublic[x]获得某个列中的最大的值
24Vipkwd\Utils\DbMysqlminpublic[x]获得某个列中的最小的值
25Vipkwd\Utils\DbMysqlorderpublic$order[x]order by
26Vipkwd\Utils\DbMysqlpagepublic$page=1, $limit=10[x]按页码获取limit条数记录
27Vipkwd\Utils\DbMysqlpdopublic[x]获取标准PDO接口
28Vipkwd\Utils\DbMysqlquerypublic$sql[x]
29Vipkwd\Utils\DbMysqlrandompublic[x]随机获取条件内数据
30Vipkwd\Utils\DbMysqlrawpublic$expression, $map=[][x]生成原始SQL表达式优化语句
31Vipkwd\Utils\DbMysqlreplacepublic$columns[x]批量替换字段的数据
32Vipkwd\Utils\DbMysqlselectpublic$callback=null[x]多条查询,支持回调遍历获取
33Vipkwd\Utils\DbMysqlsumpublic[x]某个列字段相加
34Vipkwd\Utils\DbMysqltablepublic$tbName[x]切换/选择数据表
35Vipkwd\Utils\DbMysqlupdatepublic$data=[][x]修改表数据
36Vipkwd\Utils\DbMysqlwherepublic$where=[][x]设置操作过滤条件

[ -m method ] 查看方法详细

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd dump color -m rgb2hex
IdxNamespaceClassMethodTypeArgumentsEgComment
1Vipkwd\UtilsColorrgb2hexstatic$r=255, $g=255, $b=255[√]RGB数值转16进制色值
/**
 * RGB数值转16进制色值
 *
 * -e.g: phpunit("Color::rgb2hex",[255,255,255]);
 * -e.g: phpunit("Color::rgb2hex",[1,10,100]);
 * -e.g: phpunit("Color::rgb2hex",[9,0,1]);
 *
 * @param integer $r
 * @param integer $g
 * @param integer $b
 * @return string
 */
Struct: \Vipkwd\Utils\Color::rgb2hex(
    $r=255,
    $g=255,
    $b=255
);

[--eg|-e ] 执行测试用例

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd dump color -m rgb2hex --eg

[01] \Vipkwd\Utils\Color::rgb2hex(255, 255, 255); //<string:>“#ffffff”
[02] \Vipkwd\Utils\Color::rgb2hex(1, 10, 100); //<string:>“#010a64”
[03] \Vipkwd\Utils\Color::rgb2hex(9, 0, 1); //<string:>“#090001”
------------------------------------------------------------------------------------

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd dump ip -m getInfo --eg

[01] \Vipkwd\Utils\Ip::getInfo("1.2.4.8"); //array(8) {
    [state] =>    “中国”
    [region] =>   “-”
    [province] => “北京”
    [city] =>     “北京市”
    [isp] =>      “CNNIC权威云解析(CDNS.CN)全球Anycast节点”
    [ip] =>       “1.2.4.8”
    [beginip] =>  “1.2.4.0”
    [endip] =>    “1.2.4.255”
}
[02] \Vipkwd\Utils\Ip::getInfo("127.0.0.1"); //array(8) {
    [state] =>    “-”
    [region] =>   “-”
    [province] => “-”
    [city] =>     “内网IP”
    [isp] =>      “内网IP”
    [ip] =>       “127.0.0.1”
    [beginip] =>  “127.0.0.1”
    [endip] =>    “127.0.0.1”
}
[03] \Vipkwd\Utils\Ip::getInfo("120.235.131.155"); //array(8) {
    [state] =>    “中国”
    [region] =>   “-”
    [province] => “广东省”
    [city] =>     “惠州市”
    [isp] =>      “移动”
    [ip] =>       “120.235.131.155”
    [beginip] =>  “120.235.129.0”
    [endip] =>    “120.235.141.255”
}
[04] \Vipkwd\Utils\Ip::getInfo("236.230.35.38/29"); //array(8) {
    [state] =>    “-”
    [region] =>   “-”
    [province] => “-”
    [city] =>     “内网IP”
    [isp] =>      “内网IP”
    [ip] =>       “236.230.35.38”
    [beginip] =>  “225.0.0.0”
    [endip] =>    “239.255.255.255”
}
------------------------------------------------------------------------------------

无效空间/类

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd dump 10.musume.com
[Notice] Undefined constant "\Vipkwd\Utils\10\Musume\Com::class" with /data/wwwroot/10musume.com/vendor\vipkwd\utils/src/10/Musume/Com.php

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd dump porn
[Notice] Undefined constant "\Vipkwd\Utils\Porn::class" with /data/wwwroot/10musume.com/vendor\vipkwd\utils/src/Porn.php

[load::assets ] 下载/更新静态资源

yipeng@mbp vipkwd-framework % php vendor/bin/vipkwd load:assets
 You must use option `-c https://domain.com` manually enter your own cdn address or specify one from the list of below
 But have found the following cdn maps, please choose[index/url] one of them?  [http://vipkwd.eu5.net]:
  [0] http://vipkwd.eu5.net
  [1] http://vipkwd.totalh.net
  [2] http://dl.vipkwd.com
  [3] http://vipkwd.byethost13.com
  [4] quit
 >

-----------------------------------------------------------------------------------------------------------------
--- CDN Ping( http://vipkwd.eu5.net ):Ok
--- CDN Maps( http://vipkwd.eu5.net/vipkwd-cdn/maps.php ): Ok
-----------------------------------------------------------------------------------------------------------------

--> [1] 55fc1266e3821b3dd3d1a533dcd9c113 ttfs/1.ttf
    └-····················································································· (Download completed)
--> [2] 45d3bab54f8d612976187570fbde8e3a ttfs/2.ttf
    └-····················································································· (Download completed)
--> [3] 08774b94f4feaedebb6072251124f8aa ttfs/3.ttf
    └-····················································································· (Download completed)
--> [4] 629a55a7e793da068dc580d184cc0e31 ttfs/4.ttf
    └-····················································································· (Download completed)
--> [5] ac3f799d5bbaf5196fab15ab8de8431c ttfs/5.ttf
    └-····················································································· (Download completed)
--> [6] 1c5965c2b1dcdea439b54c3ac60cee38 ttfs/6.ttf
    └-····················································································· (Download completed)
--> [7] f80465e9d8cea2b48da01f5aba236b59 ttfs/msyh.ttf
    └-····················································································· (Download completed)
--> [8] 084fe7a7c7c24816842b618a3e839290 qqwry.dat
     └-····················································································· (Download completed)

实例

  • 更多使用请参照example用例

欢迎Star,欢迎Fork