Completed
Push — master ( 796be0...ac8dfd )
by Tim
11s
created

ConfigurationLoader::getMagentoDbConnection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
ccs 0
cts 14
cp 0
cc 2
eloc 10
nc 2
nop 2
crap 6
1
<?php
2
3
/**
4
 * TechDivision\Import\Cli\ConfigurationLoader
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 Psr\Log\LogLevel;
24
use Rhumsaa\Uuid\Uuid;
25
use TechDivision\Import\App\Simple;
26
use Symfony\Component\Console\Input\InputInterface;
27
use TechDivision\Import\Utils\EntityTypeCodes;
28
use TechDivision\Import\Cli\Command\InputOptionKeys;
29
use TechDivision\Import\Cli\Command\InputArgumentKeys;
30
use TechDivision\Import\Cli\Utils\MagentoConfigurationKeys;
31
use TechDivision\Import\Configuration\Jms\Configuration\Database;
32
33
/**
34
 * The configuration factory implementation.
35
 *
36
 * @author    Tim Wagner <[email protected]>
37
 * @copyright 2016 TechDivision GmbH <[email protected]>
38
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
39
 * @link      https://github.com/techdivision/import-cli-simple
40
 * @link      http://www.techdivision.com
41
 */
42
class ConfigurationLoader
43
{
44
45
    /**
46
     * The composer name => Magento Edition mappings.
47
     *
48
     * @var array
49
     */
50
    protected $editionMappings = array(
51
        'magento2ce'                 => 'CE',
52
        'project-community-edition'  => 'CE',
53
        'magento2ee'                 => 'EE',
54
        'project-enterprise-edition' => 'EE'
55
    );
56
57
    /**
58
     * The array with the default entity type code => import directory mappings.
59
     *
60
     * @var array
61
     */
62
    protected $defaultDirectories = array(
63
        EntityTypeCodes::CATALOG_PRODUCT  => 'products',
64
        EntityTypeCodes::CATALOG_CATEGORY => 'categories',
65
        EntityTypeCodes::EAV_ATTRIBUTE    => 'attributes'
66
    );
67
68
    /**
69
     * The array with the default entity type => configuration mapping.
70
     *
71
     * @var array
72
     */
73
    protected $defaultConfigurations = array(
74
        'ce' => array(
75
            EntityTypeCodes::EAV_ATTRIBUTE    => 'techdivision/import-attribute',
76
            EntityTypeCodes::CATALOG_PRODUCT  => 'techdivision/import-product',
77
            EntityTypeCodes::CATALOG_CATEGORY => 'techdivision/import-category'
78
        ),
79
        'ee' => array(
80
            EntityTypeCodes::EAV_ATTRIBUTE    => 'techdivision/import-attribute',
81
            EntityTypeCodes::CATALOG_PRODUCT  => 'techdivision/import-product-ee',
82
            EntityTypeCodes::CATALOG_CATEGORY => 'techdivision/import-category-ee'
83
        )
84
    );
85
86
    /**
87
     * The Magento Edition specific default libraries.
88
     *
89
     * @var array
90
     */
91
    protected $defaultLibraries = array(
92
        'ce' => array(
93
            'techdivision/import-app-simple',
94
            'techdivision/import',
95
            'techdivision/import-attribute',
96
            'techdivision/import-category',
97
            'techdivision/import-product',
98
            'techdivision/import-product-bundle',
99
            'techdivision/import-product-link',
100
            'techdivision/import-product-media',
101
            'techdivision/import-product-variant'
102
        ),
103
        'ee' => array(
104
            'techdivision/import-app-simple',
105
            'techdivision/import',
106
            'techdivision/import-ee',
107
            'techdivision/import-attribute',
108
            'techdivision/import-category',
109
            'techdivision/import-category-ee',
110
            'techdivision/import-product',
111
            'techdivision/import-product-ee',
112
            'techdivision/import-product-bundle',
113
            'techdivision/import-product-bundle-ee',
114
            'techdivision/import-product-link',
115
            'techdivision/import-product-link-ee',
116
            'techdivision/import-product-media',
117
            'techdivision/import-product-media-ee',
118
            'techdivision/import-product-variant',
119
            'techdivision/import-product-variant-ee'
120
        )
121
    );
122
123
    protected $configurationClassName;
124
125
    /**
126
     * The vendor directory used to load the default configuration files from.
127
     *
128
     * @var string
129
     */
130
    protected $vendorDir;
131
132
    /**
133
     * Initializes the configuration loader with the configuration factory class name.
134
     *
135
     * @param string $vendorDir                 The vendor directory
136
     * @param string $configurationFactoryClass The configuration factory class name
137
     */
138
    public function __construct($vendorDir, $configurationFactoryClass)
139
    {
140
        $this->vendorDir = $vendorDir;
141
        $this->configurationFactoryClass = $configurationFactoryClass;
0 ignored issues
show
Bug introduced by
The property configurationFactoryClass does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
142
    }
143
144
    /**
145
     * Return's the vendor directory used to load the default configuration files from.
146
     *
147
     * @return string The vendor directory
148
     */
149
    public function getVendorDir()
150
    {
151
        return $this->vendorDir;
152
    }
153
154
    /**
155
     * The configuration factory class name.
156
     *
157
     * @return string The configuration factory class name
158
     */
159
    public function getConfigurationFactoryClass()
160
    {
161
        return $this->configurationFactoryClass;
162
    }
163
164
    /**
165
     * Factory implementation to create a new initialized configuration instance.
166
     *
167
     * If command line options are specified, they will always override the
168
     * values found in the configuration file.
169
     *
170
     * @param \Symfony\Component\Console\Input\InputInterface $input          The Symfony console input instance
171
     * @param string                                          $entityTypeCode The entity type code to use
172
     *
173
     * @return \TechDivision\Import\Cli\Configuration The configuration instance
174
     * @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
175
     */
176
    public function load(InputInterface $input, $entityTypeCode)
177
    {
178
179
        // load the configuration factory class name
180
        $configurationFactoryClass = $this->getConfigurationFactoryClass();
181
182
        // query whether or not, a configuration file has been specified
183
        if ($configuration = $input->getOption(InputOptionKeys::CONFIGURATION)) {
184
            // load the configuration from the file with the given filename
185
            $instance = $configurationFactoryClass::factory($configuration);
186
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
187
        } elseif ($magentoEdition = $input->getOption(InputOptionKeys::MAGENTO_EDITION)) {
188
            // use the Magento Edition that has been specified as option
189
            $instance = $configurationFactoryClass::factory($this->getDefaultConfiguration($magentoEdition, $entityTypeCode));
190
191
            // override the Magento Edition
192
            $instance->setMagentoEdition($magentoEdition);
193
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
194
        } else {
195
            // finally, query whether or not the installation directory is a valid Magento root directory
196
            if (!$this->isMagentoRootDir($installationDir = $input->getOption(InputOptionKeys::INSTALLATION_DIR))) {
197
                throw new \Exception(
198
                    sprintf(
199
                        'Directory "%s" specified with option "--installation-dir" is not a valid Magento root directory',
200
                        $installationDir
201
                    )
202
                );
203
            }
204
205
            // load the composer file from the Magento root directory
206
            $composer = json_decode(file_get_contents($composerFile = sprintf('%s/composer.json', $installationDir)), true);
207
208
            // try to load and explode the Magento Edition identifier from the Composer name
209
            $explodedVersion = explode('/', $composer[MagentoConfigurationKeys::COMPOSER_EDITION_NAME_ATTRIBUTE]);
210
211
            // try to locate Magento Edition
212
            if (!isset($this->editionMappings[$possibleEdition = end($explodedVersion)])) {
213
                throw new \Exception(
214
                    sprintf(
215
                        '"%s" detected in "%s" is not a valid Magento Edition, please set Magento Edition with the "--magento-edition" option',
216
                        $possibleEdition,
217
                        $composerFile
218
                    )
219
                );
220
            }
221
222
            // if Magento Edition/Version are available, load them
223
            $magentoEdition = $this->editionMappings[$possibleEdition];
224
225
            // use the Magento Edition that has been detected by the installation directory
226
            $instance = $configurationFactoryClass::factory($this->getDefaultConfiguration($magentoEdition, $entityTypeCode));
227
228
            // override the Magento Edition, if NOT explicitly specified
229
            $instance->setMagentoEdition($magentoEdition);
230
        }
231
232
        // query whether or not an operation name has been specified as command line
233
        // option, if yes override the value from the configuration file
234
        if ($operationName = $input->getArgument(InputArgumentKeys::OPERATION_NAME)) {
235
            $instance->setOperationName($operationName);
236
        }
237
238
        // query whether or not a system name has been specified as command line
239
        // option, if yes override the value from the configuration file
240 View Code Duplication
        if (($input->hasOptionSpecified(InputOptionKeys::SYSTEM_NAME) && $input->getOption(InputOptionKeys::SYSTEM_NAME)) ||
0 ignored issues
show
Bug introduced by
The method hasOptionSpecified() does not exist on Symfony\Component\Console\Input\InputInterface. Did you maybe mean hasOption()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
241
            $instance->getSystemName() === null
242
        ) {
243
            $instance->setSystemName($input->getOption(InputOptionKeys::SYSTEM_NAME));
244
        }
245
246
        // query whether or not a PID filename has been specified as command line
247
        // option, if yes override the value from the configuration file
248 View Code Duplication
        if (($input->hasOptionSpecified(InputOptionKeys::PID_FILENAME) && $input->getOption(InputOptionKeys::PID_FILENAME)) ||
0 ignored issues
show
Bug introduced by
The method hasOptionSpecified() does not exist on Symfony\Component\Console\Input\InputInterface. Did you maybe mean hasOption()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
249
            $instance->getPidFilename() === null
250
        ) {
251
            $instance->setPidFilename($input->getOption(InputOptionKeys::PID_FILENAME));
252
        }
253
254
        // query whether or not a Magento installation directory has been specified as command line
255
        // option, if yes override the value from the configuration file
256 View Code Duplication
        if (($input->hasOptionSpecified(InputOptionKeys::INSTALLATION_DIR) && $input->getOption(InputOptionKeys::INSTALLATION_DIR)) ||
0 ignored issues
show
Bug introduced by
The method hasOptionSpecified() does not exist on Symfony\Component\Console\Input\InputInterface. Did you maybe mean hasOption()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
257
            $instance->getInstallationDir() === null
258
        ) {
259
            $instance->setInstallationDir($input->getOption(InputOptionKeys::INSTALLATION_DIR));
260
        }
261
262
        // query whether or not a Magento edition has been specified as command line
263
        // option, if yes override the value from the configuration file
264
        if ($magentoEdition = $input->getOption(InputOptionKeys::MAGENTO_EDITION)) {
265
            $instance->setMagentoEdition($magentoEdition);
266
        }
267
268
        // query whether or not a Magento version has been specified as command line
269
        // option, if yes override the value from the configuration file
270
        if ($magentoVersion = $input->getOption(InputOptionKeys::MAGENTO_VERSION)) {
271
            $instance->setMagentoVersion($magentoVersion);
272
        }
273
274
        // query whether or not a directory for the source files has been specified as command line
275
        // option, if yes override the value from the configuration file
276
        if ($sourceDir = $input->getOption(InputOptionKeys::SOURCE_DIR)) {
277
            $instance->setSourceDir($sourceDir);
278
        }
279
280
        // query whether or not a directory containing the imported files has been specified as command line
281
        // option, if yes override the value from the configuration file
282
        if ($targetDir = $input->getOption(InputOptionKeys::TARGET_DIR)) {
283
            $instance->setTargetDir($targetDir);
284
        }
285
286
        // query whether or not a source date format has been specified as command
287
        // line  option, if yes override the value from the configuration file
288
        if ($sourceDateFormat = $input->getOption(InputOptionKeys::SOURCE_DATE_FORMAT)) {
289
            $instance->setSourceDateFormat($sourceDateFormat);
290
        }
291
292
        // query whether or not the debug mode has been specified as command line
293
        // option, if yes override the value from the configuration file
294
        if ($debugMode = $input->getOption(InputOptionKeys::DEBUG_MODE)) {
295
            $instance->setDebugMode($instance->mapBoolean($debugMode));
296
        }
297
298
        // query whether or not the log level has been specified as command line
299
        // option, if yes override the value from the configuration file
300
        if ($logLevel = $input->getOption(InputOptionKeys::LOG_LEVEL)) {
301
            $instance->setLogLevel($logLevel);
302
        }
303
304
        // query whether or not we've an valid Magento root directory specified
305
        if ($this->isMagentoRootDir($installationDir = $instance->getInstallationDir())) {
306
            // if yes, add the database configuration
307
            $instance->addDatabase($this->getMagentoDbConnection($installationDir));
308
309
            // add the source directory if NOT specified in the configuration file
310
            if ($instance->getSourceDir() === null) {
311
                $instance->setSourceDir($sourceDir = sprintf('%s/var/importexport', $installationDir));
312
            }
313
314
            // add the target directory if NOT specified in the configuration file
315
            if ($instance->getTargetDir() === null) {
316
                $instance->setTargetDir($sourceDir);
317
            }
318
        }
319
320
        // query whether or not a DB ID has been specified as command line
321
        // option, if yes override the value from the configuration file
322
        if ($useDbId = $input->getOption(InputOptionKeys::USE_DB_ID)) {
323
            $instance->setUseDbId($useDbId);
324
        } else {
325
            // query whether or not a PDO DSN has been specified as command line
326
            // option, if yes override the value from the configuration file
327
            if ($dsn = $input->getOption(InputOptionKeys::DB_PDO_DSN)) {
328
                // first REMOVE all other database configurations
329
                $instance->clearDatabases();
330
331
                // add the database configuration
332
                $instance->addDatabase(
333
                    $this->newDatabaseConfiguration(
334
                        $dsn,
335
                        $input->getOption(InputOptionKeys::DB_USERNAME),
336
                        $input->getOption(InputOptionKeys::DB_PASSWORD)
337
                    )
338
                );
339
            }
340
        }
341
342
        // extend the plugins with the main configuration instance
343
        /** @var \TechDivision\Import\Cli\Configuration\Subject $subject */
344
        foreach ($instance->getPlugins() as $plugin) {
345
            // set the configuration instance on the plugin
346
            $plugin->setConfiguration($instance);
347
348
            // query whether or not the plugin has subjects configured
349
            if ($subjects = $plugin->getSubjects()) {
350
                // extend the plugin's subjects with the main configuration instance
351
                /** @var \TechDivision\Import\Cli\Configuration\Subject $subject */
352
                foreach ($subjects as $subject) {
353
                    // set the configuration instance on the subject
354
                    $subject->setConfiguration($instance);
355
                }
356
            }
357
        }
358
359
        // query whether or not the debug mode is enabled and log level
360
        // has NOT been overwritten with a commandline option
361
        if ($instance->isDebugMode() && !$input->getOption(InputOptionKeys::LOG_LEVEL)) {
362
            // set debug log level, if log level has NOT been overwritten on command line
363
            $instance->setLogLevel(LogLevel::DEBUG);
364
        }
365
366
        // prepend the array with the Magento Edition specific core libraries
367
        $instance->setExtensionLibraries(
368
            array_merge(
369
                $this->getDefaultLibraries($instance->getMagentoEdition()),
370
                $instance->getExtensionLibraries()
371
            )
372
        );
373
374
        // return the initialized configuration instance
375
        return $instance;
376
    }
377
378
    /**
379
     * Query whether or not, the passed directory is a Magento root directory.
380
     *
381
     * @param string $dir The directory to query
382
     *
383
     * @return boolean TRUE if the directory is a Magento root directory, else FALSE
384
     */
385
    public function isMagentoRootDir($dir)
386
    {
387
        return is_file($this->getMagentoEnv($dir));
388
    }
389
390
    /**
391
     * Return's the path to the Magento file with the environment configuration.
392
     *
393
     * @param string $dir The path to the Magento root directory
394
     *
395
     * @return string The path to the Magento file with the environment configuration
396
     */
397
    public function getMagentoEnv($dir)
398
    {
399
        return sprintf('%s/app/etc/env.php', $dir);
400
    }
401
402
    /**
403
     * Return's the requested Magento DB connction data.
404
     *
405
     * @param string $dir            The path to the Magento root directory
406
     * @param string $connectionName The connection name to return the data for
407
     *
408
     * @return array The connection data
409
     * @throws \Exception Is thrown, if the requested DB connection is not available
410
     */
411
    public function getMagentoDbConnection($dir, $connectionName = 'default')
412
    {
413
414
        // load the magento environment
415
        $env = require $this->getMagentoEnv($dir);
416
417
        // query whether or not, the requested connection is available
418
        if (isset($env[MagentoConfigurationKeys::DB][MagentoConfigurationKeys::CONNECTION][$connectionName])) {
419
            // load the connection data
420
            $connection = $env[MagentoConfigurationKeys::DB][MagentoConfigurationKeys::CONNECTION][$connectionName];
421
422
            // create and return a new database configuration
423
            return $this->newDatabaseConfiguration(
424
                $this->newDsn($connection[MagentoConfigurationKeys::HOST], $connection[MagentoConfigurationKeys::DBNAME]),
425
                $connection[MagentoConfigurationKeys::USERNAME],
426
                $connection[MagentoConfigurationKeys::PASSWORD],
427
                false
428
            );
429
        }
430
431
        // throw an execption if not
432
        throw new \Exception(sprintf('Requested Magento DB connection "%s" not found in Magento "%s"', $connectionName, $dir));
433
    }
434
435
    /**
436
     * Create's and return's a new database configuration instance, initialized with
437
     * the passed values.
438
     *
439
     * @param string      $dsn      The DSN to use
440
     * @param string      $username The username to  use
441
     * @param string|null $password The passed to use
442
     * @param boolean     $default  TRUE if this should be the default connection
443
     * @param string      $id       The ID to use
444
     *
445
     * @return \TechDivision\Import\Configuration\Jms\Configuration\Database The database configuration instance
446
     */
447
    public function newDatabaseConfiguration($dsn, $username = 'root', $password = null, $default = true, $id = null)
448
    {
449
450
        // initialize a new database configuration
451
        $database = new Database();
452
        $database->setDsn($dsn);
453
        $database->setDefault($default);
454
        $database->setUsername($username);
455
456
        // query whether or not an ID has been passed
457
        if ($id === null) {
458
            $id = Uuid::uuid4()->__toString();
459
        }
460
461
        // set the ID
462
        $database->setId($id);
463
464
        // query whether or not a password has been passed
465
        if ($password) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $password of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
466
            $database->setPassword($password);
467
        }
468
469
        // return the database configuration
470
        return $database;
471
    }
