cinling / ext-lib
通用代码库。
3.0.0.beta
2023-02-08 12:23 UTC
Requires
- php: ^7.3||^8.0
- ext-curl: *
- ext-ftp: *
- ext-json: *
- ext-libxml: *
- ext-mbstring: *
- ext-simplexml: *
- phpoffice/phpspreadsheet: ^1.8
Requires (Dev)
- doctrine/instantiator: 1.5.0
- phpunit/phpunit: 9.5.10
- symfony/yaml: v3.4.47
README
安装
composer require "cinling/ext-lib"
文档
- 服务
- Util
- ArrayUtil
- ConsoleUtil
- CronParseUtil
- DevelUtil
- EncryptUtil
- EnvUtil
- ExcelUtil
- FileUtil
- GeoUtil
- 值对象(vo)...
- 枚举...
服务
- 函数封装
- 提供可配置参数
FileCacheService
- 保存数据到文件
配置
示例
设置缓存
use cin\extLib\services\FileCacheService; FileCacheService::getIns()->set("CacheKeyCin", "cin");
获取缓存
use cin\extLib\services\FileCacheService; $srv = FileCacheService::getIns(); $srv->set("CacheKeyCin", "cin"); $value = FileCacheService::getIns()->get("CacheKeyCin"); echo $value; // output: cin
删除缓存
use cin\extLib\services\FileCacheService; $srv = FileCacheService::getIns(); $srv->set("CacheKeyCin", "cin"); $srv->del("CacheKeyCin"); $value = $srv->get("CacheKeyCin"); echo $value; // output: null
设置带过期时间的缓存
use cin\extLib\services\FileCacheService; FileCacheService::getIns()->set("CacheKeyCin", "cin", 3600); // expire after 3600s
LogService
- 输出日志并保存到日志文件
配置
示例
use cin\extLib\services\LogService; LogService::getIns()->info("Content...", "Title");
输出到 runtime/cin-log/cin.log
[2021-01-18 14:54:31 INFO 标题] 内容...
Util
- 提供静态方法的封装
- 可以通过
trait
插入
ArrayUtil
toArray($attrs): array
将 $attrs
转换为数组。 $attrs
可以是 array
、object
、BaseVo
派生类或上述任意的组合