|
4 | 4 | use Drupal\Console\Core\Style\DrupalStyle; |
5 | 5 | use Drupal\Console\Core\Utils\ArgvInputReader; |
6 | 6 | use Drupal\Console\Core\Utils\ConfigurationManager; |
| 7 | +use Drupal\Console\Core\Utils\TranslatorManager; |
7 | 8 | use Drupal\Console\Core\Utils\DrupalFinder; |
8 | 9 | use Drupal\Console\Launcher\Application; |
9 | 10 | use Symfony\Component\Console\Input\ArrayInput; |
|
24 | 25 | exit(1); |
25 | 26 | } |
26 | 27 |
|
| 28 | +$launcherType = [ |
| 29 | + 'local' => new Drupal\Console\Launcher\Utils\LauncherLocal(), |
| 30 | + 'ssh' => new Drupal\Console\Launcher\Utils\LauncherSsh(), |
| 31 | + 'container' => new Drupal\Console\Launcher\Utils\LauncherContainer() |
| 32 | +]; |
| 33 | + |
| 34 | +$output = new ConsoleOutput(); |
| 35 | +$input = new ArrayInput([]); |
| 36 | +$io = new DrupalStyle($input, $output); |
| 37 | + |
27 | 38 | $argvInputReader = new ArgvInputReader(); |
28 | 39 | $target = $argvInputReader->get('target', null); |
29 | 40 | $root = $argvInputReader->get('root', getcwd()); |
|
34 | 45 | $drupalFinder->locateRoot($root); |
35 | 46 | $composerRoot = $drupalFinder->getComposerRoot(); |
36 | 47 | $drupalRoot = $drupalFinder->getDrupalRoot(); |
37 | | -$isValidDrupal = ($composerRoot && $drupalRoot)?true:false; |
38 | 48 |
|
39 | | -$drupalConsole = new DrupalConsoleCore($pharRoot, null, $drupalFinder); |
40 | | -$container = $drupalConsole->boot(); |
41 | | - |
42 | | -/* @var ConfigurationManager $configurationManager */ |
43 | | -$configurationManager = $container->get('console.configuration_manager'); |
| 49 | +$configurationManager = new ConfigurationManager(); |
| 50 | +$configurationManager->loadConfiguration($drupalFinder->getComposerRoot()); |
44 | 51 | $configuration = $configurationManager->getConfiguration(); |
45 | | -$translator = $container->get('console.translator_manager'); |
46 | 52 |
|
47 | 53 | if ($options = $configuration->get('application.options') ?: []) { |
48 | 54 | $argvInputReader->setOptionsFromConfiguration($options); |
49 | 55 | } |
50 | | -$targetConfig = []; |
51 | | -if ($target = $argvInputReader->get('target')) { |
52 | | - $targetConfig = $container->get('console.configuration_manager') |
53 | | - ->readTarget($target); |
54 | | - $argvInputReader->setOptionsFromTargetConfiguration($targetConfig); |
55 | | -} |
56 | | - |
57 | | -$argvInputReader->setOptionsAsArgv(); |
58 | 56 |
|
59 | | -$output = new ConsoleOutput(); |
60 | | -$input = new ArrayInput([]); |
61 | | -$io = new DrupalStyle($input, $output); |
62 | | - |
63 | | -if ($target = $argvInputReader->get('target')) { |
64 | | - $configurationManager->loadConfiguration($drupalFinder->getComposerRoot()); |
65 | | - $configurationManager->getSites(); |
66 | | - $options = $configurationManager->readTarget($target); |
67 | | - if ($options) { |
68 | | - if ($options['type'] != 'local') { |
69 | | - $launcherType = 'console.launcher_' . $options['type']; |
70 | | - if ($container->has($launcherType)) { |
71 | | - $launcher = $container->get($launcherType); |
72 | | - $launch = $launcher->launch($options); |
73 | | - exit(0); |
74 | | - } |
| 57 | +if ($target) { |
| 58 | + if ($targetOptions = $configurationManager->readTarget($target)) { |
| 59 | + $argvInputReader->setOptionsFromTargetConfiguration($targetOptions); |
| 60 | + $argvInputReader->setOptionsAsArgv(); |
| 61 | + $type = $targetOptions['type']; |
| 62 | + if ($type !== 'local') { |
| 63 | + $launcher = $launcherType[$type]; |
| 64 | + $exitCode = $launcher->launch($targetOptions); |
| 65 | + exit($exitCode); |
75 | 66 | } else { |
76 | | - $root = $options['root']; |
77 | | - $drupalFinder = new DrupalFinder(); |
| 67 | + $root = $targetOptions['root']; |
78 | 68 | $drupalFinder->locateRoot($root); |
79 | | - $composerRoot = $drupalFinder->getComposerRoot(); |
80 | | - $drupalRoot = $drupalFinder->getDrupalRoot(); |
81 | | - $isValidDrupal = ($composerRoot && $drupalRoot)?true:false; |
82 | 69 | } |
83 | 70 | } |
84 | 71 | } |
85 | 72 |
|
86 | | -if ($debug || ($isValidDrupal && $command == 'list')) { |
| 73 | +if ($debug || ($drupalFinder->isValidDrupal() && $command == 'list')) { |
87 | 74 | $io->writeln( |
88 | 75 | sprintf( |
89 | 76 | '<info>%s</info> version <comment>%s</comment>', |
|
102 | 89 | ); |
103 | 90 | } |
104 | 91 |
|
105 | | -if ($isValidDrupal) { |
106 | | - $launcher = $container->get('console.launcher_local'); |
| 92 | +if ($drupalFinder->isValidDrupal()) { |
| 93 | + $launcher = $launcherType['local']; |
107 | 94 | $exitCode = $launcher->launch($drupalFinder); |
108 | | - |
109 | 95 | if ($exitCode === FALSE) { |
| 96 | + $translator = new TranslatorManager(); |
| 97 | + $translator->loadCoreLanguage( |
| 98 | + $configuration->get('application.language'), |
| 99 | + $pharRoot |
| 100 | + ); |
| 101 | + |
110 | 102 | $message = sprintf( |
111 | 103 | $translator->trans('application.site.errors.not-installed'), |
112 | 104 | PHP_EOL . $drupalFinder->getComposerRoot() |
|
127 | 119 | exit($exitCode); |
128 | 120 | } |
129 | 121 |
|
| 122 | +// Restore original argv values |
130 | 123 | $argvInputReader->restoreOriginalArgvValues(); |
| 124 | +// Boot Launcher as standalone. |
| 125 | +$drupalConsole = new DrupalConsoleCore($pharRoot, null, $drupalFinder); |
| 126 | +$container = $drupalConsole->boot(); |
131 | 127 | $application = new Application($container); |
132 | 128 | $application->run(); |
0 commit comments