472
473
    /**
474
     * Create's and return's a new DSN from the passed values.
475
     *
476
     * @param string $host    The host to use
477
     * @param string $dbName  The database name to use
478
     * @param string $charset The charset to use
479
     *
480
     * @return string The DSN
481
     */
482
    public function newDsn($host, $dbName, $charset = 'utf8')
483
    {
484
        return sprintf('mysql:host=%s;dbname=%s;charset=%s', $host, $dbName, $charset);
485
    }
486
487
    /**
488
     * Return's the default configuration for the passed Magento Edition and the actual entity type.
489
     *
490
     * @param string $magentoEdition The Magento Edition to return the configuration for
491
     * @param string $entityTypeCode The entity type code to use
492
     *
493
     * @return string The path to the default configuration
494
     */
495
    public function getDefaultConfiguration($magentoEdition, $entityTypeCode)
496
    {
497
        return sprintf(
498
            '%s/%s/etc/techdivision-import.json',
499
            $this->getVendorDir(),
500
            $this->getDefaultConfigurationLibrary(
501
                $magentoEdition,
502
                $entityTypeCode
503
            )
504
        );
505
    }
506
507
    /**
508
     * Return's the Magento Edition specific default libraries. Supported Magento Editions are CE or EE.
509
     *
510
     * @param string $magentoEdition The Magento Edition to return the libraries for
511
     *
512
     * @return array The Magento Edition specific default libraries
513
     * @throws \Exception Is thrown, if the passed Magento Edition is NOT supported
514
     */
