|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CRM library |
|
4
|
|
|
* @author Tao <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Slince\Crm\Command; |
|
7
|
|
|
|
|
8
|
|
|
use Slince\Crm\Exception\RuntimeException; |
|
9
|
|
|
use Slince\Crm\RegistryManager; |
|
10
|
|
|
use Symfony\Component\Console\Command\Command as BaseCommand; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
13
|
|
|
|
|
14
|
|
|
class Command extends BaseCommand implements CommandInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var RegistryManager |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $manager; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* composer.json |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $composerFileName = 'composer.json'; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(RegistryManager $manager, $name = null) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->manager = $manager; |
|
30
|
|
|
parent::__construct($name); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function configure() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->addOption('current', 'c', InputOption::VALUE_NONE, 'Manage the current config file'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param RegistryManager $manager |
|
40
|
|
|
*/ |
|
41
|
|
|
public function setManager($manager) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->manager = $manager; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getManager() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->manager; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Is global mode |
|
56
|
|
|
* @param InputInterface $input |
|
57
|
|
|
* @throws RuntimeException |
|
58
|
|
|
* @return bool |
|
59
|
|
|
*/ |
|
60
|
|
|
public function checkIsCurrent(InputInterface $input) |
|
61
|
|
|
{ |
|
62
|
|
|
$isCurrentMode = $input->getOption('current'); |
|
63
|
|
|
if ($isCurrentMode) { |
|
64
|
|
|
$composerJson = getcwd() . DIRECTORY_SEPARATOR . $this->composerFileName; |
|
65
|
|
|
if (!file_exists($composerJson)) { |
|
66
|
|
|
throw new RuntimeException("Crm could not find a composer.json file"); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
return $isCurrentMode; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param string $composerFileName |
|
74
|
|
|
*/ |
|
75
|
|
|
public function setComposerFileName($composerFileName) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->composerFileName = $composerFileName; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getComposerFileName() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->composerFileName; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|