Skip to content

Commit 6ac9806

Browse files
authored
Merge pull request #4 from cjango/analysis-bQvGoM
Apply fixes from StyleCI
2 parents ed5fc98 + e2b98b3 commit 6ac9806

File tree

13 files changed

+127
-94
lines changed

13 files changed

+127
-94
lines changed

config/api.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
return [
44
/**
5-
* 重新登录后,自动作废以前的token
5+
* 重新登录后,自动作废以前的token.
66
*/
77
'token_auto_revoke' => env('TOKEN_AUTO_REVOKE', true),
88
/**
9-
* token的名称
9+
* token的名称.
1010
*/
1111
'passport_token_name' => env('PASSPORT_TOKEN_NAME', ''),
1212

@@ -16,33 +16,33 @@
1616
*/
1717
'as' => 'api.',
1818
/**
19-
* 可配置 API 独立域名
19+
* 可配置 API 独立域名.
2020
*/
2121
'domain' => env('API_ROUTE_DOMAIN', ''),
2222
/**
2323
* 不使用用独立域名,API 地址前缀
2424
*/
2525
'prefix' => env('API_ROUTE_PREFIX', 'api'),
2626
/**
27-
* API 控制器命名空间
27+
* API 控制器命名空间.
2828
*/
2929
'namespace' => 'App\\Api\\Controllers',
3030
/**
31-
* 中间件
31+
* 中间件.
3232
*/
3333
'middleware' => ['api', 'api.accept'],
3434
/**
35-
* 身份认证的中间件
35+
* 身份认证的中间件.
3636
*/
3737
'middleware_auth' => ['api', 'api.accept', 'token.auth'],
3838
/**
39-
* 获取token,获取不到也不报错的中间件
39+
* 获取token,获取不到也不报错的中间件.
4040
*/
4141
'middleware_guess' => ['api', 'api.accept', 'token.guess'],
4242
],
4343

4444
/**
45-
* 接口目录
45+
* 接口目录.
4646
*/
4747
'directory' => app_path('Api'),
4848
];

src/Api.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Illuminate\Support\Facades\Facade;
77

88
/**
9-
* Class Api
10-
* @package Jason
9+
* Class Api.
10+
*
1111
* @method static string attempt(array $credentials, array $scopes = [])
1212
* @method static string login(User $user, array $scopes = [])
1313
* @method static int userId()
@@ -17,10 +17,8 @@
1717
*/
1818
class Api extends Facade
1919
{
20-
2120
protected static function getFacadeAccessor(): string
2221
{
2322
return 'api';
2423
}
25-
2624
}

src/ApiServiceProvider.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ class ApiServiceProvider extends ServiceProvider
1111
{
1212

1313
/**
14-
* 命令操作
14+
* 命令操作.
15+
*
1516
* @var array
1617
*/
1718
protected array $commands = [
1819
Console\ApiCommand::class,
1920
];
2021

2122
/**
22-
* 路由中间件
23+
* 路由中间件.
24+
*
2325
* @var array
2426
*/
2527
protected array $routeMiddleware = [
@@ -29,17 +31,18 @@ class ApiServiceProvider extends ServiceProvider
2931
];
3032

3133
/**
32-
* Notes: 部署
34+
* Notes: 部署.
35+
*
3336
* @Author: <C.Jason>
3437
* @Date : 2020/1/14 5:21 下午
3538
*/
3639
public function boot()
3740
{
3841
if ($this->app->runningInConsole()) {
39-
$this->publishes([__DIR__ . '/../config' => config_path()], 'api-config');
42+
$this->publishes([__DIR__.'/../config' => config_path()], 'api-config');
4043
}
4144

42-
$this->mergeConfigFrom(__DIR__ . '/../config/api.php', 'api');
45+
$this->mergeConfigFrom(__DIR__.'/../config/api.php', 'api');
4346

4447
if (file_exists($bootstrap = $this->getBootstrapFile())) {
4548
require $bootstrap;
@@ -58,7 +61,8 @@ public function boot()
5861
}
5962

6063
/**
61-
* Notes : 注册监听器
64+
* Notes : 注册监听器.
65+
*
6266
* @Date : 2021/7/23 1:49 下午
6367
* @Author : <Jason.C>
6468
*/
@@ -68,7 +72,8 @@ protected function registerTokenListeners(): void
6872
}
6973

7074
/**
71-
* Notes: 注册功能
75+
* Notes: 注册功能.
76+
*
7277
* @Author: <C.Jason>
7378
* @Date : 2020/1/14 5:21 下午
7479
*/
@@ -78,11 +83,12 @@ public function register()
7883

7984
$this->registerRouteMiddlewares();
8085

81-
$this->app->singleton('api', fn(Application $app) => new Factory($app));
86+
$this->app->singleton('api', fn (Application $app) => new Factory($app));
8287
}
8388

