
Boris is a small but reliable REPL for php
- Tutorial
Python, ruby, clojure have REPL. REPL - read-eval-print loop. If you describe what REPL is on pseudo-code, it will look something like this:
Such an implementation allows the developer to experiment with the code as he pleases without creating files. You can make a mistake, Boris will display a message about this, but will continue to work waiting for the new code.

Boris is available through composer:
Or the old fashioned way:
When you start Boris, an invitation appears:
Try to write something, Boris will process it and give the result. If you have a long multi-line expression, Boris will put it together and execute it together. To cancel any operations used
To exit the utility is used
Everything is very simple:
Here the utility is initialized with a global variable
It is possible to add callbacks before starting the utility. There are two options for adding them:
First, we pass a line of code that Boris simply executes through
Link to the repository.
while(true){
echo eval($input->get());
}
Such an implementation allows the developer to experiment with the code as he pleases without creating files. You can make a mistake, Boris will display a message about this, but will continue to work waiting for the new code.
Requirements
- PHP> = 5.3
- The readline functions
- The PCNTL functions
- The posix functions
Installation
Boris is available through composer:
composer require d11wtq/boris dev-master
Or the old fashioned way:
git clone git://github.com/d11wtq/boris.git
cd boris
./bin/boris
Using
When you start Boris, an invitation appears:
boris>
Try to write something, Boris will process it and give the result. If you have a long multi-line expression, Boris will put it together and execute it together. To cancel any operations used
ctrl + c
. By default, all results are returned by the functionvar_dump
boris> $x = 1;
int(1)
boris> $y = 2;
int(2)
boris> "x + y = " . ($x + $y);
string(9) "x + y = 3"
boris> exit;
To exit the utility is used
ctrl + D
.Use in projects
Everything is very simple:
require_once 'lib/autoload.php';
$boris = new \Boris\Boris('myapp> ');
$boris->setLocal(array('appContext' => $appContext));
$boris->start();
Here the utility is initialized with a global variable
appContext
accessible from Boris. It is possible to add callbacks before starting the utility. There are two options for adding them:
$boris->onStart('$foo = 42; $bar = 2; echo "Hello Boris!\n";');
$boris->onStart(function($worker, $scope){
extract($scope);
echo '$foo * $bar = ' . ($foo * $bar) . "\n";
$worker->setLocal('name', 'Chris');
});
First, we pass a line of code that Boris simply executes through
eval
. Then we execute a callback, which exports data from the scope of Boris, performs some actions with them, and then adds a variable $name
to Boris. Link to the repository.
Only registered users can participate in the survey. Please come in.
Useful thing?
- 37.3% Yes 215
- 12.8% No 74
- 49.7% I still do not understand why this is necessary at all 286