1 | <?php |
||
12 | class IncenteevParametersProcessor |
||
13 | { |
||
14 | private static $PARAMETER_KEY = null; |
||
15 | |||
16 | /** |
||
17 | * @var FileHandler |
||
18 | */ |
||
19 | private $fileHandler; |
||
20 | /** |
||
21 | * @var IOInterface |
||
22 | */ |
||
23 | private $io; |
||
24 | /** |
||
25 | * @var Filesystem |
||
26 | */ |
||
27 | private $fs; |
||
28 | |||
29 | /** |
||
30 | * IncenteevParametersProcessor constructor. |
||
31 | * @param Filesystem $fs |
||
32 | * @param FileHandler $fileHandler |
||
33 | * @param IOInterface $io |
||
34 | */ |
||
35 | public function __construct(Filesystem $fs, FileHandler $fileHandler, IOInterface $io) |
||
41 | |||
42 | /** |
||
43 | * @param $configs |
||
44 | * @param Event $event |
||
45 | * @return bool |
||
46 | */ |
||
47 | public function process($configs, Event $event) |
||
48 | { |
||
49 | if (!isset($configs['incenteev-parameters'])) { |
||
50 | return true; |
||
51 | } |
||
52 | |||
53 | $processor = new Processor($event->getIO()); |
||
54 | $parameters = $configs['incenteev-parameters']; |
||
55 | if (array_keys($parameters) !== range(0, count($parameters) - 1)) { |
||
56 | $parameters = array($parameters); |
||
57 | } |
||
58 | |||
59 | if (empty($parameters['parameter-key'])) { |
||
60 | self::$PARAMETER_KEY = 'parameters'; |
||
61 | } else { |
||
62 | self::$PARAMETER_KEY = $parameters['parameter-key']; |
||
63 | } |
||
64 | |||
65 | foreach ($parameters as $config) { |
||
66 | if (!is_array($config)) { |
||
67 | throw new \InvalidArgumentException('The extra.environment-parameters.incenteev-parameters setting must be an array of configuration objects.'); |
||
68 | } |
||
69 | |||
70 | $file = $this->fileHandler->findFile($config['file']); |
||
71 | |||
72 | $outputFileName = $this->fileHandler->preparePath($configs['build-folder'] . '/' . (isset($config['name']) ? $config['name'] : $file)); |
||
73 | $this->processFile($file, $outputFileName . '.dist'); |
||
74 | |||
75 | $config['dist-file'] = $outputFileName . '.dist'; |
||
76 | $config['file'] = $outputFileName; |
||
77 | $processor->processFile($config); |
||
78 | $this->fs->remove($outputFileName . '.dist'); |
||
79 | |||
80 | $this->updateCommentInFile($outputFileName); |
||
81 | } |
||
82 | |||
83 | return true; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @param $inFile |
||
88 | * @param null $outFile |
||
89 | * @param array $stack |
||
90 | * @return array|bool|mixed |
||
91 | */ |
||
92 | public function processFile($inFile, $outFile = null, array $stack = array()) |
||
123 | |||
124 | protected function updateCommentInFile($file) |
||
130 | |||
131 | protected function processEnvironmentalVariables(array $parameters) |
||
142 | } |
||
143 |