1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Cli\SimpleConfigurationLoader |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Cli; |
22
|
|
|
|
23
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
24
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
25
|
|
|
use TechDivision\Import\ConfigurationFactoryInterface; |
26
|
|
|
use TechDivision\Import\Cli\Command\InputOptionKeys; |
27
|
|
|
use TechDivision\Import\Cli\Configuration\LibraryLoader; |
28
|
|
|
use TechDivision\Import\Cli\Utils\DependencyInjectionKeys; |
29
|
|
|
use TechDivision\Import\Cli\Utils\MagentoConfigurationKeys; |
30
|
|
|
use TechDivision\Import\Utils\CommandNames; |
31
|
|
|
use TechDivision\Import\Utils\Mappings\CommandNameToEntityTypeCode; |
32
|
|
|
use TechDivision\Import\ConsoleOptionLoaderInterface; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The configuration loader implementation. |
36
|
|
|
* |
37
|
|
|
* @author Tim Wagner <[email protected]> |
38
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
39
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
40
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
41
|
|
|
* @link http://www.techdivision.com |
42
|
|
|
*/ |
43
|
|
|
class SimpleConfigurationLoader implements ConfigurationLoaderInterface |
44
|
|
|
{ |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The key for the Magento Edition in the metadata extracted from the Composer configuration. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
const EDITION = 'edition'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* The key for the Magento Version in the metadata extracted from the Composer configuration. |
55
|
|
|
* |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
const VERSION = 'version'; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* The container instance. |
62
|
|
|
* |
63
|
|
|
* @var \Symfony\Component\DependencyInjection\ContainerInterface |
64
|
|
|
*/ |
65
|
|
|
protected $container; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* The actual input instance. |
69
|
|
|
* |
70
|
|
|
* @var \Symfony\Component\Console\Input\InputInterface |
71
|
|
|
*/ |
72
|
|
|
protected $input; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* The library loader instance. |
76
|
|
|
* |
77
|
|
|
* @param \TechDivision\Import\Cli\LibraryLoader |
78
|
|
|
*/ |
79
|
|
|
protected $libraryLoader; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* The configuration factory instance. |
83
|
|
|
* |
84
|
|
|
* @var \TechDivision\Import\ConfigurationFactoryInterface |
85
|
|
|
*/ |
86
|
|
|
protected $configurationFactory; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* The available command names. |
90
|
|
|
* |
91
|
|
|
* @var \TechDivision\Import\Utils\CommandNames |
92
|
|
|
*/ |
93
|
|
|
protected $commandNames; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* The mapping of the command names to the entity type codes |
97
|
|
|
* |
98
|
|
|
* @var \TechDivision\Import\Utils\Mappings\CommandNameToEntityTypeCode |
99
|
|
|
*/ |
100
|
|
|
protected $commandNameToEntityTypeCode; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* The console option loader instance. |
104
|
|
|
* |
105
|
|
|
* @var \TechDivision\Import\ConsoleOptionLoaderInterface |
106
|
|
|
*/ |
107
|
|
|
protected $consoleOptionLoader; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Initializes the configuration loader. |
111
|
|
|
* |
112
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input The input instance |
113
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container The container instance |
114
|
|
|
* @param \TechDivision\Import\Cli\Configuration\LibraryLoader $libraryLoader The configuration loader instance |
115
|
|
|
* @param \TechDivision\Import\ConfigurationFactoryInterface $configurationFactory The configuration factory instance |
116
|
|
|
* @param \TechDivision\Import\Utils\CommandNames $commandNames The available command names |
117
|
|
|
* @param \TechDivision\Import\Utils\Mappings\CommandNameToEntityTypeCode $commandNameToEntityTypeCodes The mapping of the command names to the entity type codes |
118
|
|
|
* @param \TechDivision\Import\ConsoleOptionLoaderInterface $consoleOptionLoader The console option loader instance |
119
|
|
|
*/ |
120
|
|
|
public function __construct( |
121
|
|
|
InputInterface $input, |
122
|
|
|
ContainerInterface $container, |
123
|
|
|
LibraryLoader $libraryLoader, |
124
|
|
|
ConfigurationFactoryInterface $configurationFactory, |
125
|
|
|
CommandNames $commandNames, |
126
|
|
|
CommandNameToEntityTypeCode $commandNameToEntityTypeCodes, |
127
|
|
|
ConsoleOptionLoaderInterface $consoleOptionLoader |
128
|
|
|
) { |
129
|
|
|
|
130
|
|
|
// set the passed instances |
131
|
|
|
$this->input = $input; |
132
|
|
|
$this->container = $container; |
133
|
|
|
$this->libraryLoader = $libraryLoader; |
134
|
|
|
$this->configurationFactory = $configurationFactory; |
135
|
|
|
$this->commandNames = $commandNames; |
136
|
|
|
$this->commandNameToEntityTypeCode = $commandNameToEntityTypeCodes; |
137
|
|
|
$this->consoleOptionLoader = $consoleOptionLoader; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Factory implementation to create a new initialized configuration instance. |
142
|
|
|
* |
143
|
|
|
* If command line options are specified, they will always override the |
144
|
|
|
* values found in the configuration file. |
145
|
|
|
* |
146
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration instance |
147
|
|
|
*/ |
148
|
|
|
public function load() |
149
|
|
|
{ |
150
|
|
|
|
151
|
|
|
// initially try to create the configuration instance |
152
|
|
|
$instance = $this->createInstance(); |
153
|
|
|
|
154
|
|
|
// we have to set the entity type code at least |
155
|
|
|
$instance->setEntityTypeCode($this->getEntityTypeCode()); |
156
|
|
|
|
157
|
|
|
// load and merge the console options |
158
|
|
|
$this->getConsoleOptionLoader()->load($instance); |
159
|
|
|
|
160
|
|
|
// return the initialized configuration instance |
161
|
|
|
return $instance; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* This method create the configuration instance from the configuration file |
166
|
|
|
* defined by the commandline args and options. |
167
|
|
|
* |
168
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration instance loaded from the configuration file |
169
|
|
|
* @throws \Exception Is thrown, if the specified configuration file doesn't exist or the mandatory arguments/options to run the requested operation are not available |
170
|
|
|
*/ |
171
|
|
|
protected function createInstance() |
172
|
|
|
{ |
173
|
|
|
|
174
|
|
|
// load the actual vendor directory and entity type code |
175
|
|
|
$vendorDir = $this->getVendorDir(); |
176
|
|
|
|
177
|
|
|
// the path of the JMS serializer directory, relative to the vendor directory |
178
|
|
|
$jmsDir = DIRECTORY_SEPARATOR . 'jms' . DIRECTORY_SEPARATOR . 'serializer' . DIRECTORY_SEPARATOR . 'src'; |
179
|
|
|
|
180
|
|
|
// try to find the path to the JMS Serializer annotations |
181
|
|
|
if (!file_exists($annotationDir = $vendorDir . DIRECTORY_SEPARATOR . $jmsDir)) { |
182
|
|
|
// stop processing, if the JMS annotations can't be found |
183
|
|
|
throw new \Exception( |
184
|
|
|
sprintf( |
185
|
|
|
'The jms/serializer libarary can not be found in one of "%s"', |
186
|
|
|
implode(', ', $vendorDir) |
|
|
|
|
187
|
|
|
) |
188
|
|
|
); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
// register the autoloader for the JMS serializer annotations |
192
|
|
|
\Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace( |
|
|
|
|
193
|
|
|
'JMS\Serializer\Annotation', |
194
|
|
|
$annotationDir |
195
|
|
|
); |
196
|
|
|
|
197
|
|
|
// query whether or not, a configuration file has been specified |
198
|
|
|
if ($configuration = $this->input->getOption(InputOptionKeys::CONFIGURATION)) { |
199
|
|
|
// load the configuration from the file with the given filename |
200
|
|
|
$instance = $this->createConfiguration($configuration); |
201
|
|
|
// set the actual command name in the configuration |
202
|
|
|
$instance->setCommandName($this->input->getFirstArgument()); |
203
|
|
|
// return the instance |
204
|
|
|
return $instance; |
205
|
|
|
} elseif (($magentoEdition = $this->input->getOption(InputOptionKeys::MAGENTO_EDITION)) && ($magentoVersion = $this->input->getOption(InputOptionKeys::MAGENTO_VERSION))) { |
206
|
|
|
// use the Magento Edition that has been specified as option |
207
|
|
|
$instance = $this->createConfiguration(); |
208
|
|
|
|
209
|
|
|
// override the Magento Edition/Version |
210
|
|
|
$instance->setMagentoEdition($magentoEdition); |
211
|
|
|
$instance->setMagentoVersion($magentoVersion); |
212
|
|
|
|
213
|
|
|
// set the actual command name in the configuration |
214
|
|
|
$instance->setCommandName($this->input->getFirstArgument()); |
215
|
|
|
|
216
|
|
|
// return the instance |
217
|
|
|
return $instance; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
// finally, query whether or not the installation directory is a valid Magento root directory |
221
|
|
|
if (!$this->isMagentoRootDir($installationDir = $this->input->getOption(InputOptionKeys::INSTALLATION_DIR))) { |
|
|
|
|
222
|
|
|
throw new \Exception( |
223
|
|
|
sprintf( |
224
|
|
|
'Directory "%s" is not a valid Magento root directory, please use option "--installation-dir" to specify it', |
225
|
|
|
$installationDir |
|
|
|
|
226
|
|
|
) |
227
|
|
|
); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
// use the Magento Edition that has been detected by the installation directory |
231
|
|
|
$instance = $this->createConfiguration(); |
232
|
|
|
|
233
|
|
|
// load the Magento Edition from the Composer configuration file |
234
|
|
|
$metadata = $this->getEditionMapping($installationDir); |
|
|
|
|
235
|
|
|
|
236
|
|
|
// extract edition & version from the metadata |
237
|
|
|
$magentoEdition = $metadata[SimpleConfigurationLoader::EDITION]; |
238
|
|
|
$magentoVersion = $metadata[SimpleConfigurationLoader::VERSION]; |
239
|
|
|
|
240
|
|
|
// override the Magento Edition/Version |
241
|
|
|
$instance->setMagentoEdition($magentoEdition); |
242
|
|
|
$instance->setMagentoVersion($magentoVersion); |
243
|
|
|
|
244
|
|
|
// set the actual command name in the configuration |
245
|
|
|
$instance->setCommandName($this->input->getFirstArgument()); |
246
|
|
|
|
247
|
|
|
// return the instance |
248
|
|
|
return $instance; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Create and return a new configuration instance from the passed configuration filename |
253
|
|
|
* after merging additional specified params from the commandline. |
254
|
|
|
* |
255
|
|
|
* @param string|null $filename The configuration filename to use |
256
|
|
|
* |
257
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration instance |
258
|
|
|
*/ |
259
|
|
|
protected function createConfiguration($filename = null) |
260
|
|
|
{ |
261
|
|
|
|
262
|
|
|
// initialize the params specified with the --params parameter |
263
|
|
|
$params = null; |
264
|
|
|
|
265
|
|
|
// try to load the params from the commandline |
266
|
|
|
if ($this->input->hasOptionSpecified(InputOptionKeys::PARAMS) && $this->input->getOption(InputOptionKeys::PARAMS)) { |
|
|
|
|
267
|
|
|
$params = $this->input->getOption(InputOptionKeys::PARAMS); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
// initialize the params file specified with the --params-file parameter |
271
|
|
|
$paramsFile = null; |
272
|
|
|
|
273
|
|
|
// try to load the path of the params file from the commandline |
274
|
|
|
if ($this->input->hasOptionSpecified(InputOptionKeys::PARAMS_FILE) && $this->input->getOption(InputOptionKeys::PARAMS_FILE)) { |
275
|
|
|
$paramsFile = $this->input->getOption(InputOptionKeys::PARAMS_FILE); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
// if a filename has been passed, try to load the configuration from the file |
279
|
|
|
if (is_file($filename)) { |
280
|
|
|
return $this->configurationFactory->factory($filename, pathinfo($filename, PATHINFO_EXTENSION), $params, $paramsFile); |
|
|
|
|
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
// initialize the array for the directories |
284
|
|
|
$directories = array(); |
285
|
|
|
|
286
|
|
|
// set the default file format |
287
|
|
|
$format = 'json'; |
288
|
|
|
|
289
|
|
|
// load the actual vendor directory and entity type code |
290
|
|
|
$vendorDir = $this->getVendorDir(); |
291
|
|
|
|
292
|
|
|
// load the default configuration directory from the DI configuration |
293
|
|
|
$defaultConfigurationDirectory = $this->getContainer()->getParameter(DependencyInjectionKeys::APPLICATION_DEFAULT_CONFIGURATION_DIR); |
294
|
|
|
|
295
|
|
|
// load the directories that has to be parsed for configuration files1 |
296
|
|
|
foreach ($this->getDefaultLibraries() as $defaultLibrary) { |
297
|
|
|
// initialize the directory name |
298
|
|
|
$directory = implode( |
299
|
|
|
DIRECTORY_SEPARATOR, |
300
|
|
|
array_merge( |
301
|
|
|
array($vendorDir), |
302
|
|
|
explode('/', $defaultLibrary), |
303
|
|
|
explode('/', $defaultConfigurationDirectory) |
304
|
|
|
) |
305
|
|
|
); |
306
|
|
|
|
307
|
|
|
// query whether or not the directory is available1 |
308
|
|
|
if (is_dir($directory)) { |
309
|
|
|
$directories[] = $directory; |
310
|
|
|
} |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
// initialize the default custom configuration directory |
314
|
|
|
$customConfigurationDirectory = implode( |
315
|
|
|
DIRECTORY_SEPARATOR, |
316
|
|
|
array_merge( |
317
|
|
|
array(getcwd()), |
318
|
|
|
explode('/', $this->getContainer()->getParameter(DependencyInjectionKeys::APPLICATION_CUSTOM_CONFIGURATION_DIR)) |
319
|
|
|
) |
320
|
|
|
); |
321
|
|
|
|
322
|
|
|
// query whether or not a custom configuration directory has been speified, if yes override the default one |
323
|
|
|
if ($this->input->hasOptionSpecified(InputOptionKeys::CUSTOM_CONFIGURATION_DIR) && $this->input->getOption(InputOptionKeys::CUSTOM_CONFIGURATION_DIR)) { |
324
|
|
|
$customConfigurationDirectory = $this->input->getOption(InputOptionKeys::CUSTOM_CONFIGURATION_DIR); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
// specify the default directory for custom configuration files |
328
|
|
|
if (is_dir($customConfigurationDirectory)) { |
|
|
|
|
329
|
|
|
$directories[] = $customConfigurationDirectory; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
// load and return the configuration from the files found in the passed directories |
333
|
|
|
$instance = $this->configurationFactory->factoryFromDirectories($directories, $format, $params, $paramsFile); |
|
|
|
|
334
|
|
|
|
335
|
|
|
// query whether or not we've an valid Magento root directory specified |
336
|
|
|
if ($this->isMagentoRootDir($installationDir = $this->input->getOption(InputOptionKeys::INSTALLATION_DIR))) { |
|
|
|
|
337
|
|
|
// add the source directory if NOT specified in the configuration file |
338
|
|
|
if (($sourceDir = $instance->getSourceDir()) === null) { |
339
|
|
|
$instance->setSourceDir($sourceDir = sprintf('%s/var/importexport', $installationDir)); |
|
|
|
|
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
// add the target directory if NOT specified in the configuration file |
343
|
|
|
if ($instance->getTargetDir() === null) { |
344
|
|
|
$instance->setTargetDir($sourceDir); |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
return $instance; |
|
|
|
|
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* Return's the DI container instance. |
353
|
|
|
* |
354
|
|
|
* @return \Symfony\Component\DependencyInjection\ContainerInterface The DI container instance |
355
|
|
|
*/ |
356
|
|
|
protected function getContainer() |
357
|
|
|
{ |
358
|
|
|
return $this->container; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* The console option loader instance. |
363
|
|
|
* |
364
|
|
|
* @return \TechDivision\Import\ConsoleOptionLoaderInterface The instance |
365
|
|
|
*/ |
366
|
|
|
protected function getConsoleOptionLoader() |
367
|
|
|
{ |
368
|
|
|
return $this->consoleOptionLoader; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Return's the absolute path to the actual vendor directory. |
373
|
|
|
* |
374
|
|
|
* @return string The absolute path to the actual vendor directory |
375
|
|
|
* @throws \Exception Is thrown, if none of the possible vendor directories can be found |
376
|
|
|
*/ |
377
|
|
|
protected function getVendorDir() |
378
|
|
|
{ |
379
|
|
|
return $this->getContainer()->getParameter(DependencyInjectionKeys::CONFIGURATION_VENDOR_DIR); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* Return's the actual command name. |
384
|
|
|
* |
385
|
|
|
* @return string The actual command name |
386
|
|
|
*/ |
387
|
|
|
protected function getCommandName() |
388
|
|
|
{ |
389
|
|
|
return $this->input->getArgument('command'); |
|
|
|
|
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Return's the command's entity type code. |
394
|
|
|
* |
395
|
|
|
* @return string The command's entity type code |
396
|
|
|
* @throws \Exception Is thrown, if the command name can not be mapped |
397
|
|
|
*/ |
398
|
|
|
protected function getEntityTypeCode() |
399
|
|
|
{ |
400
|
|
|
|
401
|
|
|
// try to map the command name to a entity type code |
402
|
|
|
if (array_key_exists($commandName = $this->getCommandName(), (array) $this->commandNameToEntityTypeCode)) { |
403
|
|
|
return $this->commandNameToEntityTypeCode[$commandName]; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
// throw an exception if not possible |
407
|
|
|
throw new \Exception(sprintf('Can\'t map command name %s to a entity type', $commandName)); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Returns the mapped Magento Edition from the passed Magento installation. |
412
|
|
|
* |
413
|
|
|
* @param string $installationDir The Magento installation directory |
414
|
|
|
* |
415
|
|
|
* @return array The array with the mapped Magento Edition (either CE or EE) + the Version |
416
|
|
|
* @throws \Exception Is thrown, if the passed installation directory doesn't contain a valid Magento installation |
417
|
|
|
*/ |
418
|
|
|
protected function getEditionMapping($installationDir) |
419
|
|
|
{ |
420
|
|
|
|
421
|
|
|
// load the default edition mappings from the configuration |
422
|
|
|
$editionMappings = $this->getContainer()->getParameter(DependencyInjectionKeys::APPLICATION_EDITION_MAPPINGS); |
423
|
|
|
|
424
|
|
|
// load the composer file from the Magento root directory |
425
|
|
|
$composer = json_decode(file_get_contents($composerFile = sprintf('%s/composer.json', $installationDir)), true); |
426
|
|
|
|
427
|
|
|
// try to load and explode the Magento Edition identifier from the Composer name |
428
|
|
|
$explodedEdition = explode('/', $composer[MagentoConfigurationKeys::COMPOSER_EDITION_NAME_ATTRIBUTE]); |
429
|
|
|
|
430
|
|
|
// try to load and explode the Magento Edition from the Composer configuration |
431
|
|
|
if (!isset($editionMappings[$possibleEdition = end($explodedEdition)])) { |
432
|
|
|
throw new \Exception( |
433
|
|
|
sprintf( |
434
|
|
|
'"%s" detected in "%s" is not a valid Magento Edition, please set Magento Edition with the "--magento-edition" option', |
435
|
|
|
$possibleEdition, |
436
|
|
|
$composerFile |
437
|
|
|
) |
438
|
|
|
); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
// try to load and explode the Magento Version from the Composer configuration |
442
|
|
|
if (!isset($composer[MagentoConfigurationKeys::COMPOSER_EDITION_VERSION_ATTRIBUTE])) { |
443
|
|
|
throw new \Exception( |
444
|
|
|
sprintf( |
445
|
|
|
'Can\'t detect a version in "%s", please set Magento Version with the "--magento-version" option', |
446
|
|
|
$composerFile |
447
|
|
|
) |
448
|
|
|
); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
// return the array with the Magento Version/Edition data |
452
|
|
|
return array( |
453
|
|
|
SimpleConfigurationLoader::VERSION => $composer[MagentoConfigurationKeys::COMPOSER_EDITION_VERSION_ATTRIBUTE], |
454
|
|
|
SimpleConfigurationLoader::EDITION => $editionMappings[$possibleEdition] |
455
|
|
|
); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* Return's the application's default libraries. |
461
|
|
|
* |
462
|
|
|
* @return array The default libraries |
463
|
|
|
*/ |
464
|
|
|
protected function getDefaultLibraries() |
465
|
|
|
{ |
466
|
|
|
|
467
|
|
|
// load the default libraries from the configuration |
468
|
|
|
$defaultLibraries = $this->getContainer()->getParameter(DependencyInjectionKeys::APPLICATION_DEFAULT_LIBRARIES); |
469
|
|
|
|
470
|
|
|
// initialize the array for the libraries |
471
|
|
|
$libraries = array(); |
472
|
|
|
|
473
|
|
|
// append each library only ONCE |
474
|
|
|
foreach ($defaultLibraries as $libraries) { |
475
|
|
|
foreach ($libraries as $library) { |
476
|
|
|
if (in_array($library, $libraries)) { |
477
|
|
|
continue; |
478
|
|
|
} |
479
|
|
|
// append the library |
480
|
|
|
$libraries[] = $library; |
481
|
|
|
} |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
// return the array with the libraries |
485
|
|
|
return $libraries; |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
/** |
489
|
|
|
* Query whether or not, the passed directory is a Magento root directory. |
490
|
|
|
* |
491
|
|
|
* @param string $dir The directory to query |
492
|
|
|
* |
493
|
|
|
* @return boolean TRUE if the directory is a Magento root directory, else FALSE |
494
|
|
|
*/ |
495
|
|
|
protected function isMagentoRootDir($dir) |
496
|
|
|
{ |
497
|
|
|
return is_file($this->getMagentoEnv($dir)); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* Return's the path to the Magento file with the environment configuration. |
502
|
|
|
* |
503
|
|
|
* @param string $dir The path to the Magento root directory |
504
|
|
|
* |
505
|
|
|
* @return string The path to the Magento file with the environment configuration |
506
|
|
|
*/ |
507
|
|
|
protected function getMagentoEnv($dir) |
508
|
|
|
{ |
509
|
|
|
return sprintf('%s/app/etc/env.php', $dir); |
510
|
|
|
} |
511
|
|
|
} |
512
|
|
|
|