cinling/ext-lib

通用代码库。

3.0.0.beta 2023-02-08 12:23 UTC

This package is auto-updated.

Last update: 2024-09-08 15:44:04 UTC


README

简体中文版

Packagist license Packagist version GitHub last commit

安装

composer require "cinling/ext-lib"

文档

服务

  • 函数封装
  • 提供可配置参数

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 可以是 arrayobjectBaseVo 派生类或上述任意的组合