Completed
Push — develop ( ebaeb1...83c828 )
by Tom
04:01
created

Application::isMagerunStopFileFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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