Skip to content

Commit

Permalink
添加facade注释, 更新助手函数
Browse files Browse the repository at this point in the history
  • Loading branch information
isszz committed Jan 5, 2022
1 parent d3d904c commit dda06fe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
- 未启用存储生成图片时,~~每次图片访问后会清理存储图片的目录内所有文件~~,删除当前访问生成验证码图片
- **2021-10-20 更新**
- 将语言改到为配置项
- **2022-01-05 更新**
- 增加facade注释
- 移除助手类的rotate_captcha_img方法使用rotate_captcha_output代替,用法和\isszz\captcha\rotate\facade\Captcha::output方法相同,返回数组[$mime, $image],生成图片的mime类型和图片内容

## 安装
```
Expand Down Expand Up @@ -335,7 +338,7 @@ if(empty($id)) {
exit('');
}

[$mime, $image] = Captcha::img($id, upload_path('captcha'));
[$mime, $image] = Captcha::output($id, upload_path('captcha'));

if(empty($image)) {
exit('');
Expand Down
4 changes: 2 additions & 2 deletions src/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function get($size = 350): array
* Check if it is rotated to the correct angle
*
* @param int|float|string $angle
* @return array
* @return bool
*/
public function check(string $token, int|float|string $angle = null): bool
{
Expand Down Expand Up @@ -530,7 +530,7 @@ private function getStoreFilePath(): string
* @param string $path
* @return string
*/
public function formatPath(string $path = ''): string
private function formatPath(string $path = ''): string
{
return rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
Expand Down
20 changes: 19 additions & 1 deletion src/facade/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,27 @@

namespace isszz\captcha\rotate\facade;

// use think\Facade;
// use think\Facade; // 如果使用的tinkphp6+也可以使用自带的facade类
use isszz\captcha\rotate\Facade;

/**
* Class Captcha
*
* @package isszz\captcha\rotate\facade
* @mixin \isszz\captcha\rotate\Captcha
* @method static \isszz\captcha\rotate\Captcha create($image = '', $uploadPath = null) 创建旋转验证码所需图像
* @method static array get($size = 350) 生成验证图片并获取相关信息
* @method static bool check(string $token, int|float|string $angle = null) 检查是否旋转到正确的角度
* @method static array output(?string $str = '', string $uploadPath = null) 根据加密后的字符串,获取图片内容数据
* @method static array info() 获取一些信息
* @method static void buildBase() 组装必要的参数
* @method static string getMime() 获取需要生成图像的mime类型
* @method static \isszz\captcha\rotate\Captcha configDrive(string $config) 设置配置驱动
* @method static \isszz\captcha\rotate\Captcha config(string|null $name = null, string|null $defaultValue = null) 获取配置
* @method static \isszz\captcha\rotate\Captcha setLang(string $language = 'en', ?string $file = null) 设置语言
* @method static object lang(string $language = null, ?string $file = null) 初始化语言
* @method static __toString() 输出图像内容|建议只用于测试
*/
class Captcha extends Facade
{
protected static function getFacadeClass()
Expand Down
15 changes: 8 additions & 7 deletions src/helper.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php

use isszz\captcha\rotate\facade\Captcha;
// use isszz\captcha\rotate\facade\Captcha;

if (!function_exists('rotate_captcha')) {
/**
* @param string $image
* @param string $uploadPath
* @param int $size
* @return array
*/
function rotate_captcha(string $image = '', string $uploadPath = null, int $size = 350): array
{
return Captcha::create($image, $uploadPath)->get($size);
return \isszz\captcha\rotate\facade\Captcha::create($image, $uploadPath)->get($size);
}
}

Expand All @@ -22,19 +23,19 @@ function rotate_captcha(string $image = '', string $uploadPath = null, int $size
*/
function rotate_captcha_check(string $token, string $value): bool
{
return Captcha::check($token, $value);
return \isszz\captcha\rotate\facade\Captcha::check($token, $value);
}
}

if (!function_exists('rotate_captcha_img')) {
if (!function_exists('rotate_captcha_output')) {
/**
* @param string $value
* @param string $uploadPath
* @return string
* @return array
*/
function rotate_captcha_img(string $value, string $uploadPath = null): array
function rotate_captcha_output(string $value, string $uploadPath = null): array
{
return Captcha::img($value, $uploadPath);
return \isszz\captcha\rotate\facade\Captcha::output($value, $uploadPath);
}
}

Expand Down

0 comments on commit dda06fe

Please sign in to comment.