Skip to content

Helloworld.script

<?php

//
// This example demonstrates how to write a script for the php:script command.
// Pass additional arguments after a double dash:
//   dr php:script helloworld.script -- apple --cider
// The script sees the command's $output and those arguments in $extra.
//

$output->writeln("Hello world!");
$output->writeln("The extra arguments to this command were:");
$output->writeln(print_r($extra, true));

//
// Scripts run after a full Drupal bootstrap, so Drupal's APIs are available.
//
$output->writeln('The site name is ' . \Drupal::config('system.site')->get('name'));

//
// A returned value is printed. Use --format=json or --format=yaml to change how.
//
return [
  'site path' => \Drupal::getContainer()->getParameter('site.path'),
  'drupal version' => \Drupal::VERSION,
];