Console for Drupal EXtensions.
An intentionally short-lived project designed to demo the Dex proposal at #3453474: CLI entry point in Drupal Core.
Includes the necessary components to develop and register commands without needing to use a core patch.
How to use
- Require and enable the module.
- Create a new file in a module with directory/namespace:
src/Command//Drupal\MYMODULE\Command. - Add code to file:
- Create a class extending
Symfony\Component\Console\Command\Command - Add the class attribute
Symfony\Component\Console\Attribute\AsCommand
- Create a class extending
- Clear cache
- Execute your new command with
dex MYMODULE:command
declare(strict_types=1);
namespace Drupal\MYMODULE\Command;
use Drupal\Component\Datetime\TimeInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(name: 'MYMODULE:command', description: 'An example command.')]
final class MyCommand extends Command {
public function __construct(
private readonly TimeInterface $dateTime,
) {
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$io = new SymfonyStyle($input, $output);
$now = new \DateTimeImmutable('@' . $this->dateTime->getRequestTime());
$io->note('The current time is ' . $now->format('r'));
return static::SUCCESS;
}
}
Supporting organizations:
Project information
Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed.Maintenance fixes only
Considered feature-complete by its maintainers.16 sites report using this module
- Created by dpi on , updated
Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