8489
/**
85-
* Notes: 注册路由中间件
90+
* Notes: 注册路由中间件.
91+
*
8692
* @Author: <C.Jason>
8793
* @Date : 2020/1/14 5:21 下午
8894
*/
@@ -94,30 +100,33 @@ public function registerRouteMiddlewares()
94100
}
95101

96102
/**
97-
* Notes: 获取路由文件
103+
* Notes: 获取路由文件.
104+
*
98105
* @Author: <C.Jason>
99106
* @Date : 2020/1/14 5:21 下午
107+
*
100108
* @return string
101109
*/
102110
protected function getRouteFile(): string
103111
{
104-
return ucfirst(config('api.directory')) . DIRECTORY_SEPARATOR . 'routes.php';
112+
return ucfirst(config('api.directory')).DIRECTORY_SEPARATOR.'routes.php';
105113
}
106114

107115
/**
108-
* Notes: 加载部署文件
116+
* Notes: 加载部署文件.
117+
*
109118
* @Author: <C.Jason>
110119
* @Date : 2020/1/14 5:21 下午
120+
*
111121
* @return string
112122
*/
113123
protected function getBootstrapFile(): string
114124
{
115-
return ucfirst(config('api.directory')) . DIRECTORY_SEPARATOR . 'bootstrap.php';
125+
return ucfirst(config('api.directory')).DIRECTORY_SEPARATOR.'bootstrap.php';
116126
}
117127

118128
public function provides(): array
119129
{
120130
return ['api'];
121131
}
122-
123132
}

src/Console/ApiCommand.php

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
class ApiCommand extends Command
88
{
9+
protected $signature = 'api:install';
910

10-
protected $signature = 'api:install';
11-
12-
protected $description = 'Install the API package';
11+
protected $description = 'Install the API package';
1312

1413
protected string $directory = '';
1514

@@ -41,10 +40,10 @@ protected function initDirectory()
4140
}
4241

4342
$this->makeDir('/');
44-
$this->line('<info>Api directory was created:</info> ' . str_replace(base_path(), '', $this->directory));
43+
$this->line('<info>Api directory was created:</info> '.str_replace(base_path(), '', $this->directory));
4544

4645
$this->makeDir('Resources');
47-
$this->line('<info>Resources directory was created:</info> ' . str_replace(base_path(), '', $this->directory));
46+
$this->line('<info>Resources directory was created:</info> '.str_replace(base_path(), '', $this->directory));
4847

4948
$this->makeDir('Controllers');
5049

@@ -58,88 +57,95 @@ protected function initDirectory()
5857
}
5958

6059
/**
61-
* Notes : 创建基础控制器
60+
* Notes : 创建基础控制器.
61+
*
6262
* @Date : 2021/8/25 4:37 下午
6363
* @Author : <Jason.C>
6464
*/
6565
protected function createBaseController()
6666
{
67-
$baseController = $this->directory . '/Controllers/Controller.php';
67+
$baseController = $this->directory.'/Controllers/Controller.php';
6868
$contents = $this->getStub('Controller');
6969

7070
$this->laravel['files']->put(
7171
$baseController,
7272
str_replace('DummyNamespace', config('api.route.namespace'), $contents)
7373
);
74-
$this->line('<info>BaseController file was created:</info> ' . str_replace(base_path(), '', $baseController));
74+
$this->line('<info>BaseController file was created:</info> '.str_replace(base_path(), '', $baseController));
7575
}
7676

