Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Load commands from profiles when drupal and profile are not installed. #3367

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/Bootstrap/Drupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down