|
@@ -1,63 +0,0 @@
|
|
|
-<?php
|
|
|
|
|
-declare(strict_types=1);
|
|
|
|
|
-
|
|
|
|
|
-namespace SixShop\Auth\Hook;
|
|
|
|
|
-
|
|
|
|
|
-use SixShop\Core\Attribute\Hook;
|
|
|
|
|
-use SixShop\Core\Helper;
|
|
|
|
|
-use Symfony\Component\HttpClient\HttpClient;
|
|
|
|
|
-
|
|
|
|
|
-class ConfigFileHook
|
|
|
|
|
-{
|
|
|
|
|
- private array $normalModuleList = [];
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @param array{market_server_url: array<string, string>, market_server_url: array<string, string>, market_api_key: string} $config
|
|
|
|
|
- */
|
|
|
|
|
- #[Hook('after_write_extension_config:auth')]
|
|
|
|
|
- public function updateNormalModuleList(array $config): void
|
|
|
|
|
- {
|
|
|
|
|
- $marketServerUrl = $config['market_server_url']['value'] ?? '';
|
|
|
|
|
- $marketApiKey = $config['market_api_key']['value'] ?? '';
|
|
|
|
|
-
|
|
|
|
|
- // 方案A:当 key 为空时,跳过外部校验与请求,保持保存成功且不抛错
|
|
|
|
|
- if ($marketApiKey === '') {
|
|
|
|
|
- $this->normalModuleList = [];
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- $client = HttpClient::create([
|
|
|
|
|
- 'base_uri' => $marketServerUrl,
|
|
|
|
|
- 'headers' => ['X-API-KEY' => $marketApiKey],
|
|
|
|
|
- ]);
|
|
|
|
|
- $response = $client->request('GET', '/php/site/extension');
|
|
|
|
|
- if ($response->getStatusCode() !== 200) {
|
|
|
|
|
- // 有 key 但校验/请求失败时,也不抛错,静默返回
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- $content = $response->getContent(false); // 不抛异常,手动校验
|
|
|
|
|
- if (!json_validate($content)) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- $data = json_decode($content, true);
|
|
|
|
|
- if (!isset($data['data']) || !is_array($data['data'])) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- $this->normalModuleList = array_column($data['data'], 'slug');
|
|
|
|
|
- } catch (\Throwable $e) {
|
|
|
|
|
- // 不抛错,保证保存流程成功
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public function __destruct()
|
|
|
|
|
- {
|
|
|
|
|
- $header = '// This file is automatically generated at:' . date('Y-m-d H:i:s') . PHP_EOL . 'declare (strict_types = 1);' . PHP_EOL;
|
|
|
|
|
- $content = '<?php ' . PHP_EOL . $header . "return " . var_export($this->normalModuleList, true) . ';';
|
|
|
|
|
- file_put_contents(
|
|
|
|
|
- root_path('runtime') . 'module_name_list_normal.php',
|
|
|
|
|
- $content
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|