Last Updated: February 25, 2016
·
1.682K
· grota

Drupal REPL using Boris

What is this and why it is useful

Ever wanted a nice REPL where you can run a bunch of simple Drupal code and immediately get feedback about what's returned?

Well now you can using boris and the power of drush scripts.

Requirements

  • drush A command line shell and scripting interface for Drupal.
  • boris, a tiny REPL for PHP.
  • A Drupal installation.
  • A *NIX system and a shell

The script

Save the following script and put it somewhere in your $PATH:

#!/usr/bin/env drush
<?php
$which_boris = exec('which boris');
$boris_path = is_link($which_boris) ? readlink($which_boris) : $which_boris;
require_once dirname($boris_path).'/../lib/autoload.php';
$boris = new \Boris\Boris('drupal> ');
$boris->setInspector(new \Boris\ColoredInspector());
$boris->start();
?>

Result

Picture

Launching the script from a Drupal installation makes boris bootstrap Drupal and you can start using the REPL as shown in the picture above.

2 Responses
Add your response

over 1 year ago ·

On my install the symlink was relative, so I had to change the require_once line to:

require_once dirname($which_boris).'/'.dirname($boris_path).'/../lib/autoload.php';
over 1 year ago ·