erwane / cakephp-token
在 CakePHP 4 中轻松使用令牌
2.2.0
2023-11-14 15:55 UTC
Requires
- php: >=7.2
- ext-json: *
- cakephp/cakephp: >=4.5 <5
- cakephp/migrations: ^3.0
Requires (Dev)
- cakephp/cakephp-codesniffer: ^3.0
- php-parallel-lint/php-parallel-lint: ^1.2
- phpro/grumphp: ^1.3
- phpunit/phpunit: ^9.0
README
描述
这是一个用于生成和读取临时令牌的非常“易于使用”的 cakephp 4 插件。
安装
composer require erwane/cakephp-token:^2.0 bin/cake migrations migrate -p Token
使用
生成令牌
/** * Create a token with data and return the id * @param array $content an array of custom data * @param string $expire expire exprimed in '+6 days +2 hours' format * @param int $length Token length * @return string The token id */ $myNewTokenId = \Token\Token::generate(array $content, $expire, 8);
获取令牌
// return null (expired or not found) or Token entity $token = \Token\Token::get($tokenId);
删除令牌
令牌的删除可以忽略,它们将在过期时自动销毁,但在某些情况下,您可能需要立即删除一个令牌。
/** * Delete token from id or entity * * @param \Token\Model\Entity\Token|string $token Token entity or id * @return bool True if token was deleted */ $result = \Token\Token::delete($token);
自动清理
每次读取令牌时,都会修剪已过期的令牌。