|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * FetchVendorCommand.php |
4 |
| - * avanzu-admin |
5 |
| - * Date: 15.02.14 |
| 3 | + * @class FetchVendorCommand |
| 4 | + * |
6 | 5 | */
|
7 |
| - |
8 | 6 | namespace Avanzu\AdminThemeBundle\Command;
|
9 | 7 |
|
10 |
| -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
| 8 | +use Symfony\Component\Console\Command\Command; |
11 | 9 | use Symfony\Component\Console\Helper\FormatterHelper;
|
12 | 10 | use Symfony\Component\Console\Input\InputArgument;
|
13 | 11 | use Symfony\Component\Console\Input\InputInterface;
|
14 | 12 | use Symfony\Component\Console\Input\InputOption;
|
15 | 13 | use Symfony\Component\Console\Output\OutputInterface;
|
16 | 14 | use Symfony\Component\HttpKernel\Kernel;
|
17 | 15 | use Symfony\Component\Process\Process;
|
| 16 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
18 | 17 |
|
19 |
| -class FetchVendorCommand extends ContainerAwareCommand |
| 18 | +class FetchVendorCommand extends Command |
20 | 19 | {
|
| 20 | + |
| 21 | + private $container; |
| 22 | + |
| 23 | + public function __construct(ContainerInterface $container) |
| 24 | + { |
| 25 | + parent::__construct(); |
| 26 | + $this->container = $container; |
| 27 | + } |
| 28 | + |
21 | 29 | protected function configure()
|
22 | 30 | {
|
23 |
| - $this |
24 |
| - ->setName('avanzu:admin:fetch-vendor') |
25 |
| - ->setDescription('fetch vendor assets') |
| 31 | + $this->setName('avanzu:admin:fetch-vendor') |
| 32 | + ->setDescription('Fetch vendor assets') |
26 | 33 | ->addOption('update', 'u', InputOption::VALUE_NONE, 'perform update instead of install')
|
27 |
| - ->addOption('root', 'r', InputOption::VALUE_NONE, 'allow bower to run as root') |
28 |
| - //->addArgument('name', InputArgument::OPTIONAL, 'Who do you want to greet?') |
29 |
| - //->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters') |
30 |
| - ; |
| 34 | + ->addOption('root', 'r', InputOption::VALUE_NONE, 'allow bower to run as root'); |
| 35 | + // ->addArgument('name', InputArgument::OPTIONAL, 'Who do you want to greet?') |
| 36 | + // ->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters') |
| 37 | + |
31 | 38 | }
|
32 | 39 |
|
33 | 40 | protected function execute(InputInterface $input, OutputInterface $output)
|
34 | 41 | {
|
35 |
| - $kernel = $this->getContainer()->get('kernel'); /** @var $kernel Kernel */ |
36 |
| - $res = $kernel->locateResource('@AvanzuAdminThemeBundle/Resources/bower'); |
37 |
| - $helper = $this->getHelperSet()->get('formatter'); /** @var $helper FormatterHelper */ |
38 |
| - $bower = $this->getContainer()->getParameter('avanzu_admin_theme.bower_bin'); |
| 42 | + $kernel = $this->container->get('kernel'); |
| 43 | + /** @var $kernel Kernel */ |
| 44 | + $bowerResource = $kernel->locateResource('@AvanzuAdminThemeBundle/Resources/bower'); |
| 45 | + $helper = $this->getHelperSet()->get('formatter'); |
| 46 | + /** @var $helper FormatterHelper */ |
| 47 | + $bower = $this->container->getParameter('avanzu_admin_theme.bower_bin'); |
39 | 48 |
|
40 | 49 | $action = $input->getOption('update') ? 'update' : 'install';
|
41 | 50 | $asRoot = $input->getOption('root') ? '--allow-root' : '';
|
42 | 51 | $process = new Process($bower . ' ' . $action . ' ' . $asRoot);
|
43 | 52 | $process->setTimeout(600);
|
| 53 | + |
44 | 54 | $output->writeln($helper->formatSection('Executing', $process->getCommandLine(), 'comment'));
|
45 |
| - $process->setWorkingDirectory($res); |
46 |
| - $process->run(function ($type, $buffer) use ($output, $helper) { |
47 |
| - if(Process::ERR == $type) { |
| 55 | + $process->setWorkingDirectory($bowerResource); |
| 56 | + $process->run(function ($type, $buffer) use ($output, $helper) |
| 57 | + { |
| 58 | + if(Process::ERR == $type) |
| 59 | + { |
48 | 60 | $output->write($helper->formatSection('Error', $buffer, 'error'));
|
49 |
| - } else { |
| 61 | + } |
| 62 | + else |
| 63 | + { |
50 | 64 | $output->write($helper->formatSection('Progress', $buffer, 'info'));
|
51 | 65 | }
|
52 | 66 | });
|
| 67 | + |
| 68 | + $output->writeln($helper->formatSection('Done. You should now execute', 'php bin/console assets:install', 'comment')); |
53 | 69 | }
|
54 | 70 | }
|
0 commit comments