Skip to content

Latest commit

 

History

History
136 lines (90 loc) · 2.49 KB

README.md

File metadata and controls

136 lines (90 loc) · 2.49 KB

cinling/ext-lib

简体中文版

Packagist license Packagist version GitHub last commit

Install

composer require "cinling/ext-lib"

Document


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