Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 123 lines (103 sloc) 4.329 kB
d2536b6 @kriswallsmith [AsseticBundle] initial entry of assetic integration
kriswallsmith authored
1 <?php
2
3 /*
4 * This file is part of the Symfony framework.
5 *
7bca164 @fabpot replaced symfony-project.org by symfony.com
fabpot authored
6 * (c) Fabien Potencier <fabien@symfony.com>
d2536b6 @kriswallsmith [AsseticBundle] initial entry of assetic integration
kriswallsmith authored
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
4845c65 @kriswallsmith use spork to distribute dump across many procs
kriswallsmith authored
14 use Spork\Batch\Strategy\ChunkStrategy;
15 use Spork\EventDispatcher\WrappedEventDispatcher;
16 use Spork\ProcessManager;
33532c7 @kriswallsmith broke out assetic:watch command
kriswallsmith authored
17 use Symfony\Component\Console\Input\ArrayInput;
d2536b6 @kriswallsmith [AsseticBundle] initial entry of assetic integration
kriswallsmith authored
18 use Symfony\Component\Console\Input\InputArgument;
19 use Symfony\Component\Console\Input\InputInterface;
49ddc95 @kriswallsmith [AsseticBundle] added a --watch option to the assetic:dump command
kriswallsmith authored
20 use Symfony\Component\Console\Input\InputOption;
33532c7 @kriswallsmith broke out assetic:watch command
kriswallsmith authored
21 use Symfony\Component\Console\Output\ConsoleOutputInterface;
d2536b6 @kriswallsmith [AsseticBundle] initial entry of assetic integration
kriswallsmith authored
22 use Symfony\Component\Console\Output\OutputInterface;
23
24 /**
25 * Dumps assets to the filesystem.
26 *
0351324 @kriswallsmith updated my email address
kriswallsmith authored
27 * @author Kris Wallsmith <kris@symfony.com>
d2536b6 @kriswallsmith [AsseticBundle] initial entry of assetic integration
kriswallsmith authored
28 */
33532c7 @kriswallsmith broke out assetic:watch command
kriswallsmith authored
29 class DumpCommand extends AbstractCommand
d2536b6 @kriswallsmith [AsseticBundle] initial entry of assetic integration
kriswallsmith authored
30 {
4845c65 @kriswallsmith use spork to distribute dump across many procs
kriswallsmith authored
31 private $spork;
32
d2536b6 @kriswallsmith [AsseticBundle] initial entry of assetic integration
kriswallsmith authored
33 protected function configure()
34 {
35 $this
36 ->setName('assetic:dump')
37 ->setDescription('Dumps all assets to the filesystem')
98b9606 @kriswallsmith [AsseticBundle] separated read and write paths to facilitate writing …
kriswallsmith authored
38 ->addArgument('write_to', InputArgument::OPTIONAL, 'Override the configured asset root')
4845c65 @kriswallsmith use spork to distribute dump across many procs
kriswallsmith authored
39 ->addOption('forks', null, InputOption::VALUE_REQUIRED, 'Fork work across many processes (requires kriswallsmith/spork)')
33532c7 @kriswallsmith broke out assetic:watch command
kriswallsmith authored
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)
d2536b6 @kriswallsmith [AsseticBundle] initial entry of assetic integration
kriswallsmith authored
43 ;
44 }
45
4845c65 @kriswallsmith use spork to distribute dump across many procs
kriswallsmith authored
46 protected function initialize(InputInterface $input, OutputInterface $stdout)
47 {
48 if (null !== $input->getOption('forks')) {
9044feb @johnkary Throw Exception early if using --forks and missing spork library
johnkary authored
49 if (!class_exists('Spork\ProcessManager')) {
cfebc3e @johnkary More explicit in what exactly kriswallsmith/spork is
johnkary authored
50 throw new \RuntimeException('The --forks option requires that package kriswallsmith/spork be installed');
9044feb @johnkary Throw Exception early if using --forks and missing spork library
johnkary authored
51 }
52
4845c65 @kriswallsmith use spork to distribute dump across many procs
kriswallsmith authored
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')),
95c2079 @Soullivaneuh Fix kriswallsmith/spork ProcessManager::__construct signature change
Soullivaneuh authored
59 null,
4845c65 @kriswallsmith use spork to distribute dump across many procs
kriswallsmith authored
60 $this->getContainer()->getParameter('kernel.debug')
61 );
62 }
63
64 parent::initialize($input, $stdout);
65 }
66
33532c7 @kriswallsmith broke out assetic:watch command
kriswallsmith authored
67 protected function execute(InputInterface $input, OutputInterface $stdout)
10e1f2f @kriswallsmith [AsseticBundle] moved base path to object property
kriswallsmith authored
68 {
33532c7 @kriswallsmith broke out assetic:watch command
kriswallsmith authored
69 // capture error output
70 $stderr = $stdout instanceof ConsoleOutputInterface
71 ? $stdout->getErrorOutput()
72 : $stdout;
73
74 if ($input->getOption('watch')) {
4fed8c6 @Burgov Fixed fatal error after --watch was deprecated
Burgov authored
75 $stderr->writeln(
33532c7 @kriswallsmith broke out assetic:watch command
kriswallsmith authored
76 '<error>The --watch option is deprecated. Please use the '.
77 'assetic:watch command instead.</error>'
78 );
79
80 // build assetic:watch arguments
81 $arguments = array(
82 'command' => 'assetic:watch',
83 'write_to' => $this->basePath,
84 '--period' => $input->getOption('period'),
85 '--env' => $input->getOption('env'),
86 );
87
88 if ($input->getOption('no-debug')) {
89 $arguments['--no-debug'] = true;
279baf7 @kriswallsmith [AsseticBundle] rearranged execute() method
kriswallsmith authored
90 }
49ddc95 @kriswallsmith [AsseticBundle] added a --watch option to the assetic:dump command
kriswallsmith authored
91
33532c7 @kriswallsmith broke out assetic:watch command
kriswallsmith authored
92 if ($input->getOption('force')) {
93 $arguments['--force'] = true;
ef24188 @tgabi333 avoiding 100% proc usage and error handling when unserialization is u…
tgabi333 authored
94 }
49ddc95 @kriswallsmith [AsseticBundle] added a --watch option to the assetic:dump command
kriswallsmith authored
95
33532c7 @kriswallsmith broke out assetic:watch command
kriswallsmith authored
96 $command = $this->getApplication()->find('assetic:watch');
49ddc95 @kriswallsmith [AsseticBundle] added a --watch option to the assetic:dump command
kriswallsmith authored
97
33532c7 @kriswallsmith broke out assetic:watch command
kriswallsmith authored
98 return $command->run(new ArrayInput($arguments), $stdout);
49ddc95 @kriswallsmith [AsseticBundle] added a --watch option to the assetic:dump command
kriswallsmith authored
99 }
100
33532c7 @kriswallsmith broke out assetic:watch command
kriswallsmith authored
101 // print the header
102 $stdout->writeln(sprintf('Dumping all <comment>%s</comment> assets.', $input->getOption('env')));
103 $stdout->writeln(sprintf('Debug mode is <comment>%s</comment>.', $this->am->isDebug() ? 'on' : 'off'));
104 $stdout->writeln('');
49ddc95 @kriswallsmith [AsseticBundle] added a --watch option to the assetic:dump command
kriswallsmith authored
105
4845c65 @kriswallsmith use spork to distribute dump across many procs
kriswallsmith authored
106 if ($this->spork) {
107 $batch = $this->spork->createBatchJob(
108 $this->am->getNames(),
109 new ChunkStrategy($input->getOption('forks'))
110 );
111
112 $self = $this;
97a07a8 @stof Fixed CS
stof authored
113 $batch->execute(function ($name) use ($self, $stdout) {
4845c65 @kriswallsmith use spork to distribute dump across many procs
kriswallsmith authored
114 $self->dumpAsset($name, $stdout);
115 });
116 } else {
117 foreach ($this->am->getNames() as $name) {
118 $this->dumpAsset($name, $stdout);
119 }
49ddc95 @kriswallsmith [AsseticBundle] added a --watch option to the assetic:dump command
kriswallsmith authored
120 }
cfe439a @kriswallsmith cleaned up dump command
kriswallsmith authored
121 }
d2536b6 @kriswallsmith [AsseticBundle] initial entry of assetic integration
kriswallsmith authored
122 }
Something went wrong with that request. Please try again.