cinling / ext-lib
General code base for work.
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
Install
composer require "cinling/ext-lib"
Document
- Service
- Util
- ArrayUtil
- ConsoleUtil
- CronParseUtil
- DevelUtil
- EncryptUtil
- EnvUtil
- ExcelUtil
- FileUtil
- GeoUtil
- Value Object(vo)...
- Enums...
Service
- Encapsulation of a function
- Provides configurable parameters
FileCacheService
- Save data to file
Config
name | type | note | default |
---|---|---|---|
path | string | Cache file save path | ./runtime/cin-cache |
pathDeeps | int | Path depth | 2 |
pathUnitLen | int | The number of characters in a single directory | 2 |
Example
Set cache
use cin\extLib\services\FileCacheService; FileCacheService::getIns()->set("CacheKeyCin", "cin");
Get cache
use cin\extLib\services\FileCacheService; $srv = FileCacheService::getIns(); $srv->set("CacheKeyCin", "cin"); $value = FileCacheService::getIns()->get("CacheKeyCin"); echo $value; // output: cin
Delete cache
use cin\extLib\services\FileCacheService; $srv = FileCacheService::getIns(); $srv->set("CacheKeyCin", "cin"); $srv->del("CacheKeyCin"); $value = $srv->get("CacheKeyCin"); echo $value; // output: null
Set cache with expiration time
use cin\extLib\services\FileCacheService; FileCacheService::getIns()->set("CacheKeyCin", "cin", 3600); // expire after 3600s
LogService
- Output the log and save it in the log file
Config
name | type | note | default |
---|---|---|---|
path | string | Log file save path | ./runtime/cin-log |
fileMaxSize | string | Log file max bytes | 2MB |
Example
use cin\extLib\services\LogService; LogService::getIns()->info("Content...", "Title");
output in runtime/cin-log/cin.log
:
[2021-01-18 14:54:31 INFO Title] Content...
Util
- Provides encapsulation of static methods
- It can be inserted by
trait
ArrayUtil
toArray($attrs): array
Convert $attrs
to an array。
$attrs
can be an array
, an object
, a BaseVo
derived class, or any collation of the above