drupalvm config:generate \
--machine-name="drupalbristol" \
--hostname="drupalbristol.l" \
--ip-address="192.168.88.88" \
--cpus="1" --memory="512" \
--webserver="nginx" --drupal-version="8" \
--database-name="drupal" --database-user="drupal" \
--database-password="drupal" --build-makefile=false \
...
The Console component allows you to create command-line commands. Your console commands can be used for any recurring task, such as cronjobs, imports, or other batch jobs.
$ composer require symfony/console
$ composer install
# composer.json
"require": {
"symfony/console": "^3.1"
}
# app.php
require __DIR__ . '/vendor/autoload.php';
// Do stuff.
Application
class
#!/usr/bin/env php
require __DIR__ . '/drupalcamp.php';
require __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\Console\Application;
$application = new Application();
$application->run();
require __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\Console\Application;
$application = new Application();
$application->run('DrupalCamps', '1.0');
src/
Application
# composer.json
"autoload": {
"psr-4": {
"": "src/"
}
}
# composer.json
"autoload": {
"psr-4": {
"DrupalCamps\\": "src/"
}
}
use Symfony\Component\Console\Command\Command;
class GoCommand extends Command
{
public function configure()
{
$this->setName('go')
->setDescription('Go to a DrupalCamp.');
}
}
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
...
public function execute(InputInterface $input, OutputInterface $output)
{
// Execute the command.
}
$application = new Application();
$application->add(new GoCommand());
$application->run();
$application = new Application();
$application->addCommands(
[
new GoCommand(),
]
);
$application->run();
use Symfony\Component\Console\Input\InputArgument;
...
public function configure()
{
$this->setName('go')
->setDescription('Go to a DrupalCamp')
->addArgument('name', InputArgument::OPTIONAL, 'Which DrupalCamp?')
->addOption('past', null, InputOption::VALUE_NONE);
}
public function execute(InputInterface $input, OutputInterface $output)
{
$text = $input->getArgument('name');
$past = $input->getOption('past');
...
}
$input->getArgument('foo');
$input->getOption('bar');
$output->write($text);
$output->writeln($text);
$output->write("$text ");
$output->write("$text ");
$output->write("$text ");
public function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->table(
['Title', 'Speaker'],
[
['Drupal VM, Meet Symfony Console', 'Oliver Davies'],
['Drupal 8 and the Symfony EventDispatcher', 'Eric Smith'],
['Building with APIs', 'Nigel Dunn'],
]
);
}
public function interact(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
if (!$input->getArgument('name')) {
$input->setArgument('name', $io->ask('Which DrupalCamp?'));
}
}
public function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->success($input->getArgument('name'));
}
use GuzzleHttp\Client;
...
$client = new Client();
$application->add(new NewCommand($client));
use GuzzleHttp\ClientInterface;
use Symfony\Component\Console\Command;
final class NewCommand extends Command
{
private $client;
public function __construct(ClientInterface $client)
{
parent::__construct();
$this->client = $client;
}
}
box build
# composer.json
"scripts": {
"build": [
"box build",
"shasum drupalvm.phar |
awk '{print $1}' > drupalvm.phar.version"
]
}
$ composer run-script build