Skip to content

Commit c990f5c

Browse files
authored
Merge pull request #5 from inhere/master
add more info show
2 parents 40162fe + 96cfcb7 commit c990f5c

126 files changed

Lines changed: 1056 additions & 333 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

res/images/devtool.jpg

19.7 KB
Loading

src/Command/DevCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public static function internalConfig(): array
3232
/**
3333
* Used to publish the internal resources of the module to the 'public' directory
3434
* @Arguments
35-
* srcDir The source assets directory path. eg. `@vendor/some/lib/assets`
36-
* dstDir The defined component name.(default is `@root/public`)
35+
* srcDir The source assets directory path. eg. `@vendor/some/lib/assets`
36+
* dstDir The dist directory component name.(default is `@root/public/some/lib`)
3737
* @Options
3838
* -y, --yes BOOL Do not confirm when execute publish. default is: <info>False</info>
3939
* -f, --force BOOL Force override all exists file.(default: <info>False</info>)

src/Command/GenCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function init()
3333
* name The class name, don't need suffix and ext.(eg. <info>demo</info>)
3434
* dir The class file save dir(default: <info>@app/Commands</info>)
3535
* @Options
36-
* -y, --yes BOOL Whether to ask when writing a file. default is: <info>True</info>
36+
* -y, --yes BOOL No need to confirm when performing file writing. default is: <info>False</info>
3737
* -o, --override BOOL Force override exists file. default is: <info>False</info>
3838
* -n, --namespace STRING The class namespace. default is: <info>App\Commands</info>
3939
* --suffix STRING The class name suffix. default is: <info>Command</info>
@@ -69,7 +69,7 @@ public function command(Input $in, Output $out): int
6969
* name The class name, don't need suffix and ext.(eg. <info>demo</info>)
7070
* dir The class file save dir(default: <info>@app/Controllers</info>)
7171
* @Options
72-
* -y, --yes BOOL Whether to ask when writing a file. default is: <info>True</info>
72+
* -y, --yes BOOL No need to confirm when performing file writing. default is: <info>False</info>
7373
* -o, --override BOOL Force override exists file. default is: <info>False</info>
7474
* -n, --namespace STRING The class namespace. default is: <info>App\Controllers</info>
7575
* --rest BOOL The class will contains CURD action. default is: <info>False</info>
@@ -113,7 +113,7 @@ public function controller(Input $in, Output $out): int
113113
* name The class name, don't need suffix and ext.(eg. <info>demo</info>)
114114
* dir The class file save dir(default: <info>@app/WebSocket</info>)
115115
* @Options
116-
* -y, --yes BOOL Whether to ask when writing a file. default is: <info>True</info>
116+
* -y, --yes BOOL No need to confirm when performing file writing. default is: <info>False</info>
117117
* -o, --override BOOL Force override exists file. default is: <info>False</info>
118118
* -n, --namespace STRING The class namespace. default is: <info>App\WebSocket</info>
119119
* --prefix STRING The route path for the controller. default is class name
@@ -161,7 +161,7 @@ public function rpcService(): int
161161
* name The class name, don't need suffix and ext.(eg. <info>demo</info>)
162162
* dir The class file save dir(default: <info>@app/Listener</info>)
163163
* @Options
164-
* -y, --yes BOOL Whether to ask when writing a file. default is: <info>True</info>
164+
* -y, --yes BOOL No need to confirm when performing file writing. default is: <info>False</info>
165165
* -o, --override BOOL Force override exists file. default is: <info>False</info>
166166
* -n, --namespace STRING The class namespace. default is: <info>App\Listener</info>
167167
* --suffix STRING The class name suffix. default is: <info>Listener</info>
@@ -194,7 +194,7 @@ public function listener(Input $in, Output $out): int
194194
* name The class name, don't need suffix and ext.(eg. <info>demo</info>)
195195
* dir The class file save dir(default: <info>@app/Middlewares</info>)
196196
* @Options
197-
* -y, --yes BOOL Whether to ask when writing a file. default is: <info>True</info>
197+
* -y, --yes BOOL No need to confirm when performing file writing. default is: <info>False</info>
198198
* -o, --override BOOL Force override exists file. default is: <info>False</info>
199199
* -n, --namespace STRING The class namespace. default is: <info>App\Middlewares</info>
200200
* --suffix STRING The class name suffix. default is: <info>Middleware</info>
@@ -227,7 +227,7 @@ public function middleware(Input $in, Output $out): int
227227
* name The class name, don't need suffix and ext.(eg. <info>demo</info>)
228228
* dir The class file save dir(default: <info>@app/Tasks</info>)
229229
* @Options
230-
* -y, --yes BOOL Whether to ask when writing a file. default is: <info>True</info>
230+
* -y, --yes BOOL No need to confirm when performing file writing. default is: <info>False</info>
231231
* -o, --override BOOL Force override exists file. default is: <info>False</info>
232232
* -n, --namespace STRING The class namespace. default is: <info>App\Tasks</info>
233233
* --suffix STRING The class name suffix. default is: <info>Task</info>
@@ -260,7 +260,7 @@ public function task(Input $in, Output $out): int
260260
* name The class name, don't need suffix and ext.(eg. <info>demo</info>)
261261
* dir The class file save dir(default: <info>@app/Process</info>)
262262
* @Options
263-
* -y, --yes BOOL Whether to ask when writing a file. default is: <info>True</info>
263+
* -y, --yes BOOL No need to confirm when performing file writing. default is: <info>False</info>
264264
* -o, --override BOOL Force override exists file. default is: <info>False</info>
265265
* -n, --namespace STRING The class namespace. default is: <info>App\Process</info>
266266
* --suffix STRING The class name suffix. default is: <info>Process</info>

src/Controller/AppController.php

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
namespace Swoft\Devtool\Controller;
1212

13+
use Swoft\Aop\Aop;
1314
use Swoft\App;
1415
use Swoft\Bean\BeanFactory;
1516
use Swoft\Bean\Collector\PoolCollector;
1617
use Swoft\Core\Config;
18+
use Swoft\Devtool\Helper\DevToolHelper;
1719
use Swoft\Http\Message\Server\Request;
1820
use Swoft\Http\Server\Bean\Annotation\Controller;
1921
use Swoft\Http\Server\Bean\Annotation\RequestMapping;
@@ -159,43 +161,73 @@ public function events(Request $request): Payload
159161
* get all registered components
160162
* @RequestMapping(route="components", method=RequestMethod::GET)
161163
* @return array
164+
* @throws \InvalidArgumentException
162165
*/
163166
public function components(): array
164167
{
165-
return [];
168+
$lockFile = App::getAlias('@root/composer.lock');
169+
170+
return DevToolHelper::parseComposerLockFile($lockFile);
171+
}
172+
173+
/**
174+
* get all registered aop handlers
175+
* @RequestMapping(route="aop/handlers", method=RequestMethod::GET)
176+
* @return array
177+
*/
178+
public function aopHandles(): array
179+
{
180+
/** @var Aop $aop */
181+
$aop = \bean(Aop::class);
182+
183+
return $aop->getAspects();
166184
}
167185

