Last Updated: February 25, 2016
·
558
· tungd

Adding a REPL to Kohana

Having a REPL is very handy for experiment during development, this is how I added a Boris REPL to Kohana PHP Framework.

Requirements:

composer.json:

{
  "config": {
    "vendor-dir": "application/vendor"
  },
  "require-dev": {
    "phpunit/phpunit": "3.7.*",
    "d11wtq/boris": "1.0.*"
  }
}

Load Composer's autoloader in bootstrap.php:

/**
 * Composer
 */
require_once(Kohana::find_file('vendor', 'autoload'));

modules/repl/classes/Task/REPL.php:

<?php defined('SYSPATH') or die('No direct access allowed.');

class Task_REPL extends Minion_Task {

  protected function _execute(array $options) {
    try {
      $boris = new \Boris\Boris('Kohana> ');
      $boris->start();
    } catch (ErrorException $e) {
      Minion_CLI::write($e->getMessage());
    }
  }
}

After enable the minion and repl module in your bootstrap.php, start the REPL with

$ php index.php repl

Profit!