|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JK\SamBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use JK\Sam\Filter\FilterBuilder; |
|
7
|
|
|
use JK\Sam\Filter\FilterInterface; |
|
8
|
|
|
use JK\Sam\Task\Task; |
|
9
|
|
|
use JK\Sam\Task\TaskBuilder; |
|
10
|
|
|
use Symfony\Component\Console\Command\Command; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
15
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
16
|
|
|
|
|
17
|
|
|
abstract class AbstractAssetsCommand extends Command implements ContainerAwareInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var SymfonyStyle |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $io; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var boolean |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $debug = false; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var ContainerInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $container; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param InputInterface $input |
|
36
|
|
|
* |
|
37
|
|
|
* @return Task[] |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function buildTasks(InputInterface $input) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->io->text('- Building tasks...'); |
|
42
|
|
|
$builder = new TaskBuilder($this->debug); |
|
43
|
|
|
|
|
44
|
|
|
$configuration = $this->loadConfiguration($input); |
|
45
|
|
|
$tasks = $builder->build($configuration); |
|
46
|
|
|
|
|
47
|
|
|
$this->io->text('- Tasks build !'); |
|
48
|
|
|
$this->io->newLine(); |
|
49
|
|
|
|
|
50
|
|
|
return $tasks; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param InputInterface $input |
|
55
|
|
|
* |
|
56
|
|
|
* @return string[] |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function loadConfiguration(InputInterface $input) |
|
59
|
|
|
{ |
|
60
|
|
|
if ($input->hasOption('config') && $input->getOption('config')) { |
|
61
|
|
|
$configuration = $this->loadConfigurationFile($input->getOption('config')); |
|
62
|
|
|
} else { |
|
63
|
|
|
$configuration = $this |
|
64
|
|
|
->container |
|
65
|
|
|
->getParameter('jk.assets.tasks'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $configuration; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param $configurationFile |
|
73
|
|
|
* |
|
74
|
|
|
* @return string[] |
|
75
|
|
|
* |
|
76
|
|
|
* @throws Exception |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function loadConfigurationFile($configurationFile) |
|
79
|
|
|
{ |
|
80
|
|
|
if (!file_exists($configurationFile)) { |
|
81
|
|
|
throw new Exception('The configuration yml file '.$configurationFile.' was not found'); |
|
82
|
|
|
} |
|
83
|
|
|
$configuration = Yaml::parse(file_get_contents($configurationFile)); |
|
84
|
|
|
|
|
85
|
|
|
if (empty($configuration['jk_assets']['tasks'])) { |
|
86
|
|
|
throw new Exception('Tasks not found in configuration file '.$configurationFile); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return $configuration['jk_assets']['tasks']; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return FilterInterface[] |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function buildFilters() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->io->text('- Building filters...'); |
|
98
|
|
|
$builder = new FilterBuilder($this->container->get('event_dispatcher')); |
|
99
|
|
|
$filters = $builder->build( |
|
100
|
|
|
$this |
|
101
|
|
|
->container |
|
102
|
|
|
->getParameter('jk.assets.filters') |
|
103
|
|
|
); |
|
104
|
|
|
$this->io->text('- Filters build !'); |
|
105
|
|
|
$this->io->newLine(); |
|
106
|
|
|
|
|
107
|
|
|
return $filters; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Sets the container. |
|
112
|
|
|
* |
|
113
|
|
|
* @param ContainerInterface|null $container A ContainerInterface instance or null |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setContainer(ContainerInterface $container = null) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->container = $container; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|