168186
/**
169187
* get all registered http middleware list
170188
* @RequestMapping(route="http/middles", method=RequestMethod::GET)
189+
* @param Request $request
171190
* @return array
172191
*/
173-
public function httpMiddles(): array
192+
public function httpMiddles(Request $request): array
174193
{
175194
/** @var \Swoft\Http\Server\ServerDispatcher $dispatcher */
176195
$dispatcher = \bean('serverDispatcher');
177196

178-
if (\method_exists($dispatcher, 'getMiddlewares')) {
197+
$type = (int)$request->query('type');
198+
199+
// 1 only return user's
200+
if ($type === 1) {
179201
return $dispatcher->getMiddlewares();
180202
}
181203

182-
return [];
204+
return $dispatcher->requestMiddleware();
183205
}
184206

185207
/**
186208
* get all registered rpc middleware list
187209
* @RequestMapping(route="rpc/middles", method=RequestMethod::GET)
210+
* @param Request $request
188211
* @return array
189212
*/
190-
public function rpcMiddles(): array
213+
public function rpcMiddles(Request $request): array
191214
{
215+
$bean = 'ServiceDispatcher';
216+
217+
if (!App::hasBean($bean)) {
218+
return [];
219+
}
220+
192221
/** @var \Swoft\Rpc\Server\ServiceDispatcher $dispatcher */
193-
$dispatcher = \bean('serviceDispatcher');
222+
$dispatcher = \bean($bean);
194223

195-
if (\method_exists($dispatcher, 'getMiddlewares')) {
224+
$type = (int)$request->query('type');
225+
226+
// 1 only return user's
227+
if ($type === 1) {
196228
return $dispatcher->getMiddlewares();
197229
}
198230

199-
return [];
231+
return $dispatcher->requestMiddleware();
200232
}
201233
}

src/Controller/DashboardController.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/Controller/ServerController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@ public function stats(): Payload
101101
return Payload::make($stat);
102102
}
103103

