forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitCommand.php
More file actions
89 lines (78 loc) · 2.2 KB
/
Copy pathInitCommand.php
File metadata and controls
89 lines (78 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* @file
* Contains \Drupal\AppConsole\Command\InitCommand.
*/
namespace Drupal\AppConsole\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class InitCommand extends ContainerAwareCommand
{
private $files = [
[
'source' => 'config/dist/config.yml',
'destination' => 'config.yml'
],
[
'source' => 'config/dist/chain.yml',
'destination' => 'chain/sample.yml'
]
];
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('init')
->setDescription($this->trans('commands.init.description'))
->addOption(
'override',
null,
InputOption::VALUE_NONE,
$this->trans('commands.init.options.override')
)
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$application = $this->getApplication();
$config = $application->getConfig();
$message = $this->getHelperSet()->get('message');
$basePath = __DIR__ . '/../../';
$userPath = $config->getUserHomeDir() . '/.console/';
$copiedFiles = [];
$override = false;
if ($input->hasOption('override')) {
$override = $input->getOption('override');
}
foreach ($this->files as $file) {
$source = $basePath . $file['source'];
$destination = $userPath . '/' . $file['destination'];
if ($this->copyFile($source, $destination, $override)) {
$copiedFiles[] = $file['destination'];
}
}
if ($copiedFiles) {
$message->showCopiedFiles($output, $copiedFiles);
}
}
public function copyFile($source, $destination, $override)
{
if (file_exists($destination) && !$override) {
return false;
}
$filePath = dirname($destination);
if (!is_dir($filePath)) {
mkdir($filePath);
}
return copy(
$source,
$destination
);
}
}