These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\Component\Initializer\Initializer; |
||
11 | use Deployer\Component\Initializer\Template\CakeTemplate; |
||
12 | use Deployer\Component\Initializer\Template\CodeIgniterTemplate; |
||
13 | use Deployer\Component\Initializer\Template\CommonTemplate; |
||
14 | use Deployer\Component\Initializer\Template\DrupalTemplate; |
||
15 | use Deployer\Component\Initializer\Template\LaravelTemplate; |
||
16 | use Deployer\Component\Initializer\Template\SymfonyTemplate; |
||
17 | use Deployer\Component\Initializer\Template\Typo3Template; |
||
18 | use Deployer\Component\Initializer\Template\Yii2AdvancedAppTemplate; |
||
19 | use Deployer\Component\Initializer\Template\Yii2BasicAppTemplate; |
||
20 | use Deployer\Component\Initializer\Template\YiiTemplate; |
||
21 | use Deployer\Component\Initializer\Template\ZendTemplate; |
||
22 | use Symfony\Component\Console\Command\Command; |
||
23 | use Symfony\Component\Console\Helper\FormatterHelper; |
||
24 | use Symfony\Component\Console\Input\InputInterface; |
||
25 | use Symfony\Component\Console\Input\InputOption; |
||
26 | use Symfony\Component\Console\Output\OutputInterface; |
||
27 | use Symfony\Component\Console\Style\SymfonyStyle; |
||
28 | use Symfony\Component\Process\Exception\RuntimeException; |
||
29 | use Symfony\Component\Process\Process; |
||
30 | |||
31 | class InitCommand extends Command |
||
32 | { |
||
33 | |||
34 | 9 | protected function configure() |
|
35 | { |
||
36 | $this |
||
37 | 9 | ->setName('init') |
|
38 | 9 | ->setDescription('Initialize deployer in your project') |
|
39 | 9 | ->addOption('template', 't', InputOption::VALUE_OPTIONAL, 'The template of you project') |
|
40 | 9 | ->addOption('filepath', null, InputOption::VALUE_OPTIONAL, 'The file path (default "deploy.php")', 'deploy.php'); |
|
41 | 9 | } |
|
42 | |||
43 | protected function execute(InputInterface $input, OutputInterface $output) |
||
44 | { |
||
45 | /** @var FormatterHelper $formatter */ |
||
46 | $formatter = $this->getHelper('formatter'); |
||
47 | $initializer = new Initializer(); |
||
48 | $template = $input->getOption('template'); |
||
49 | $filepath = $input->getOption('filepath'); |
||
50 | |||
51 | if (file_exists($filepath)) { |
||
52 | $output->writeln([ |
||
53 | $formatter->formatBlock( |
||
54 | sprintf('The file "%s" already exist.', $filepath), |
||
55 | 'bg=red;fg=white', true |
||
56 | ), |
||
57 | ]); |
||
58 | return 2; |
||
59 | } |
||
60 | |||
61 | $project = 'my_project'; |
||
62 | $repository = ''; |
||
63 | $hosts = []; |
||
64 | $allow = true; |
||
65 | |||
66 | if ($template === null) { |
||
67 | $io = new SymfonyStyle($input, $output); |
||
68 | |||
69 | // Welcome message |
||
70 | $output->writeln(" |
||
71 | _____ _ |
||
72 | | __ \ | | |
||
73 | | | | | ___ _ __ | | ___ _ _ ___ _ __ |
||
74 | | | | |/ _ \ '_ \| |/ _ \| | | |/ _ \ '__| |
||
75 | | |__| | __/ |_) | | (_) | |_| | __/ | |
||
76 | |_____/ \___| .__/|_|\___/ \__, |\___|_| |
||
77 | | | __/ | |
||
78 | |_| |___/ |
||
79 | "); |
||
80 | |||
81 | $io->text([ |
||
82 | 'Welcome to the Deployer config generator.', |
||
83 | 'This utility will walk you through creating a deploy.php file.', |
||
84 | '', |
||
85 | 'Press ^C at any time to quit.', |
||
86 | ]); |
||
87 | |||
88 | // Yes? |
||
89 | $io->confirm('Continue?'); |
||
90 | |||
91 | // Template |
||
92 | $recipes = $initializer->getRecipes(); |
||
93 | $template = $io->choice('Select project template', $recipes, 'common'); |
||
94 | |||
95 | // Repo |
||
96 | $default = false; |
||
97 | try { |
||
98 | $process = Process::fromShellCommandline('git remote get-url origin'); |
||
99 | $default = $process->mustRun()->getOutput(); |
||
100 | $default = trim($default); |
||
101 | } catch (RuntimeException $e) { |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
Loading history...
|
|||
102 | } |
||
103 | $repository = $io->ask('Repository', $default); |
||
104 | |||
105 | // Repo |
||
106 | $default = false; |
||
107 | try { |
||
108 | $process = Process::fromShellCommandline('basename "$PWD"'); |
||
109 | $default = $process->mustRun()->getOutput(); |
||
110 | $default = trim($default); |
||
111 | } catch (RuntimeException $e) { |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
112 | } |
||
113 | $project = $io->ask('Project name', $default); |
||
114 | |||
115 | // Hosts |
||
116 | $hosts = explode(',', $io->ask('Hosts (comma separated)', 'deployer.org')); |
||
117 | |||
118 | // Privacy |
||
119 | $io->text([ |
||
120 | 'Contribute to the Deployer Development', |
||
121 | '', |
||
122 | 'In order to help development and improve the features in Deployer,', |
||
123 | 'Deployer has a setting for usage data collection. This function', |
||
124 | 'collects anonymous usage data and sends it to Deployer. The data is', |
||
125 | 'used in Deployer development to get reliable statistics on which', |
||
126 | 'features are used (or not used). The information is not traceable', |
||
127 | 'to any individual or organization. Participation is voluntary,', |
||
128 | 'and you can change your mind at any time.', |
||
129 | '', |
||
130 | 'Anonymous usage data contains Deployer version, php version, os type,', |
||
131 | 'name of the command being executed and whether it was successful or not,', |
||
132 | 'exception class name, count of hosts and anonymized project hash.', |
||
133 | '', |
||
134 | 'This function will not affect the performance of Deployer as', |
||
135 | 'the data is insignificant and transmitted in a separate process.', |
||
136 | '', |
||
137 | 'We appreciate your involvement!', |
||
138 | ]); |
||
139 | |||
140 | $allow = $io->confirm('Do you confirm?'); |
||
141 | } |
||
142 | |||
143 | |||
144 | file_put_contents($filepath, $initializer->getTemplate($template, $project, $repository, $hosts, $allow)); |
||
145 | |||
146 | $output->writeln(sprintf( |
||
147 | '<info>Successfully created</info> <comment>%s</comment>', |
||
148 | $filepath |
||
149 | )); |
||
150 | |||
151 | return 0; |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Create a initializer system |
||
156 | * |
||
157 | * @return Initializer |
||
158 | */ |
||
159 | private function createInitializer() |
||
160 | { |
||
161 | $initializer = new Initializer(); |
||
162 | |||
163 | $initializer->addTemplate('Common', new CommonTemplate()); |
||
0 ignored issues
–
show
The method
addTemplate() does not seem to exist on object<Deployer\Componen...nitializer\Initializer> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
164 | $initializer->addTemplate('Laravel', new LaravelTemplate()); |
||
0 ignored issues
–
show
The method
addTemplate() does not seem to exist on object<Deployer\Componen...nitializer\Initializer> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
165 | $initializer->addTemplate('Symfony', new SymfonyTemplate()); |
||
0 ignored issues
–
show
The method
addTemplate() does not seem to exist on object<Deployer\Componen...nitializer\Initializer> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
166 | $initializer->addTemplate('Yii', new YiiTemplate()); |
||
0 ignored issues
–
show
The method
addTemplate() does not seem to exist on object<Deployer\Componen...nitializer\Initializer> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
167 | $initializer->addTemplate('Yii2 Basic App', new Yii2BasicAppTemplate()); |
||
168 | $initializer->addTemplate('Yii2 Advanced App', new Yii2AdvancedAppTemplate()); |
||
169 | $initializer->addTemplate('Zend Framework', new ZendTemplate()); |
||
0 ignored issues
–
show
The method
addTemplate() does not seem to exist on object<Deployer\Componen...nitializer\Initializer> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
170 | $initializer->addTemplate('CakePHP', new CakeTemplate()); |
||
0 ignored issues
–
show
The method
addTemplate() does not seem to exist on object<Deployer\Componen...nitializer\Initializer> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
171 | $initializer->addTemplate('CodeIgniter', new CodeIgniterTemplate()); |
||
0 ignored issues
–
show
The method
addTemplate() does not seem to exist on object<Deployer\Componen...nitializer\Initializer> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
172 | $initializer->addTemplate('Drupal', new DrupalTemplate()); |
||
0 ignored issues
–
show
The method
addTemplate() does not seem to exist on object<Deployer\Componen...nitializer\Initializer> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
173 | $initializer->addTemplate('TYPO3', new Typo3Template()); |
||
0 ignored issues
–
show
The method
addTemplate() does not seem to exist on object<Deployer\Componen...nitializer\Initializer> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
174 | |||
175 | return $initializer; |
||
176 | } |
||
177 | } |
||
178 |