diff --git a/config/config.php b/config/config.php index 9d48a95..506bc6a 100644 --- a/config/config.php +++ b/config/config.php @@ -9,7 +9,7 @@ // 插件市场 api 域名 'api_base' => 'http://plugin.you-tang.com/', // 插件市场默认调用的 client class - 'default' => \Yxx\LaravelPlugin\Support\Client\Market::class + 'default' => \Yxx\LaravelPlugin\Support\Client\Market::class, ], 'stubs' => [ @@ -39,7 +39,6 @@ ], 'paths' => [ - 'plugins' => base_path('plugins'), // 资源发布目录 @@ -67,11 +66,9 @@ ], ], - // 自定义命令 'commands' => [], - 'cache' => [ 'enabled' => false, 'key' => 'laravel-plugin', @@ -93,5 +90,4 @@ 'activator' => 'file', - ]; diff --git a/src/Console/Commands/DownLoadCommand.php b/src/Console/Commands/DownLoadCommand.php index b8d0bd0..a456c11 100644 --- a/src/Console/Commands/DownLoadCommand.php +++ b/src/Console/Commands/DownLoadCommand.php @@ -1,4 +1,5 @@ plugins(1), 'data'); - $rows = array_reduce($plugins,function($rows,$item){ + $rows = array_reduce($plugins, function ($rows, $item) { $rows[] = [ count($rows), $item['name'], $item['author'], $item['download_times'], ]; + return $rows; - },[]); + }, []); $this->comment(__('plugins.plugin_list')); $this->table([ __('plugins.serial_number'), __('plugins.name'), __('plugins.author'), - __('plugins.download_times') + __('plugins.download_times'), ], $rows); $sn = $this->ask(__('plugins.input_sn')); @@ -48,14 +48,14 @@ public function handle(): int throw new \InvalidArgumentException(__('plugins.sn_not_exist')); } - $versions = array_map(fn($version) => [ + $versions = array_map(fn ($version) => [ $version['id'], $version['version'], $version['description'], $version['download_times'], $version['status_str'], $version['price'], - ], data_get($plugin, 'versions')); + ], data_get($plugin, 'versions')); $this->comment(__('plugins.version_list')); @@ -70,24 +70,23 @@ public function handle(): int $versionId = $this->ask(__('plugins.input_version_id')); - if (! in_array($versionId, Arr::pluck($plugin['versions'], 'id'))) { throw new \InvalidArgumentException(__('plugins.version_not_exist')); } Storage::put($path, app('plugins.client')->download($versionId)); - Artisan::call("plugin:install", ["path" => Storage::path($path)]); + Artisan::call('plugin:install', ['path' => Storage::path($path)]); $this->info(__('plugins.download_successful')); - } catch (\Exception $exception) { $this->error($exception->getMessage()); + return E_ERROR; } finally { - Storage::delete($path); + Storage::delete($path); } return 0; } -} \ No newline at end of file +} diff --git a/src/Console/Commands/RegisterCommand.php b/src/Console/Commands/RegisterCommand.php index a35fbd5..54d66ae 100644 --- a/src/Console/Commands/RegisterCommand.php +++ b/src/Console/Commands/RegisterCommand.php @@ -25,12 +25,12 @@ public function handle(): int $account = $this->ask('Account'); $password = $this->secret('Password'); if (Str::length($password) < 8) { - throw new \InvalidArgumentException("The password must be at least 8 characters."); + throw new \InvalidArgumentException('The password must be at least 8 characters.'); } $passwordConfirmation = $this->secret('Confirmation Password'); if ($passwordConfirmation !== $password) { - throw new \InvalidArgumentException("The password confirmation does not match."); + throw new \InvalidArgumentException('The password confirmation does not match.'); } $result = app('plugins.client')->register( diff --git a/src/Console/Commands/UploadCommand.php b/src/Console/Commands/UploadCommand.php index 5d6add4..5f7996f 100644 --- a/src/Console/Commands/UploadCommand.php +++ b/src/Console/Commands/UploadCommand.php @@ -53,7 +53,7 @@ public function handle(): int ]); } catch (\Exception $exception) { $this->line(''); - $this->error('Plugin upload failed : ' . $exception->getMessage()); + $this->error('Plugin upload failed : '.$exception->getMessage()); return E_ERROR; } diff --git a/src/Contracts/ClientInterface.php b/src/Contracts/ClientInterface.php index ae5cfaa..869f95a 100644 --- a/src/Contracts/ClientInterface.php +++ b/src/Contracts/ClientInterface.php @@ -1,4 +1,5 @@ app->singleton(ClientInterface::class, function ($app){ + $this->app->singleton(ClientInterface::class, function ($app) { $class = $app['config']->get('plugins.market.default'); if ($class === null) { throw InvalidActivatorClass::missingConfig(); } + return new $class(); }); $this->app->alias(RepositoryInterface::class, 'plugins.repository'); diff --git a/src/Support/Client/Market.php b/src/Support/Client/Market.php index e53b5b6..cc6d488 100644 --- a/src/Support/Client/Market.php +++ b/src/Support/Client/Market.php @@ -1,40 +1,43 @@ httpPostJson('/api/pluginmarket/login', [ 'email' => $account, - 'password' => $password + 'password' => $password, ]); } /** - * 用户注册 + * 用户注册. * * @param string $account * @param string $password * @param string $name * @param string $passwordConfirmation * @return array + * * @throws GuzzleException */ public function register(string $account, string $name, string $password, string $passwordConfirmation): array @@ -48,10 +51,11 @@ public function register(string $account, string $name, string $password, string } /** - * 选择插件版本进行下载 + * 选择插件版本进行下载. * * @param int $versionId * @return StreamInterface + * * @throws GuzzleException */ public function download(int $versionId): StreamInterface @@ -71,10 +75,11 @@ public function download(int $versionId): StreamInterface } /** - * 用户插件上传 + * 用户插件上传. * * @param array $options * @return array + * * @throws GuzzleException */ public function upload(array $options): array @@ -82,19 +87,19 @@ public function upload(array $options): array return $this->request('/api/pluginmarket/plugins', 'POST', $options); } - /** - * 获取插件市场发布的插件 + * 获取插件市场发布的插件. * * @param int $page * @return array + * * @throws GuzzleException */ public function plugins(int $page): array { return $this->httpGet('/api/pluginmarket/plugins', [ 'page' => $page, - 'status' => 'release' + 'status' => 'release', ]); } -} \ No newline at end of file +} diff --git a/src/Traits/HasGuzzleClient.php b/src/Traits/HasGuzzleClient.php index 22500a0..ecfd486 100644 --- a/src/Traits/HasGuzzleClient.php +++ b/src/Traits/HasGuzzleClient.php @@ -1,4 +1,5 @@ request($url, 'GET', ['query' => $query]); } + /** * @param string $url * @param array $data @@ -84,6 +86,7 @@ public function httpPostJson(string $url, array $data = [], array $query = []): * @param array $data * @param array $query * @return array + * * @throws GuzzleException */ public function httpPutJson(string $url, array $data = [], array $query = []): array @@ -124,6 +127,7 @@ public function request(string $url, string $method = 'GET', array $options = [] throw $e; } } + /** * Get a HTTP client instance. * @@ -170,4 +174,4 @@ public function getAuthorization(): string return request()->header('token', ''); } } -} \ No newline at end of file +} diff --git a/tests/Commands/RouteProviderMakeCommandTest.php b/tests/Commands/RouteProviderMakeCommandTest.php index 1299849..ec1ef2d 100644 --- a/tests/Commands/RouteProviderMakeCommandTest.php +++ b/tests/Commands/RouteProviderMakeCommandTest.php @@ -31,7 +31,6 @@ public function tearDown(): void parent::tearDown(); } - public function it_generates_a_new_service_provider_class() { $path = $this->pluginPath.'/Providers/RouteServiceProvider.php';