|
1
|
|
|
<?php |
|
2
|
|
|
/* (c) Anton Medvedev <[email protected]> |
|
3
|
|
|
* |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Deployer\Console; |
|
9
|
|
|
|
|
10
|
|
|
use Deployer\Initializer\Initializer; |
|
11
|
|
|
use Deployer\Initializer\Template\CakeTemplate; |
|
12
|
|
|
use Deployer\Initializer\Template\CodeIgniterTemplate; |
|
13
|
|
|
use Deployer\Initializer\Template\CommonTemplate; |
|
14
|
|
|
use Deployer\Initializer\Template\DrupalTemplate; |
|
15
|
|
|
use Deployer\Initializer\Template\LaravelTemplate; |
|
16
|
|
|
use Deployer\Initializer\Template\SymfonyTemplate; |
|
17
|
|
|
use Deployer\Initializer\Template\YiiTemplate; |
|
18
|
|
|
use Deployer\Initializer\Template\ZendTemplate; |
|
19
|
|
|
use Symfony\Component\Console\Command\Command; |
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
21
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
22
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
23
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The command for initialize Deployer system in your project |
|
27
|
|
|
* |
|
28
|
|
|
* @author Vitaliy Zhuk <[email protected]> |
|
29
|
|
|
*/ |
|
30
|
|
|
class InitCommand extends Command |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var Initializer |
|
34
|
|
|
*/ |
|
35
|
|
|
private $initializer; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var array |
|
39
|
|
|
*/ |
|
40
|
|
|
private $availableTemplates; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Construct |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $name |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct($name = null) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->initializer = $this->createInitializer(); |
|
50
|
|
|
$this->availableTemplates = $this->initializer->getTemplateNames(); |
|
51
|
|
|
|
|
52
|
|
|
parent::__construct($name); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritDoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function configure() |
|
59
|
|
|
{ |
|
60
|
|
|
$this |
|
61
|
|
|
->setName('init') |
|
62
|
|
|
->setDescription('Initialize deployer system in your project') |
|
63
|
|
|
->addOption('template', 't', InputOption::VALUE_OPTIONAL, 'The template of you project. Available templates: ' . implode(', ', $this->availableTemplates)) |
|
64
|
|
|
->addOption('directory', null, InputOption::VALUE_OPTIONAL, 'The directory for create "deploy.php" file', getcwd()) |
|
65
|
|
|
->addOption('filename', null, InputOption::VALUE_OPTIONAL, 'The file name. Default "deploy.php"', 'deploy.php'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritDoc} |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
72
|
|
|
{ |
|
73
|
|
|
$template = $input->getOption('template'); |
|
74
|
|
|
$directory = $input->getOption('directory'); |
|
75
|
|
|
$file = $input->getOption('filename'); |
|
76
|
|
|
|
|
77
|
|
|
if ($template === null) { |
|
78
|
|
|
$helper = $this->getHelper('question'); |
|
79
|
|
|
$question = new ChoiceQuestion( |
|
80
|
|
|
'Please select your project type (defaults to common):', |
|
81
|
|
|
$this->availableTemplates, |
|
82
|
|
|
0 |
|
83
|
|
|
); |
|
84
|
|
|
$question->setErrorMessage('Project type %s is invalid.'); |
|
85
|
|
|
|
|
86
|
|
|
$template = $helper->ask($input, $output, $question); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$filePath = $this->initializer->initialize($template, $directory, $file); |
|
90
|
|
|
|
|
91
|
|
|
$output->writeln(sprintf( |
|
92
|
|
|
'<info>Successfully created:</info> <comment>%s</comment>', |
|
93
|
|
|
$filePath |
|
94
|
|
|
)); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Create a initializer system |
|
99
|
|
|
* |
|
100
|
|
|
* @return Initializer |
|
101
|
|
|
*/ |
|
102
|
|
|
private function createInitializer() |
|
103
|
|
|
{ |
|
104
|
|
|
$initializer = new Initializer(); |
|
105
|
|
|
|
|
106
|
|
|
$initializer->addTemplate('Common', new CommonTemplate()); |
|
107
|
|
|
$initializer->addTemplate('Laravel', new LaravelTemplate()); |
|
108
|
|
|
$initializer->addTemplate('Symfony', new SymfonyTemplate()); |
|
109
|
|
|
$initializer->addTemplate('Yii', new YiiTemplate()); |
|
110
|
|
|
$initializer->addTemplate('Zend Framework', new ZendTemplate()); |
|
111
|
|
|
$initializer->addTemplate('CakePHP', new CakeTemplate()); |
|
112
|
|
|
$initializer->addTemplate('CodeIgniter', new CodeIgniterTemplate()); |
|
113
|
|
|
$initializer->addTemplate('Drupal', new DrupalTemplate()); |
|
114
|
|
|
|
|
115
|
|
|
return $initializer; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|