515
    public function getDefaultLibraries($magentoEdition)
516
    {
517
518
        // query whether or not, default libraries for the passed edition are available
519
        if (isset($this->defaultLibraries[$edition = strtolower($magentoEdition)])) {
520
            return $this->defaultLibraries[$edition];
521
        }
522
523
        // throw an exception, if the passed edition is not supported
524
        throw new \Exception(
525
            sprintf(
526
                'Default libraries for Magento \'%s\' not supported (MUST be one of CE or EE)',
527
                $magentoEdition
528
            )
529
        );
530
    }
531
532
    /**
533
     * Return's the Magento Edition and entity type's specific default library that contains
534
     * the configuration file.
535
     *
536
     * @param string $magentoEdition The Magento Edition to return the default library for
537
     * @param string $entityTypeCode The entity type code to return the default library file for
538
     *
539
     * @return string The name of the library that contains the default configuration file for the passed Magento Edition and entity type code
540
     * @throws \Exception Is thrown, if no default configuration for the passed entity type code is available
541
     */
542
    public function getDefaultConfigurationLibrary($magentoEdition, $entityTypeCode)
543
    {
544
545
        // query whether or not, a default configuration file for the passed entity type is available
546
        if (isset($this->defaultConfigurations[$edition = strtolower($magentoEdition)])) {
547
            if (isset($this->defaultConfigurations[$edition][$entityTypeCode])) {
548
                return $this->defaultConfigurations[$edition][$entityTypeCode];
549
            }
550
551
            // throw an exception, if the passed entity type is not supported
552
            throw new \Exception(
553
                sprintf(
554
                    'Entity Type Code \'%s\' not supported for Magento Edition \'%s\' (MUST be one of catalog_product, catalog_category or eav_attribute)',
555
                    $edition,
556
                    $entityTypeCode
557
                )
558
            );
559
        }
560
561
        // throw an exception, if the passed edition is not supported
562
        throw new \Exception(
563
            sprintf(
564
                'Default configuration for Magento \'%s\' not supported (MUST be one of CE or EE)',
565
                $magentoEdition
566
            )
567
        );
568
    }
569
570
    /**
571
     * Return's the entity types specific default import directory.
572
     *
573
     * @param string $entityTypeCode The entity type code to return the default import directory for
574
     *
575
     * @return string The default default import directory
576
     * @throws \Exception Is thrown, if no default import directory for the passed entity type code is available
577
     */
578
    public function getDefaultDirectory($entityTypeCode)
579
    {
580
581
        // query whether or not, a default configuration file for the passed entity type is available
582
        if (isset($this->defaultDirectories[$entityTypeCode])) {
583
            return $this->defaultDirectories[$entityTypeCode];
584
        }
585
586
        // throw an exception, if the passed entity type is not supported
587
        throw new \Exception(
588
            sprintf(
589
                'Entity Type Code \'%s\' not supported (MUST be one of catalog_product or catalog_category)',
590
                $entityTypeCode
591
            )
592
        );
593
    }
594
}
595