7777
/**
78-
* Notes : 创建默认控制器
78+
* Notes : 创建默认控制器.
79+
*
7980
* @Date : 2021/8/25 4:37 下午
8081
* @Author : <Jason.C>
8182
*/
8283
protected function createIndexController()
8384
{
84-
$indexController = $this->directory . '/Controllers/IndexController.php';
85+
$indexController = $this->directory.'/Controllers/IndexController.php';
8586
$contents = $this->getStub('IndexController');
8687

8788
$this->laravel['files']->put(
8889
$indexController,
8990
str_replace('DummyNamespace', config('api.route.namespace'), $contents)
9091
);
91-
$this->line('<info>IndexController file was created:</info> ' . str_replace(base_path(), '', $indexController));
92+
$this->line('<info>IndexController file was created:</info> '.str_replace(base_path(), '', $indexController));
9293
}
9394

9495
/**
95-
* Notes : 创建部署文件
96+
* Notes : 创建部署文件.
97+
*
9698
* @Date : 2021/8/25 4:37 下午
9799
* @Author : <Jason.C>
98100
*/
99101
protected function createBootstrapFile()
100102
{
101-
$file = $this->directory . '/bootstrap.php';
103+
$file = $this->directory.'/bootstrap.php';
102104

103105
$contents = $this->getStub('bootstrap');
104106
$this->laravel['files']->put($file, $contents);
105-
$this->line('<info>Bootstrap file was created:</info> ' . str_replace(base_path(), '', $file));
107+
$this->line('<info>Bootstrap file was created:</info> '.str_replace(base_path(), '', $file));
106108
}
107109

108110
/**
109-
* Notes : 创建路由文件
111+
* Notes : 创建路由文件.
112+
*
110113
* @Date : 2021/8/25 4:37 下午
111114
* @Author : <Jason.C>
112115
*/
113116
protected function createRoutesFile()
114117
{
115-
$file = $this->directory . '/routes.php';
118+
$file = $this->directory.'/routes.php';
116119

117120
$contents = $this->getStub('routes');
118121
$this->laravel['files']->put($file, $contents);
119-
$this->line('<info>Routes file was created:</info> ' . str_replace(base_path(), '', $file));
122+
$this->line('<info>Routes file was created:</info> '.str_replace(base_path(), '', $file));
120123
}
121124

122125
/**
123-
* Notes : 获取模板内容
126+
* Notes : 获取模板内容.
127+
*
124128
* @Date : 2021/8/25 4:37 下午
125129
* @Author : <Jason.C>
130+
*
126131
* @param $name
127132
* @return string
128133
*/
129134
protected function getStub($name): string
130135
{
131-
return $this->laravel['files']->get(__DIR__ . "/stubs/$name.stub");
136+
return $this->laravel['files']->get(__DIR__."/stubs/$name.stub");
132137
}
133138

134139
/**
135-
* Notes : 创建文件夹
140+
* Notes : 创建文件夹.
141+
*
136142
* @Date : 2021/8/25 4:37 下午
137143
* @Author : <Jason.C>
144+
*
138145
* @param string $path
139146
*/
140147
protected function makeDir(string $path = '')
141148
{
142149
$this->laravel['files']->makeDirectory("{$this->directory}/$path", 0755, true, true);
143150
}
144-
145151
}

src/Events/Authenticated.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66

77
class Authenticated
88
{
9-
109
public Authenticatable $user;
1110

1211
/**
1312
* Create a new event instance.
13+
*
1414
* @param \Illuminate\Contracts\Auth\Authenticatable $user
1515
* @return void
1616
*/
1717
public function __construct(Authenticatable $user)
1818
{
1919
$this->user = $user;
2020
}
21-
22-
}
21+
}

src/Exceptions/UnauthorizedException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
class UnauthorizedException extends Exception
88
{
9-
109
public function __construct()
1110
{
1211
parent::__construct('Unauthenticated.', 401);
1312
}
14-
15-
}
13+
}

0 commit comments

Comments
 (0)