From fb20f28d264f54a7c079b820b35b1be5f4746e63 Mon Sep 17 00:00:00 2001 From: Jesus Manuel Olivas Date: Fri, 30 Jun 2017 09:34:51 -0700 Subject: [PATCH] [console] Load commands from profiles when drupal and profile are not installed. --- src/Bootstrap/Drupal.php | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/Bootstrap/Drupal.php b/src/Bootstrap/Drupal.php index 2aefeafe4..75bc18f8e 100644 --- a/src/Bootstrap/Drupal.php +++ b/src/Bootstrap/Drupal.php @@ -5,12 +5,18 @@ use Doctrine\Common\Annotations\AnnotationRegistry; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\ConsoleOutput; +use Symfony\Component\Finder\Finder; use Symfony\Component\HttpFoundation\Request; use Drupal\Console\Core\Style\DrupalStyle; use Drupal\Console\Core\Utils\ArgvInputReader; use Drupal\Console\Core\Bootstrap\DrupalConsoleCore; use Drupal\Console\Core\Utils\DrupalFinder; +use Drupal\Console\Extension\Extension; +use Drupal\Console\Extension\Manager; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\Config\FileLocator; + class Drupal { protected $autoload; @@ -168,13 +174,66 @@ public function boot() if ($command == 'list') { $io->error($e->getMessage()); } + $drupal = new DrupalConsoleCore( $this->drupalFinder->getComposerRoot(), $this->drupalFinder->getDrupalRoot() ); + $container = $drupal->boot(); $container->set('class_loader', $this->autoload); + // Workaround to load commands from profiles. + // Drupal and the profile are not yet installed at this point. + $loader = new YamlFileLoader( + $container, + new FileLocator($this->drupalFinder->getDrupalRoot()) + ); + /** + * @var Manager $extensionManager + */ + $extensionManager = $container->get('console.extension_manager'); + $profiles = $extensionManager->discoverProfiles() + ->showNoCore() + ->showUninstalled() + ->getList(false); + + /** + * @var Extension[] $profiles + */ + foreach ($profiles as $profile) { + $profilePath = sprintf( + '%s/%s', + $this->drupalFinder->getDrupalRoot(), + $profile->getPath() + ); + $profileDirectories = [ + sprintf( + '%s/src/Command', + $profilePath + ), + sprintf( + '%s/src/Generator', + $profilePath + ) + ]; + + // Load Command & Generator Classes + $finder = new Finder(); + $finder->files() + ->name('*.php') + ->in($profileDirectories); + foreach ($finder as $file) { + echo $file->getRealPath() . PHP_EOL; + require_once($file->getRealPath()); + } + $consoleServicesExtensionFile = $profilePath . + '/console.services.yml'; + if (is_file($consoleServicesExtensionFile)) { + $loader->load($consoleServicesExtensionFile); + } + } + return $container; } }