11
11
use Magento \Framework \App \Bootstrap ;
12
12
use Magento \Framework \Shell \ComplexParameter ;
13
13
use Symfony \Component \Console \Input \ArgvInput ;
14
+ use Symfony \Component \Console \Input \InputInterface ;
15
+ use Symfony \Component \Console \Output \OutputInterface ;
14
16
15
17
/**
16
18
* Magento2 CLI Application. This is the hood for all command line tools supported by Magento.
@@ -27,6 +29,34 @@ class Cli extends SymfonyApplication
27
29
/** @var \Zend\ServiceManager\ServiceManager */
28
30
private $ serviceManager ;
29
31
32
+ /**
33
+ * Initialization exception
34
+ *
35
+ * @var \Exception
36
+ */
37
+ private $ initException ;
38
+
39
+ /**
40
+ * Process an error happened during initialization of commands, if any
41
+ *
42
+ * @param InputInterface $input
43
+ * @param OutputInterface $output
44
+ * @return int
45
+ * @throws \Exception
46
+ */
47
+ public function doRun (InputInterface $ input , OutputInterface $ output )
48
+ {
49
+ $ exitCode = parent ::doRun ($ input , $ output );
50
+ if ($ this ->initException ) {
51
+ $ output ->writeln (
52
+ "<error>We're sorry, an error occurred. Try clearing the cache and code generation directories. "
53
+ . "By default, they are: var/cache, var/di, var/generation, and var/page_cache.</error> "
54
+ );
55
+ throw $ this ->initException ;
56
+ }
57
+ return $ exitCode ;
58
+ }
59
+
30
60
/**
31
61
* @param string $name The name of the application
32
62
* @param string $version The version of the application
@@ -61,38 +91,33 @@ protected function getDefaultCommands()
61
91
*/
62
92
protected function getApplicationCommands ()
63
93
{
64
- $ setupCommands = [];
65
- $ modulesCommands = [];
94
+ $ commands = [];
95
+ try {
96
+ $ bootstrapParam = new ComplexParameter (self ::INPUT_KEY_BOOTSTRAP );
97
+ $ params = $ bootstrapParam ->mergeFromArgv ($ _SERVER , $ _SERVER );
98
+ $ params [Bootstrap::PARAM_REQUIRE_MAINTENANCE ] = null ;
99
+ $ bootstrap = Bootstrap::create (BP , $ params );
100
+ $ objectManager = $ bootstrap ->getObjectManager ();
101
+ /** @var \Magento\Setup\Model\ObjectManagerProvider $omProvider */
102
+ $ omProvider = $ this ->serviceManager ->get ('Magento\Setup\Model\ObjectManagerProvider ' );
103
+ $ omProvider ->setObjectManager ($ objectManager );
66
104
67
- $ bootstrapParam = new ComplexParameter (self ::INPUT_KEY_BOOTSTRAP );
68
- $ params = $ bootstrapParam ->mergeFromArgv ($ _SERVER , $ _SERVER );
69
- $ params [Bootstrap::PARAM_REQUIRE_MAINTENANCE ] = null ;
70
- $ bootstrap = Bootstrap::create (BP , $ params );
71
- $ objectManager = $ bootstrap ->getObjectManager ();
72
- /** @var \Magento\Setup\Model\ObjectManagerProvider $omProvider */
73
- $ omProvider = $ this ->serviceManager ->get ('Magento\Setup\Model\ObjectManagerProvider ' );
74
- $ omProvider ->setObjectManager ($ objectManager );
105
+ if (class_exists ('Magento\Setup\Console\CommandList ' )) {
106
+ $ setupCommandList = new \Magento \Setup \Console \CommandList ($ this ->serviceManager );
107
+ $ commands = array_merge ($ commands , $ setupCommandList ->getCommands ());
108
+ }
75
109
76
- if (class_exists ('Magento\Setup\Console\CommandList ' )) {
77
- $ setupCommandList = new \Magento \Setup \Console \CommandList ($ this ->serviceManager );
78
- $ setupCommands = $ setupCommandList ->getCommands ();
79
- }
110
+ if ($ objectManager ->get ('Magento\Framework\App\DeploymentConfig ' )->isAvailable ()) {
111
+ /** @var \Magento\Framework\Console\CommandList $commandList */
112
+ $ commandList = $ objectManager ->create ('Magento\Framework\Console\CommandList ' );
113
+ $ commands = array_merge ($ commands , $ commandList ->getCommands ());
114
+ }
80
115
81
- if ($ objectManager ->get ('Magento\Framework\App\DeploymentConfig ' )->isAvailable ()) {
82
- /** @var \Magento\Framework\Console\CommandList $commandList */
83
- $ commandList = $ objectManager ->create ('Magento\Framework\Console\CommandList ' );
84
- $ modulesCommands = $ commandList ->getCommands ();
116
+ $ commands = array_merge ($ commands , $ this ->getVendorCommands ($ objectManager ));
117
+ } catch (\Exception $ e ) {
118
+ $ this ->initException = $ e ;
85
119
}
86
-
87
- $ vendorCommands = $ this ->getVendorCommands ($ objectManager );
88
-
89
- $ commandsList = array_merge (
90
- $ setupCommands ,
91
- $ modulesCommands ,
92
- $ vendorCommands
93
- );
94
-
95
- return $ commandsList ;
120
+ return $ commands ;
96
121
}
97
122
98
123
/**
0 commit comments