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
Launching the script from a Drupal installation makes boris bootstrap Drupal and you can start using the REPL as shown in the picture above.
Written by Giuseppe Rota
Related protips
2 Responses
Great idea ;)
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#