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
|
|
|
use think\console\Command; |
16
|
|
|
use think\console\input\Option; |
17
|
|
|
|
18
|
|
|
class VendorPublish extends Command |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
public function configure() |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$this->setName('vendor:publish') |
23
|
|
|
->addOption('force', 'f', Option::VALUE_NONE, 'Overwrite any existing files') |
24
|
|
|
->setDescription('Publish any publishable assets from vendor packages'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function handle() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
$force = $this->input->getOption('force'); |
31
|
|
|
|
32
|
|
|
if (is_file($path = $this->app->getRootPath() . 'vendor/composer/installed.json')) { |
33
|
|
|
$packages = json_decode(@file_get_contents($path), true); |
34
|
|
|
|
35
|
|
|
foreach ($packages as $package) { |
36
|
|
|
//配置 |
37
|
|
|
$configDir = $this->app->getConfigPath(); |
38
|
|
|
|
39
|
|
|
if (!empty($package['extra']['think']['config'])) { |
40
|
|
|
|
41
|
|
|
$installPath = $this->app->getRootPath() . 'vendor/' . $package['name'] . DIRECTORY_SEPARATOR; |
42
|
|
|
|
43
|
|
|
foreach ((array) $package['extra']['think']['config'] as $name => $file) { |
44
|
|
|
|
45
|
|
|
$target = $configDir . $name . '.php'; |
46
|
|
|
$source = $installPath . $file; |
47
|
|
|
|
48
|
|
|
if (is_file($target) && !$force) { |
49
|
|
|
$this->output->info("File {$target} exist!"); |
50
|
|
|
continue; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (!is_file($source)) { |
54
|
|
|
$this->output->info("File {$source} not exist!"); |
55
|
|
|
continue; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
copy($source, $target); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->output->writeln('<info>Succeed!</info>'); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|