1
|
|
|
<?php |
2
|
|
|
// +---------------------------------------------------------------------- |
|
|
|
|
3
|
|
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
4
|
|
|
// +---------------------------------------------------------------------- |
5
|
|
|
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved. |
6
|
|
|
// +---------------------------------------------------------------------- |
7
|
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
8
|
|
|
// +---------------------------------------------------------------------- |
9
|
|
|
// | Author: yunwuxin <[email protected]> |
10
|
|
|
// +---------------------------------------------------------------------- |
11
|
|
|
declare (strict_types = 1); |
12
|
|
|
|
13
|
|
|
namespace think\console\command; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
use think\console\Command; |
17
|
|
|
use think\console\Input; |
18
|
|
|
use think\console\Output; |
19
|
|
|
use think\facade\App; |
20
|
|
|
|
21
|
|
|
class ServiceDiscover extends Command |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
public function configure() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$this->setName('service:discover') |
26
|
|
|
->setDescription('Discover Services for ThinkPHP'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function execute(Input $input, Output $output) |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
if (is_file($path = App::getRootPath() . 'vendor/composer/installed.json')) { |
32
|
|
|
$packages = json_decode(@file_get_contents($path), true); |
33
|
|
|
|
34
|
|
|
$services = []; |
35
|
|
|
foreach ($packages as $package) { |
36
|
|
|
if (!empty($package['extra']['think']['services'])) { |
37
|
|
|
$services = array_merge($services, (array)$package['extra']['think']['services']); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$header = '// This cache file is automatically generated at:' . date('Y-m-d H:i:s') . PHP_EOL . 'declare (strict_types = 1);' . PHP_EOL; |
42
|
|
|
|
43
|
|
|
$content = '<?php ' . PHP_EOL . $header . "return " . var_export($services, true) . ';'; |
44
|
|
|
|
45
|
|
|
if (!is_dir($runtimePath = App::getRuntimePath())) { |
46
|
|
|
mkdir($runtimePath, 0755, true); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
file_put_contents($runtimePath . 'services.php', $content); |
50
|
|
|
|
51
|
|
|
$output->writeln('<info>Succeed!</info>'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
} |