📜 ⬆️ ⬇️

Boris is a small but reliable REPL for php

REPL is at python, ruby, clojure. REPL - read-eval-print loop. If you describe in a pseudocode what a REPL is, it will look something like this:
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 give a message about this, but continue to work waiting for the new code.

image

Requirements



Installation


Boris is available through composer:
 composer require d11wtq/boris dev-master 

Or in the old manner:
 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, use ctrl + c . By default, all results are var_dump by the var_dump function var_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, use 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 the global appContext variable available 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 in a line of code that Boris simply executes via eval . Then we execute a callback, which exports data from the scope of Boris, performs some actions with them, and then adds the $name variable to Boris.

Link to the repository.

Source: https://habr.com/ru/post/179145/


All Articles