|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Cecil\Command; |
|
10
|
|
|
|
|
11
|
|
|
use Cecil\Util\Plateform; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
|
18
|
|
|
|
|
19
|
|
|
class CommandNewSite extends Command |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
*/ |
|
24
|
|
|
protected function configure() |
|
25
|
|
|
{ |
|
26
|
|
|
$this |
|
27
|
|
|
->setName('new:site') |
|
28
|
|
|
->setDescription('Create a new website') |
|
29
|
|
|
->setDefinition( |
|
30
|
|
|
new InputDefinition([ |
|
31
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'If specified, use the given path as working directory'), |
|
32
|
|
|
new InputOption('force', 'f', InputOption::VALUE_NONE, 'Override the directory if already exist'), |
|
33
|
|
|
]) |
|
34
|
|
|
) |
|
35
|
|
|
->setHelp('Create a new website in the current directory, or in <path> if provided.'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->force = $input->getOption('force'); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
try { |
|
46
|
|
|
if ($this->fs->exists($this->getPath().'/'.self::CONFIG_FILE) && !$this->force) { |
|
47
|
|
|
$helper = $this->getHelper('question'); |
|
48
|
|
|
$question = new ConfirmationQuestion('Website already exists. Do you want to override it? [y/n]', false); |
|
49
|
|
|
if (!$helper->ask($input, $output, $question)) { |
|
50
|
|
|
return; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
$root = __DIR__.'/../../'; |
|
54
|
|
|
if (Plateform::isPhar()) { |
|
55
|
|
|
$root = Plateform::getPharPath().'/'; |
|
56
|
|
|
} |
|
57
|
|
|
$output->writeln('<info>Creating a new website...</info>'); |
|
58
|
|
|
$this->fs->copy($root.'res/skeleton/config.yml', $this->getPath().'/'.self::CONFIG_FILE, true); |
|
59
|
|
|
$this->fs->mirror($root.'res/skeleton/content', $this->getPath().'/content'); |
|
60
|
|
|
$this->fs->mirror($root.'res/skeleton/layouts', $this->getPath().'/layouts'); |
|
61
|
|
|
$this->fs->mirror($root.'res/skeleton/static', $this->getPath().'/static'); |
|
62
|
|
|
$output->writeln('Done!'); |
|
63
|
|
|
} catch (\Exception $e) { |
|
64
|
|
|
throw new \Exception(sprintf($e->getMessage())); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return 0; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: