Completed
Push — develop ( 10e168...d8d0bb )
by Tom
04:35
created

Application::requireOnce()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace N98\Magento;
4
5
use Composer\Autoload\ClassLoader;
6
use Exception;
7
use Mage;
8
use Magento\Mtf\EntryPoint\EntryPoint;
9
use N98\Magento\Application\Config;
10
use N98\Magento\Application\ConfigurationLoader;
11
use N98\Magento\Application\Console\Events;
12
use N98\Util\Console\Helper\MagentoHelper;
13
use N98\Util\OperatingSystem;
14
use RuntimeException;
15
use Symfony\Component\Console\Application as BaseApplication;
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Event\ConsoleEvent;
18
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
19
use Symfony\Component\Console\Helper\FormatterHelper;
20
use Symfony\Component\Console\Input\ArgvInput;
21
use Symfony\Component\Console\Input\InputDefinition;
22
use Symfony\Component\Console\Input\InputInterface;
23
use Symfony\Component\Console\Input\InputOption;
24
use Symfony\Component\Console\Output\ConsoleOutput;
25
use Symfony\Component\Console\Output\OutputInterface;
26
use Symfony\Component\EventDispatcher\EventDispatcher;
27
use UnexpectedValueException;
28
29
class Application extends BaseApplication
30
{
31
    /**
32
     * @var string
33
     */
34
    const APP_NAME = 'n98-magerun';
35
36
    /**
37
     * @var string
38
     */
39
    const APP_VERSION = '1.97.29';
40
41
    /**
42
     * @var int
43
     */
44
    const MAGENTO_MAJOR_VERSION_1 = 1;
45
46
    /**
47
     * @var int
48
     */
49
    const MAGENTO_MAJOR_VERSION_2 = 2;
50
51
    /**
52
     * @var string
53
     */
54
    private static $logo = "
55
     ___ ___
56
 _ _/ _ ( _ )___ _ __  __ _ __ _ ___ _ _ _  _ _ _
57
| ' \\_, / _ \\___| '  \\/ _` / _` / -_) '_| || | ' \\
58
|_||_/_/\\___/   |_|_|_\\__,_\\__, \\___|_|  \\_,_|_||_|
59
                           |___/
60
";
61
62
    /**
63
     * Shadow copy of the Application parent when using this concrete setAutoExit() implementation
64
     *
65
     * @see \Symfony\Component\Console\Application::$autoExit
66
     * @var bool
67
     */
68
    private $autoExitShadow = true;
69
70
    /**
71
     * @var ClassLoader
72
     */
73
    protected $autoloader;
74
75
    /**
76
     * @var Config
77
     */
78
    protected $config;
79
80
    /**
81
     * @see \N98\Magento\Application::setConfigurationLoader()
82
     * @var ConfigurationLoader
83
     */
84
    private $configurationLoaderInjected;
85
86
    /**
87
     * @var string
88
     */
89
    protected $_magentoRootFolder = null;
90
91
    /**
92
     * @var bool
93
     */
94
    protected $_magentoEnterprise = false;
95
96
    /**
97
     * @var int
98
     */
99
    protected $_magentoMajorVersion = self::MAGENTO_MAJOR_VERSION_1;
100
101
    /**
102
     * @var EntryPoint
103
     */
104
    protected $_magento2EntryPoint = null;
105
106
    /**
107
     * @var bool
108
     */
109
    protected $_isPharMode = false;
110
111
    /**
112
     * @var bool
113
     */
114
    protected $_magerunStopFileFound = false;
115
116
    /**
117
     * @var string
118
     */
119
    protected $_magerunStopFileFolder = null;
120
121
    /**
122
     * @var bool
123
     */
124
    protected $_isInitialized = false;
125
126
    /**
127
     * @var EventDispatcher
128
     */
129
    protected $dispatcher;
130
131
    /**
132
     * If root dir is set by root-dir option this flag is true
133
     *
134
     * @var bool
135
     */
136
    protected $_directRootDir = false;
137
138
    /**
139
     * @var bool
140
     */
141
    protected $_magentoDetected = false;
142
143
    /**
144
     * @param ClassLoader $autoloader
145
     */
146
    public function __construct($autoloader = null)
147
    {
148
        $this->autoloader = $autoloader;
149
        parent::__construct(self::APP_NAME, self::APP_VERSION);
150
    }
151
152
    /**
153
     * @param bool $boolean
154
     * @return bool previous auto-exit state
155
     */
156
    public function setAutoExit($boolean)
157
    {
158
        $previous = $this->autoExitShadow;
159
        $this->autoExitShadow = $boolean;
160
        parent::setAutoExit($boolean);
161
162
        return $previous;
163
    }
164
165
    /**
166
     * @return InputDefinition
167
     */
168
    protected function getDefaultInputDefinition()
169
    {
170
        $inputDefinition = parent::getDefaultInputDefinition();
171
172
        /**
173
         * Root dir
174
         */
175
        $rootDirOption = new InputOption(
176
            '--root-dir',
177
            '',
178
            InputOption::VALUE_OPTIONAL,
179
            'Force magento root dir. No auto detection'
180
        );
181
        $inputDefinition->addOption($rootDirOption);
182
183
        /**
184
         * Skip config
185
         */
186
        $skipExternalConfig = new InputOption(
187
            '--skip-config',
188
            '',
189
            InputOption::VALUE_NONE,
190
            'Do not load any custom config.'
191
        );
192
        $inputDefinition->addOption($skipExternalConfig);
193
194
        /**
195
         * Skip root check
196
         */
197
        $skipExternalConfig = new InputOption(
198
            '--skip-root-check',
199
            '',
200
            InputOption::VALUE_NONE,
201
            'Do not check if n98-magerun runs as root'
202
        );
203
        $inputDefinition->addOption($skipExternalConfig);
204
205
        return $inputDefinition;
206
    }
207
208
    /**
209
     * Search for magento root folder
210
     *
211
     * @param InputInterface $input [optional]
212
     * @param OutputInterface $output [optional]
213
     * @return void
214
     */
215
    public function detectMagento(InputInterface $input = null, OutputInterface $output = null)
216
    {
217
        // do not detect magento twice
218
        if ($this->_magentoDetected) {
219
            return;
220
        }
221
222
        if (null === $input) {
223
            $input = new ArgvInput();
224
        }
225
226
        if (null === $output) {
227
            $output = new ConsoleOutput();
228
        }
229
230
        if ($this->getMagentoRootFolder() === null) {
231
            $this->_checkRootDirOption($input);
232
            $folder = OperatingSystem::getCwd();
233
        } else {
234
            $folder = $this->getMagentoRootFolder();
235
        }
236
237
        $this->getHelperSet()->set(new MagentoHelper($input, $output), 'magento');
238
        $magentoHelper = $this->getHelperSet()->get('magento');
239
        /* @var $magentoHelper MagentoHelper */
240
        if (!$this->_directRootDir) {
241
            $subFolders = $this->config->getDetectSubFolders();
242
        } else {
243
            $subFolders = array();
244
        }
245
246
        $this->_magentoDetected = $magentoHelper->detect($folder, $subFolders);
247
        $this->_magentoRootFolder = $magentoHelper->getRootFolder();
248
        $this->_magentoEnterprise = $magentoHelper->isEnterpriseEdition();
249
        $this->_magentoMajorVersion = $magentoHelper->getMajorVersion();
250
        $this->_magerunStopFileFound = $magentoHelper->isMagerunStopFileFound();
251
        $this->_magerunStopFileFolder = $magentoHelper->getMagerunStopFileFolder();
252
    }
253
254
    /**
255
     * Add own helpers to helperset.
256
     *
257
     * @return void
258
     */
259
    protected function registerHelpers()
260
    {
261
        $helperSet = $this->getHelperSet();
262
        $config = $this->config->getConfig();
263
264
        foreach ($config['helpers'] as $helperName => $helperClass) {
265
            if (!class_exists($helperClass)) {
266
                throw new RuntimeException(
267
                    sprintf('Nonexistent helper class: "%s", check helpers configuration', $helperClass)
268
                );
269
            }
270
271
            // Twig helper needs the config-file
272
            $helper = 'N98\Util\Console\Helper\TwigHelper' === $helperClass
273
                ? new $helperClass($this->config)
274
                : new $helperClass()
275
            ;
276
            $helperSet->set($helper, $helperName);
277
        }
278
    }
279
280
    /**
281
     * @param InputInterface $input
282
     *
283
     * @return ArgvInput|InputInterface
284
     */
285
    protected function checkConfigCommandAlias(InputInterface $input)
286
    {
287
        trigger_error(__METHOD__ . ' moved, use getConfig()->checkConfigCommandAlias()', E_USER_DEPRECATED);
288
289
        return $this->config->checkConfigCommandAlias($input);
290
    }
291
292
    /**
293
     * @param Command $command
294
     */
295
    protected function registerConfigCommandAlias(Command $command)
296
    {
297
        trigger_error(__METHOD__ . ' moved, use getConfig()->registerConfigCommandAlias() instead', E_USER_DEPRECATED);
298
299
        return $this->config->registerConfigCommandAlias($command);
300
    }
301
302
    /**
303
     * Adds autoloader prefixes from user's config
304
     */
305
    protected function registerCustomAutoloaders()
306
    {
307
        trigger_error(__METHOD__ . ' moved, use getConfig()->registerCustomAutoloaders() instead', E_USER_DEPRECATED);
308
309
        $this->config->registerCustomAutoloaders($this->autoloader);
310
    }
311
312
    /**
313
     * @return bool
314
     */
315
    protected function hasCustomCommands()
316
    {
317
        trigger_error(__METHOD__ . ' moved, use config directly instead', E_USER_DEPRECATED);
318
319
        return 0 < count($this->config->getConfig(array('commands', 'customCommands')));
320
    }
321
322
    /**
323
     * @return void
324
     */
325
    protected function registerCustomCommands()
326
    {
327
        trigger_error(__METHOD__ . ' moved, use getConfig()->registerCustomCommands() instead', E_USER_DEPRECATED);
328
329
        $this->config->registerCustomCommands($this);
330
    }
331
332
    /**
333
     * @param string $class
334
     * @return bool
335
     */
336
    protected function isCommandDisabled($class)
337
    {
338
        trigger_error(__METHOD__ . ' moved, use config directly instead', E_USER_DEPRECATED);
339
340
        $config = $this->config->getConfig();
341
342
        return in_array($class, $config['commands']['disabled']);
343
    }
344
345
    /**
346
     * Override standard command registration. We want alias support.
347
     *
348
     * @param Command $command
349
     *
350
     * @return Command
351
     */
352
    public function add(Command $command)
353
    {
354
        if ($this->config) {
355
            $this->config->registerConfigCommandAlias($command);
356
        }
357
358
        return parent::add($command);
359
    }
360
361
    /**
362
     * @param bool $mode
363
     */
364
    public function setPharMode($mode)
365
    {
366
        $this->_isPharMode = $mode;
367
    }
368
369
    /**
370
     * @return bool
371
     */
372
    public function isPharMode()
373
    {
374
        return $this->_isPharMode;
375
    }
376
377
    /**
378
     * @TODO Move logic into "EventSubscriber"
379
     *
380
     * @param OutputInterface $output
381
     * @return null|false
382
     */
383
    public function checkVarDir(OutputInterface $output)
384
    {
385
        $tempVarDir = sys_get_temp_dir() . '/magento/var';
386
        if (!OutputInterface::VERBOSITY_NORMAL <= $output->getVerbosity() && !is_dir($tempVarDir)) {
387
            return;
388
        }
389
390
        $this->detectMagento(null, $output);
391
        /* If magento is not installed yet, don't check */
392
        if ($this->_magentoRootFolder === null
393
            || !file_exists($this->_magentoRootFolder . '/app/etc/local.xml')
394
        ) {
395
            return;
396
        }
397
398
        try {
399
            $this->initMagento();
400
        } catch (Exception $e) {
401
            $message = 'Cannot initialize Magento. Please check your configuration. '
402
                . 'Some n98-magerun command will not work. Got message: ';
403
            if (OutputInterface::VERBOSITY_VERY_VERBOSE <= $output->getVerbosity()) {
404
                $message .= $e->getTraceAsString();
405
            } else {
406
                $message .= $e->getMessage();
407
            }
408
            $output->writeln($message);
409
410
            return;
411
        }
412
413
        $configOptions = new \Mage_Core_Model_Config_Options();
414
        $currentVarDir = $configOptions->getVarDir();
415
416
        if ($currentVarDir == $tempVarDir) {
417
            $output->writeln(array(
418
                sprintf('<warning>Fallback folder %s is used in n98-magerun</warning>', $tempVarDir),
419
                '',
420
                'n98-magerun is using the fallback folder. If there is another folder configured for Magento, this ' .
421
                'can cause serious problems.',
422
                'Please refer to https://github.com/netz98/n98-magerun/wiki/File-system-permissions ' .
423
                'for more information.',
424
                '',
425
            ));
426
        } else {
427
            $output->writeln(array(
428
                sprintf('<warning>Folder %s found, but not used in n98-magerun</warning>', $tempVarDir),
429
                '',
430
                "This might cause serious problems. n98-magerun is using the configured var-folder " .
431
                "<comment>$currentVarDir</comment>",
432
                'Please refer to https://github.com/netz98/n98-magerun/wiki/File-system-permissions ' .
433
                'for more information.',
434
                '',
435
            ));
436
437
            return false;
438
        }
439
    }
440
441
    /**
442
     * Loads and initializes the Magento application
443
     *
444
     * @param bool $soft
445
     *
446
     * @return bool false if magento root folder is not set, true otherwise
447
     */
448
    public function initMagento($soft = false)
449
    {
450
        if ($this->getMagentoRootFolder() === null) {
451
            return false;
452
        }
453
454
        $isMagento2 = $this->_magentoMajorVersion === self::MAGENTO_MAJOR_VERSION_2;
455
        if ($isMagento2) {
456
            $this->_initMagento2();
457
        } else {
458
            $this->_initMagento1($soft);
459
        }
460
461
        return true;
462
    }
463
464
    /**
465
     * @return string
466
     */
467
    public function getHelp()
468
    {
469
        return self::$logo . parent::getHelp();
470
    }
471
472
    public function getLongVersion()
473
    {
474
        return parent::getLongVersion() . ' by <info>netz98 GmbH</info>';
475
    }
476
477
    /**
478
     * @return boolean
479
     */
480
    public function isMagentoEnterprise()
481
    {
482
        return $this->_magentoEnterprise;
483
    }
484
485
    /**
486
     * @return string
487
     */
488
    public function getMagentoRootFolder()
489
    {
490
        return $this->_magentoRootFolder;
491
    }
492
493
    /**
494
     * @param string $magentoRootFolder
495
     */
496
    public function setMagentoRootFolder($magentoRootFolder)
497
    {
498
        $this->_magentoRootFolder = $magentoRootFolder;
499
    }
500
501
    /**
502
     * @return int
503
     */
504
    public function getMagentoMajorVersion()
505
    {
506
        return $this->_magentoMajorVersion;
507
    }
508
509
    /**
510
     * @return ClassLoader
511
     */
512
    public function getAutoloader()
513
    {
514
        return $this->autoloader;
515
    }
516
517
    /**
518
     * @param ClassLoader $autoloader
519
     */
520
    public function setAutoloader(ClassLoader $autoloader)
521
    {
522
        $this->autoloader = $autoloader;
523
    }
524
525
    /**
526
     * Get config array
527
     *
528
     * Specify one key per parameter to traverse the config. Then returns null
529
     * if the path of the key(s) can not be obtained.
530
     *
531
     * @param string|int $key ... (optional)
532
     *
533
     * @return array|null
534
     */
535
    public function getConfig($key = null)
536
    {
537
        $array = $this->config->getConfig();
538
539
        $keys = func_get_args();
540
        foreach ($keys as $key) {
541
            if (null === $key) {
542
                continue;
543
            }
544
            if (!isset($array[$key])) {
545
                return null;
546
            }
547
            $array = $array[$key];
548
        }
549
550
        return $array;
551
    }
552
553
    /**
554
     * @param array $config
555
     */
556
    public function setConfig($config)
557
    {
558
        $this->config->setConfig($config);
559
    }
560
561
    /**
562
     * @return boolean
563
     */
564
    public function isMagerunStopFileFound()
565
    {
566
        return $this->_magerunStopFileFound;
567
    }
568
569
    /**
570
     * Runs the current application with possible command aliases
571
     *
572
     * @param InputInterface $input An Input instance
573
     * @param OutputInterface $output An Output instance
574
     *
575
     * @return integer 0 if everything went fine, or an error code
576
     */
577
    public function doRun(InputInterface $input, OutputInterface $output)
578
    {
579
        $event = new Application\Console\Event($this, $input, $output);
580
        $this->dispatcher->dispatch(Events::RUN_BEFORE, $event);
581
582
        /**
583
         * only for compatibility to old versions.
584
         */
585
        $event = new ConsoleEvent(new Command('dummy'), $input, $output);
586
        $this->dispatcher->dispatch('console.run.before', $event);
587
588
        $input = $this->config->checkConfigCommandAlias($input);
589
        if ($output instanceof ConsoleOutput) {
590
            $this->checkVarDir($output->getErrorOutput());
591
        }
592
593
        return parent::doRun($input, $output);
594
    }
595
596
    /**
597
     * @param InputInterface $input [optional]
598
     * @param OutputInterface $output [optional]
599
     *
600
     * @return int
601
     */
602
    public function run(InputInterface $input = null, OutputInterface $output = null)
603
    {
604
        if (null === $input) {
605
            $input = new ArgvInput();
606
        }
607
608
        if (null === $output) {
609
            $output = new ConsoleOutput();
610
        }
611
        $this->_addOutputStyles($output);
612
        if ($output instanceof ConsoleOutput) {
613
            $this->_addOutputStyles($output->getErrorOutput());
614
        }
615
616
        $this->configureIO($input, $output);
617
618
        try {
619
            $this->init(array(), $input, $output);
620
        } catch (Exception $e) {
621
            $output = new ConsoleOutput();
622
            $this->renderException($e, $output->getErrorOutput());
623
        }
624
625
        $return = parent::run($input, $output);
626
627
        // Fix for no return values -> used in interactive shell to prevent error output
628
        if ($return === null) {
629
            return 0;
630
        }
631
632
        return $return;
633
    }
634
635
    /**
636
     * @param array $initConfig [optional]
637
     * @param InputInterface $input [optional]
638
     * @param OutputInterface $output [optional]
639
     *
640
     * @return void
641
     */
642
    public function init(array $initConfig = array(), InputInterface $input = null, OutputInterface $output = null)
643
    {
644
        if ($this->_isInitialized) {
645
            return;
646
        }
647
648
        // Suppress DateTime warnings
649
        date_default_timezone_set(@date_default_timezone_get());
650
651
        // Initialize EventDispatcher early
652
        $this->dispatcher = new EventDispatcher();
653
        $this->setDispatcher($this->dispatcher);
654
655
        $input = $input ?: new ArgvInput();
656
        $output = $output ?: new ConsoleOutput();
657
658
        if (null !== $this->config) {
659
            throw new UnexpectedValueException(sprintf('Config already initialized'));
660
        }
661
662
        $loadExternalConfig = !$input->hasParameterOption('--skip-config');
663
664
        $this->config = $config = new Config($initConfig, $this->isPharMode(), $output);
665
        if ($this->configurationLoaderInjected) {
666
            $config->setLoader($this->configurationLoaderInjected);
667
        }
668
        $config->loadPartialConfig($loadExternalConfig);
669
        $this->detectMagento($input, $output);
670
        $configLoader = $config->getLoader();
671
        $configLoader->loadStageTwo($this->_magentoRootFolder, $loadExternalConfig, $this->_magerunStopFileFolder);
672
        $config->load();
673
674
        if ($autoloader = $this->autoloader) {
675
            $config->registerCustomAutoloaders($autoloader);
676
            $this->registerEventSubscribers();
677
            $config->registerCustomCommands($this);
678
        }
679
680
        $this->registerHelpers();
681
682
        $this->_isInitialized = true;
683
    }
684
685
    /**
686
     * @param array $initConfig [optional]
687
     * @param InputInterface $input [optional]
688
     * @param OutputInterface $output [optional]
689
     */
690
    public function reinit($initConfig = array(), InputInterface $input = null, OutputInterface $output = null)
691
    {
692
        $this->_isInitialized = false;
693
        $this->_magentoDetected = false;
694
        $this->_magentoRootFolder = null;
695
        $this->config = null;
696
        $this->init($initConfig, $input, $output);
697
    }
698
699
    /**
700
     * @return void
701
     */
702
    protected function registerEventSubscribers()
703
    {
704
        $config = $this->config->getConfig();
705
        $subscriberClasses = $config['event']['subscriber'];
706
        foreach ($subscriberClasses as $subscriberClass) {
707
            $subscriber = new $subscriberClass();
708
            $this->dispatcher->addSubscriber($subscriber);
709
        }
710
    }
711
712
    /**
713
     * @param InputInterface $input
714
     * @return bool
715
     * @deprecated 1.97.27
716
     */
717
    protected function _checkSkipConfigOption(InputInterface $input)
718
    {
719
        trigger_error(
720
            __METHOD__ . ' removed, use $input->hasParameterOption(\'--skip-config\') instead',
721
            E_USER_DEPRECATED
722
        );
723
724
        return $input->hasParameterOption('--skip-config');
725
    }
726
727
    /**
728
     * @param InputInterface $input
729
     * @return string
730
     */
731
    protected function _checkRootDirOption(InputInterface $input)
732
    {
733
        $rootDir = $input->getParameterOption('--root-dir');
734
        if (is_string($rootDir)) {
735
            $this->setRootDir($rootDir);
736
        }
737
    }
738
739
    /**
740
     * Set root dir (chdir()) of magento directory
741
     *
742
     * @param string $path to Magento directory
743
     */
744
    private function setRootDir($path)
745
    {
746
        if (isset($path[0]) && '~' === $path[0]) {
747
            $path = OperatingSystem::getHomeDir() . substr($path, 1);
748
        }
749
750
        $folder = realpath($path);
751
        $this->_directRootDir = true;
752
        if (is_dir($folder)) {
753
            chdir($folder);
754
        }
755
    }
756
757
    /**
758
     * @param bool $soft
759
     *
760
     * @return void
761
     */
762
    protected function _initMagento1($soft = false)
763
    {
764
        // Load Mage class definition
765
        Initialiser::bootstrap($this->_magentoRootFolder);
766
767
        // skip Mage::app init routine and return
768
        if ($soft === true) {
769
            return;
770
        }
771
772
        $initSettings = $this->config->getConfig('init');
773
774
        Mage::app($initSettings['code'], $initSettings['type'], $initSettings['options']);
775
    }
776
777
    /**
778
     * @return void
779
     */
780
    protected function _initMagento2()
781
    {
782
        $this->outputMagerunCompatibilityNotice('2');
783
    }
784
785
    /**
786
     * Show a hint that this is Magento incompatible with Magerun and how to obtain the correct Magerun for it
787
     *
788
     * @param string $version of Magento, "1" or "2", that is incompatible
789
     */
790
    private function outputMagerunCompatibilityNotice($version)
791
    {
792
        $file = $version === '2' ? $version : '';
793
        $magentoHint = <<<MAGENTOHINT
794
You are running a Magento $version.x instance. This version of n98-magerun is not compatible
795
with Magento $version.x. Please use n98-magerun$version (version $version) for this shop.
796
797
A current version of the software can be downloaded on github.
798
799
<info>Download with curl
800
------------------</info>
801
802
    <comment>curl -O https://files.magerun.net/n98-magerun$file.phar</comment>
803
804
<info>Download with wget
805
------------------</info>
806
807
    <comment>wget https://files.magerun.net/n98-magerun$file.phar</comment>
808
809
MAGENTOHINT;
810
811
        $output = new ConsoleOutput();
812
813
        /** @var $formatter FormatterHelper */
814
        $formatter = $this->getHelperSet()->get('formatter');
815
816
        $output->writeln(array(
817
            '',
818
            $formatter->formatBlock('Compatibility Notice', 'bg=blue;fg=white', true),
819
            '',
820
            $magentoHint,
821
        ));
822
823
        throw new RuntimeException('This version of n98-magerun is not compatible with Magento ' . $version);
824
    }
825
826
    /**
827
     * @return EventDispatcher
828
     */
829
    public function getDispatcher()
830
    {
831
        return $this->dispatcher;
832
    }
833
834
    /**
835
     * @param array $initConfig
836
     * @param OutputInterface $output
837
     * @return ConfigurationLoader
838
     */
839
    public function getConfigurationLoader(array $initConfig, OutputInterface $output)
840
    {
841
        trigger_error(__METHOD__ . ' moved, use getConfig()->getLoader()', E_USER_DEPRECATED);
842
843
        unset($initConfig, $output);
844
845
        $loader = $this->config ? $this->config->getLoader() : $this->configurationLoaderInjected;
846
847
        if (!$loader) {
848
            throw new RuntimeException('ConfigurationLoader is not yet available, initialize it or Config first');
849
        }
850
851
        return $loader;
852
    }
853
854
    /**
855
     * @param ConfigurationLoader $configurationLoader
856
     *
857
     * @return $this
858
     */
859
    public function setConfigurationLoader(ConfigurationLoader $configurationLoader)
860
    {
861
        if ($this->config) {
862
            $this->config->setLoader($configurationLoader);
863
        } else {
864
            /* inject loader to be used later when config is created in */
865
            /* @see N98\Magento\Application::init */
866
            $this->configurationLoaderInjected = $configurationLoader;
867
        }
868
869
        return $this;
870
    }
871
872
    /**
873
     * @param OutputInterface $output
874
     */
875
    protected function _addOutputStyles(OutputInterface $output)
876
    {
877
        $output->getFormatter()->setStyle('debug', new OutputFormatterStyle('magenta', 'white'));
878
        $output->getFormatter()->setStyle('warning', new OutputFormatterStyle('red', 'yellow', array('bold')));
879
    }
880
}
881