Passed
Push — 5.2 ( 2e1dae...2e1dae )
by
unknown
02:38 queued 21s
created

VendorPublish::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
// +----------------------------------------------------------------------
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
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
1 ignored issue
show
Coding Style introduced by
Missing class doc comment
Loading history...
19
{
20
    public function configure()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
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()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
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