104+
/**
105+
* get crontab list
106+
* @RequestMapping(route="crontab", method=RequestMethod::GET)
107+
* @return array
108+
*/
109+
public function crontab(): array
110+
{
111+
if (!App::hasBean('crontab')) {
112+
return [];
113+
}
114+
115+
/** @var \Swoft\Task\Crontab\Crontab $cronTab */
116+
$cronTab = \bean('crontab');
117+
118+
return $cronTab->getTasks();
119+
}
120+
104121
/**
105122
* get swoole info
106123
* @RequestMapping(route="processes", method=RequestMethod::GET)

src/Helper/DevToolHelper.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Swoft\Devtool\Helper;
4+
5+
/**
6+
* Class DevToolHelper
7+
* @package Swoft\Devtool\Helper
8+
*/
9+
class DevToolHelper
10+
{
11+
/**
12+
* @param string $file
13+
* @return array
14+
*/
15+
public static function parseComposerLockFile(string $file): array
16+
{
17+
if (!\is_file($file)) {
18+
return [];
19+
}
20+
21+
if (!$json = \file_get_contents($file)) {
22+
return [];
23+
}
24+
25+
/** @var array[] $data */
26+
$data = \json_decode($json, true);
27+
$components = [];
28+
29+
if (!$data || !isset($data['packages'])) {
30+
return [];
31+
}
32+
33+
foreach ($data['packages'] as $package) {
34+
if (0 !== \strpos($package['name'], 'swoft/')) {
35+
continue;
36+
}
37+
38+
$components[] = [
39+
'name' => $package['name'],
40+
'version' => $package['version'],
41+
'source' => $package['source'],
42+
'require' => $package['require'] ?? [],
43+
'description' => $package['description'],
44+
'keywords' => $package['keywords'],
45+
'time' => $package['time'],
46+
];
47+
}
48+
49+
return $components;
50+
}
51+
}

src/Middleware/DevToolMiddleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6161

6262
// if not is ajax, always render vue index file.
6363
if (0 === \strpos($path, DevTool::ROUTE_PREFIX) && !$request->isAjax()) {
64-
$json = $request->query('json', 0);
64+
$json = $request->query('json');
6565

66-
if (!$json) {
66+
if (null === $json) {
6767
return \view(App::getAlias('@devtool/web/dist/index.html'), []);
6868
}
6969
}

web/dist/devtool/static/css/app.9f7316c4ee9d5e4c3ae6bf661c9f7394.css

Lines changed: 0 additions & 2 deletions
This file was deleted.

web/dist/devtool/static/css/app.9f7316c4ee9d5e4c3ae6bf661c9f7394.css.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)