Skip to content
This repository
Newer
Older
100644 121 lines (102 sloc) 4.307 kb
d2536b6c » kriswallsmith
2011-02-10 [AsseticBundle] initial entry of assetic integration
1 <?php
2
3 /*
4 * This file is part of the Symfony framework.
5 *
7bca1643 » fabpot
2011-03-06 replaced symfony-project.org by symfony.com
6 * (c) Fabien Potencier <fabien@symfony.com>
d2536b6c » kriswallsmith
2011-02-10 [AsseticBundle] initial entry of assetic integration
7 *
8 * This source file is subject to the MIT license that is bundled
9 * with this source code in the file LICENSE.
10 */
11
12 namespace Symfony\Bundle\AsseticBundle\Command;
13
4845c654 » kriswallsmith
2013-09-05 use spork to distribute dump across many procs
14 use Spork\Batch\Strategy\ChunkStrategy;
15 use Spork\EventDispatcher\WrappedEventDispatcher;
16 use Spork\ProcessManager;
33532c75 » kriswallsmith
2013-09-05 broke out assetic:watch command
17 use Symfony\Component\Console\Input\ArrayInput;
d2536b6c » kriswallsmith
2011-02-10 [AsseticBundle] initial entry of assetic integration
18 use Symfony\Component\Console\Input\InputArgument;
19 use Symfony\Component\Console\Input\InputInterface;
49ddc95f » kriswallsmith
2011-02-25 [AsseticBundle] added a --watch option to the assetic:dump command
20 use Symfony\Component\Console\Input\InputOption;
33532c75 » kriswallsmith
2013-09-05 broke out assetic:watch command
21 use Symfony\Component\Console\Output\ConsoleOutputInterface;
d2536b6c » kriswallsmith
2011-02-10 [AsseticBundle] initial entry of assetic integration
22 use Symfony\Component\Console\Output\OutputInterface;
23
24 /**
25 * Dumps assets to the filesystem.
26 *
03513245 » kriswallsmith
2011-05-02 updated my email address
27 * @author Kris Wallsmith <kris@symfony.com>
d2536b6c » kriswallsmith
2011-02-10 [AsseticBundle] initial entry of assetic integration
28 */
33532c75 » kriswallsmith
2013-09-05 broke out assetic:watch command
29 class DumpCommand extends AbstractCommand
d2536b6c » kriswallsmith
2011-02-10 [AsseticBundle] initial entry of assetic integration
30 {
4845c654 » kriswallsmith
2013-09-05 use spork to distribute dump across many procs
31 private $spork;
32
d2536b6c » kriswallsmith
2011-02-10 [AsseticBundle] initial entry of assetic integration
33 protected function configure()
34 {
35 $this
36 ->setName('assetic:dump')
37 ->setDescription('Dumps all assets to the filesystem')
98b96066 » kriswallsmith
2011-02-28 [AsseticBundle] separated read and write paths to facilitate writing …
38 ->addArgument('write_to', InputArgument::OPTIONAL, 'Override the configured asset root')
4845c654 » kriswallsmith
2013-09-05 use spork to distribute dump across many procs
39 ->addOption('forks', null, InputOption::VALUE_REQUIRED, 'Fork work across many processes (requires kriswallsmith/spork)')
33532c75 » kriswallsmith
2013-09-05 broke out assetic:watch command
40 ->addOption('watch', null, InputOption::VALUE_NONE, 'DEPRECATED: use assetic:watch instead')
41 ->addOption('force', null, InputOption::VALUE_NONE, 'DEPRECATED: use assetic:watch instead')
42 ->addOption('period', null, InputOption::VALUE_REQUIRED, 'DEPRECATED: use assetic:watch instead', 1)
d2536b6c » kriswallsmith
2011-02-10 [AsseticBundle] initial entry of assetic integration
43 ;
44 }
45
4845c654 » kriswallsmith
2013-09-05 use spork to distribute dump across many procs
46 protected function initialize(InputInterface $input, OutputInterface $stdout)
47 {
48 if (null !== $input->getOption('forks')) {
9044feba » John Kary
2013-09-06 Throw Exception early if using --forks and missing spork library
49 if (!class_exists('Spork\ProcessManager')) {
cfebc3e4 » John Kary
2013-09-06 More explicit in what exactly kriswallsmith/spork is
50 throw new \RuntimeException('The --forks option requires that package kriswallsmith/spork be installed');
9044feba » John Kary
2013-09-06 Throw Exception early if using --forks and missing spork library
51 }
52
4845c654 » kriswallsmith
2013-09-05 use spork to distribute dump across many procs
53 if (!is_numeric($input->getOption('forks'))) {
54 throw new \InvalidArgumentException('The --forks options must be numeric');
55 }
56
57 $this->spork = new ProcessManager(
58 new WrappedEventDispatcher($this->getContainer()->get('event_dispatcher')),
59 $this->getContainer()->getParameter('kernel.debug')
60 );
61 }
62
63 parent::initialize($input, $stdout);
64 }
65
33532c75 » kriswallsmith
2013-09-05 broke out assetic:watch command
66 protected function execute(InputInterface $input, OutputInterface $stdout)
10e1f2fd » kriswallsmith
2011-05-06 [AsseticBundle] moved base path to object property
67 {
33532c75 » kriswallsmith
2013-09-05 broke out assetic:watch command
68 // capture error output
69 $stderr = $stdout instanceof ConsoleOutputInterface
70 ? $stdout->getErrorOutput()
71 : $stdout;
72
73 if ($input->getOption('watch')) {
4fed8c65 » Burgov
2013-09-10 Fixed fatal error after --watch was deprecated
74 $stderr->writeln(
33532c75 » kriswallsmith
2013-09-05 broke out assetic:watch command
75 '<error>The --watch option is deprecated. Please use the '.
76 'assetic:watch command instead.</error>'
77 );
78
79 // build assetic:watch arguments
80 $arguments = array(
81 'command' => 'assetic:watch',
82 'write_to' => $this->basePath,
83 '--period' => $input->getOption('period'),
84 '--env' => $input->getOption('env'),
85 );
86
87 if ($input->getOption('no-debug')) {
88 $arguments['--no-debug'] = true;
279baf79 » kriswallsmith
2011-05-06 [AsseticBundle] rearranged execute() method
89 }
49ddc95f » kriswallsmith
2011-02-25 [AsseticBundle] added a --watch option to the assetic:dump command
90
33532c75 » kriswallsmith
2013-09-05 broke out assetic:watch command
91 if ($input->getOption('force')) {
92 $arguments['--force'] = true;
ef241880 » tgabi333
2012-07-24 avoiding 100% proc usage and error handling when unserialization is u…
93 }
49ddc95f » kriswallsmith
2011-02-25 [AsseticBundle] added a --watch option to the assetic:dump command
94
33532c75 » kriswallsmith
2013-09-05 broke out assetic:watch command
95 $command = $this->getApplication()->find('assetic:watch');
49ddc95f » kriswallsmith
2011-02-25 [AsseticBundle] added a --watch option to the assetic:dump command
96
33532c75 » kriswallsmith
2013-09-05 broke out assetic:watch command
97 return $command->run(new ArrayInput($arguments), $stdout);
49ddc95f » kriswallsmith
2011-02-25 [AsseticBundle] added a --watch option to the assetic:dump command
98 }
99
33532c75 » kriswallsmith
2013-09-05 broke out assetic:watch command
100 // print the header
101 $stdout->writeln(sprintf('Dumping all <comment>%s</comment> assets.', $input->getOption('env')));
102 $stdout->writeln(sprintf('Debug mode is <comment>%s</comment>.', $this->am->isDebug() ? 'on' : 'off'));
103 $stdout->writeln('');
49ddc95f » kriswallsmith
2011-02-25 [AsseticBundle] added a --watch option to the assetic:dump command
104
4845c654 » kriswallsmith
2013-09-05 use spork to distribute dump across many procs
105 if ($this->spork) {
106 $batch = $this->spork->createBatchJob(
107 $this->am->getNames(),
108 new ChunkStrategy($input->getOption('forks'))
109 );
110
111 $self = $this;
97a07a8d » stof
2013-11-25 Fixed CS
112 $batch->execute(function ($name) use ($self, $stdout) {
4845c654 » kriswallsmith
2013-09-05 use spork to distribute dump across many procs
113 $self->dumpAsset($name, $stdout);
114 });
115 } else {
116 foreach ($this->am->getNames() as $name) {
117 $this->dumpAsset($name, $stdout);
118 }
49ddc95f » kriswallsmith
2011-02-25 [AsseticBundle] added a --watch option to the assetic:dump command
119 }
cfe439a3 » kriswallsmith
2013-03-11 cleaned up dump command
120 }
d2536b6c » kriswallsmith
2011-02-10 [AsseticBundle] initial entry of assetic integration
121 }
Something went wrong with that request. Please try again.