初始化本地仓库
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'enable' => true,
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'enable' => true,
|
||||
];
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
|
||||
|
||||
return [
|
||||
'enable' => true,
|
||||
/**
|
||||
* 扩展自定义验证规则
|
||||
*/
|
||||
'extends' => function (ValidationFactory $validator): void {
|
||||
// 注册手机号验证规则
|
||||
$validator->extend('mobile', function ($attribute, $value, $parameters) {
|
||||
return preg_match('/^1[3-9]\d{9}$/', $value);
|
||||
}, '无效的手机号码');
|
||||
|
||||
// 注册手机号验证规则(别名)
|
||||
$validator->extend('phone', function ($attribute, $value, $parameters) {
|
||||
return preg_match('/^1[3-9]\d{9}$/', $value);
|
||||
}, '无效的手机号码');
|
||||
}
|
||||
];
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use OpenApi\Annotations as OAA;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
return [
|
||||
/**
|
||||
* 全局开关
|
||||
*/
|
||||
'enable' => true,
|
||||
|
||||
/**
|
||||
* 全局扫描的配置
|
||||
*
|
||||
* @see \WebmanTech\Swagger\Swagger::registerGlobalRoute()
|
||||
* @see \WebmanTech\Swagger\DTO\ConfigRegisterRouteDTO
|
||||
*/
|
||||
'global_route' => [
|
||||
'register_route' => false,
|
||||
'enable' => false,
|
||||
'openapi_doc' => [
|
||||
'scan_path' => [
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
/**
|
||||
* 全局的 host forbidden 配置
|
||||
*
|
||||
* @see \WebmanTech\Swagger\DTO\ConfigHostForbiddenDTO
|
||||
*/
|
||||
'host_forbidden' => [
|
||||
'enable' => true,
|
||||
'host_white_list' => [],
|
||||
],
|
||||
|
||||
/**
|
||||
* 全局的 swagger ui 配置
|
||||
*
|
||||
* @see \WebmanTech\Swagger\DTO\ConfigSwaggerUiDTO
|
||||
*/
|
||||
'swagger_ui' => [
|
||||
|
||||
],
|
||||
|
||||
/**
|
||||
* 全局的 openapi doc 配置
|
||||
*
|
||||
* @see \WebmanTech\Swagger\DTO\ConfigOpenapiDocDTO
|
||||
*/
|
||||
'openapi_doc' => [
|
||||
'scan_path' => function () {
|
||||
},
|
||||
'scan_exclude' => [
|
||||
],
|
||||
'modify' => function (OAA\OpenApi $openapi) {
|
||||
},
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
\WebmanTech\Swagger\Swagger::create()->registerGlobalRoute();
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
];
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Lock\Store\FlockStore;
|
||||
use Symfony\Component\Lock\Store\RedisStore;
|
||||
|
||||
return [
|
||||
'storage' => 'file', // file/redis, 建议使用 redis,file 不支持 ttl
|
||||
'storage_configs' => [
|
||||
'file' => [
|
||||
'class' => FlockStore::class,
|
||||
'construct' => [
|
||||
'lockPath' => runtime_path() . '/lock',
|
||||
],
|
||||
],
|
||||
'redis' => [
|
||||
'class' => RedisStore::class,
|
||||
'construct' => function() {
|
||||
return [
|
||||
'redis' => \support\Redis::connection('default')->client(),
|
||||
];
|
||||
},
|
||||
],
|
||||
],
|
||||
'default_config' => [
|
||||
'ttl' => 300, // 默认锁超时时间
|
||||
'auto_release' => true, // 是否自动释放,建议设置为 true
|
||||
'prefix' => 'lock_', // 锁前缀
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
|
||||
'build_dir' => BASE_PATH . DIRECTORY_SEPARATOR . 'build',
|
||||
|
||||
'phar_filename' => 'webman.phar',
|
||||
|
||||
'bin_filename' => 'webman.bin',
|
||||
|
||||
'signature_algorithm'=> Phar::SHA256, //set the signature algorithm for a phar and apply it. The signature algorithm must be one of Phar::MD5, Phar::SHA1, Phar::SHA256, Phar::SHA512, or Phar::OPENSSL.
|
||||
|
||||
'private_key_file' => '', // The file path for certificate or OpenSSL private key file.
|
||||
|
||||
'exclude_pattern' => '#^(?!.*(composer.json|/.github/|/.idea/|/.git/|/.setting/|/runtime/|/vendor-bin/|/build/|/vendor/webman/admin/))(.*)$#',
|
||||
|
||||
'exclude_files' => [
|
||||
'.env', 'LICENSE', 'composer.json', 'composer.lock', 'start.php', 'webman.phar', 'webman.bin'
|
||||
],
|
||||
|
||||
'custom_ini' => '
|
||||
memory_limit = 256M
|
||||
',
|
||||
];
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
];
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
return [
|
||||
Webman\Event\BootStrap::class,
|
||||
];
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Webman\Event\EventListCommand;
|
||||
|
||||
return [
|
||||
EventListCommand::class
|
||||
];
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
'exception' => [
|
||||
// 是否记录异常到日志
|
||||
'enable' => true,
|
||||
// 不会记录到日志的异常类
|
||||
'dontReport' => [
|
||||
support\exception\BusinessException::class
|
||||
]
|
||||
],
|
||||
'dontReport' => [
|
||||
'app' => [],
|
||||
'controller' => [],
|
||||
'action' => [],
|
||||
'path' => []
|
||||
],
|
||||
'channel' => 'default' // 日志通道(在config/log.php里配置,默认是default)
|
||||
];
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
use Webman\Log\Middleware;
|
||||
|
||||
return [
|
||||
'@' => [
|
||||
Middleware::class
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
'websocket' => 'websocket://0.0.0.0:3001',
|
||||
'api' => 'http://127.0.0.1:3002',
|
||||
'app_key' => '60756ede2a9737a05384aad849e220f8',
|
||||
'app_secret' => '5042267ccd10745be938a5e54eba9375',
|
||||
'channel_hook' => 'http://127.0.0.1:8001/plugin/webman/push/hook',
|
||||
'auth' => '/plugin/webman/push/auth'
|
||||
];
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Webman\Push\Server;
|
||||
|
||||
return [
|
||||
'server' => [
|
||||
'handler' => Server::class,
|
||||
'listen' => config('plugin.webman.push.app.websocket'),
|
||||
'count' => 1, // 必须是1
|
||||
'reloadable' => false, // 执行reload不重启
|
||||
'constructor' => [
|
||||
'api_listen' => config('plugin.webman.push.app.api'),
|
||||
'app_info' => [
|
||||
config('plugin.webman.push.app.app_key') => [
|
||||
'channel_hook' => config('plugin.webman.push.app.channel_hook'),
|
||||
'app_secret' => config('plugin.webman.push.app.app_secret'),
|
||||
],
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
use support\Request;
|
||||
use Webman\Route;
|
||||
use Webman\Push\Api;
|
||||
|
||||
/**
|
||||
* 推送js客户端文件
|
||||
*/
|
||||
Route::get('/plugin/webman/push/push.js', function (Request $request) {
|
||||
return response()->file(base_path().'/vendor/webman/push/src/push.js');
|
||||
});
|
||||
|
||||
/**
|
||||
* 私有频道鉴权,这里应该使用session辨别当前用户身份,然后确定该用户是否有权限监听channel_name
|
||||
*/
|
||||
Route::post(config('plugin.webman.push.app.auth'), function (Request $request) {
|
||||
$pusher = new Api(str_replace('0.0.0.0', '127.0.0.1', config('plugin.webman.push.app.api')), config('plugin.webman.push.app.app_key'), config('plugin.webman.push.app.app_secret'));
|
||||
$channel_name = $request->post('channel_name');
|
||||
$session = $request->session();
|
||||
// 这里应该通过session和channel_name判断当前用户是否有权限监听channel_name
|
||||
$has_authority = true;
|
||||
if ($has_authority) {
|
||||
return response($pusher->socketAuth($channel_name, $request->post('socket_id')));
|
||||
} else {
|
||||
return response('Forbidden', 403);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 当频道上线以及下线时触发的回调
|
||||
* 频道上线:是指某个频道从没有连接在线到有连接在线的事件
|
||||
* 频道下线:是指某个频道的所有连接都断开触发的事件
|
||||
*/
|
||||
Route::post(parse_url(config('plugin.webman.push.app.channel_hook'), PHP_URL_PATH), function (Request $request) {
|
||||
|
||||
// 没有x-pusher-signature头视为伪造请求
|
||||
if (!$webhook_signature = $request->header('x-pusher-signature')) {
|
||||
return response('401 Not authenticated', 401);
|
||||
}
|
||||
|
||||
$body = $request->rawBody();
|
||||
|
||||
// 计算签名,$app_secret 是双方使用的密钥,是保密的,外部无从得知
|
||||
$expected_signature = hash_hmac('sha256', $body, config('plugin.webman.push.app.app_secret'), false);
|
||||
|
||||
// 安全校验,如果签名不一致可能是伪造的请求,返回401状态码
|
||||
if ($webhook_signature !== $expected_signature) {
|
||||
return response('401 Not authenticated', 401);
|
||||
}
|
||||
|
||||
// 这里存储这上线 下线的channel数据
|
||||
$payload = json_decode($body, true);
|
||||
|
||||
$channels_online = $channels_offline = [];
|
||||
|
||||
foreach ($payload['events'] as $event) {
|
||||
if ($event['name'] === 'channel_added') {
|
||||
$channels_online[] = $event['channel'];
|
||||
} else if ($event['name'] === 'channel_removed') {
|
||||
$channels_offline[] = $event['channel'];
|
||||
}
|
||||
}
|
||||
|
||||
// 业务根据需要处理上下线的channel,例如将在线状态写入数据库,通知其它channel等
|
||||
// 上线的所有channel
|
||||
echo 'online channels: ' . implode(',', $channels_online) . "\n";
|
||||
// 下线的所有channel
|
||||
echo 'offline channels: ' . implode(',', $channels_offline) . "\n";
|
||||
|
||||
return 'OK';
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
'driver' => 'auto', // auto, apcu, memory, redis
|
||||
'stores' => [
|
||||
'redis' => [
|
||||
'connection' => 'default',
|
||||
]
|
||||
],
|
||||
// 这些ip的请求不做频率限制
|
||||
'ip_whitelist' => [
|
||||
'127.0.0.1',
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
return [
|
||||
Webman\RateLimiter\Bootstrap::class
|
||||
];
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
use Webman\RateLimiter\Limiter;
|
||||
|
||||
return [
|
||||
'@' => [
|
||||
Limiter::class
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
];
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Webman\RedisQueue\Command\MakeConsumerCommand;
|
||||
|
||||
return [
|
||||
MakeConsumerCommand::class
|
||||
];
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
return [
|
||||
'default' => [
|
||||
'handlers' => [
|
||||
[
|
||||
'class' => Monolog\Handler\RotatingFileHandler::class,
|
||||
'constructor' => [
|
||||
runtime_path() . '/logs/redis-queue/queue.log',
|
||||
7, //$maxFiles
|
||||
Monolog\Logger::DEBUG,
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => Monolog\Formatter\LineFormatter::class,
|
||||
'constructor' => [null, 'Y-m-d H:i:s', true],
|
||||
],
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
return [
|
||||
'consumer' => [
|
||||
'handler' => Webman\RedisQueue\Process\Consumer::class,
|
||||
'count' => 8, // 可以设置多进程同时消费
|
||||
'constructor' => [
|
||||
// 消费者类目录
|
||||
'consumer_dir' => app_path() . '/queue/redis',
|
||||
],
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
return [
|
||||
'default' => [
|
||||
'host' => env('QUEUE_REDIS_HOST', '127.0.0.1').':'.env('QUEUE_REDIS_PORT','6379'),
|
||||
'options' => [
|
||||
'auth' => env('QUEUE_REDIS_PASSWORD', null), // 密码,字符串类型,可选参数
|
||||
'db' => env('QUEUE_REDIS_DB', 0), // 数据库
|
||||
'prefix' => env('QUEUE_REDIS_PREFIX', ''), // key 前缀,
|
||||
'max_attempts' => 5, // 消费失败后,重试次数
|
||||
'retry_seconds' => 5, // 重试间隔,单位秒
|
||||
],
|
||||
],
|
||||
];
|
||||
Reference in New Issue
Block a user