/
AcmeSymfonyanWelcomeInstallCommand.php
61 lines (53 loc) · 1.97 KB
/
AcmeSymfonyanWelcomeInstallCommand.php
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
<?php
namespace Acme\SymfonyanBundle\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Command\Command;
/**
* SymfonyanExcepotionInstallCommand.
*
* @author brtriver <brt.river@gmail.com>
*/
class AcmeSymfonyanWelcomeInstallCommand extends Command
{
protected $container;
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->container = $this->getApplication()->getKernel()->getContainer();
}
/**
* @see Command
*/
protected function configure()
{
$this
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the welcome page instead of copying it')
->setName('symfonyan:welcome-install')
->setDescription('Change the welcome page to Symfonyan')
;
}
/**
* @see Command
*
* @throws \InvalidArgumentException When the target directory does not exist
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$filesystem = $this->container->get('filesystem');
// Create the bundles directory otherwise symlink will fail.
if (is_dir($originDir = __DIR__.'/../Resources/views/AcmeDemoBundle')) {
$output->writeln(sprintf('Installing symfonyan welcomepage to <comment>app/Resources/AcmeDemoBundle</comment>'));
$targetDir = $this->container->getParameter('kernel.root_dir').'/Resources/AcmeDemoBundle';
$filesystem->remove($targetDir);
if ($input->getOption('symlink')) {
$filesystem->symlink($originDir, $targetDir);
} else {
$filesystem->mkdir($targetDir, 0777);
$filesystem->mirror($originDir, $targetDir);
}
}
}
}