\BorisBoris

Boris is a tiny REPL for PHP.

Summary

Methods
Properties
Constants
__construct()
onStart()
onFailure()
setLocal()
setPrompt()
setInspector()
start()
No public properties found
VERSION
No protected methods found
No protected properties found
N/A
No private methods found
$_prompt
$_historyFile
$_exports
$_startHooks
$_failureHooks
$_inspector
N/A

Constants

VERSION

VERSION = "1.0.8"

Properties

$_prompt

$_prompt : 

Type

$_historyFile

$_historyFile : 

Type

$_exports

$_exports : 

Type

$_startHooks

$_startHooks : 

Type

$_failureHooks

$_failureHooks : 

Type

$_inspector

$_inspector : 

Type

Methods

__construct()

__construct(  $prompt = 'boris> ',   $historyFile = null) 

Create a new REPL, which consists of an evaluation worker and a readline client.

Parameters

$prompt
$historyFile

onStart()

onStart(mixed  $hook) 

Add a new hook to run in the context of the REPL when it starts.

Parameters

mixed $hook

The hook is either a string of PHP code to eval(), or a Closure accepting the EvalWorker object as its first argument and the array of defined local variables in the second argument.

If the hook is a callback and needs to set any local variables in the REPL's scope, it should invoke $worker->setLocal($var_name, $value) to do so.

Hooks are guaranteed to run in the order they were added and the state set by each hook is available to the next hook (either through global resources, such as classes and interfaces, or through the 2nd parameter of the callback, if any local variables were set.

Examples

example where one hook sets the date and another prints it in the REPL. $boris->onStart(function($worker, $vars){ $worker->setLocal('date', date('Y-m-d')); }); $boris->onStart('echo "The date is $date\n";');
** File not found : Contrived **

onFailure()

onFailure(mixed  $hook) 

Add a new hook to run in the context of the REPL when a fatal error occurs.

Parameters

mixed $hook

The hook is either a string of PHP code to eval(), or a Closure accepting the EvalWorker object as its first argument and the array of defined local variables in the second argument.

If the hook is a callback and needs to set any local variables in the REPL's scope, it should invoke $worker->setLocal($var_name, $value) to do so.

Hooks are guaranteed to run in the order they were added and the state set by each hook is available to the next hook (either through global resources, such as classes and interfaces, or through the 2nd parameter of the callback, if any local variables were set.

Examples

example if your project requires some database connection cleanup: $boris->onFailure(function($worker, $vars){ DB::reset(); });
** File not found : An **

setLocal()

setLocal(array|string  $local,   $value = null) 

Set a local variable, or many local variables.

Parameters

array|string $local
$value

Examples

a single variable $boris->setLocal('user', $bob);
** File not found : Setting **
many variables at once $boris->setLocal(array('user' => $bob, 'appContext' => $appContext)); This method can safely be invoked repeatedly.
** File not found : Setting **

setPrompt()

setPrompt(string  $prompt) 

Sets the Boris prompt text

Parameters

string $prompt

setInspector()

setInspector(object  $inspector) 

Set an Inspector object for Boris to output return values with.

Parameters

object $inspector

any object the responds to inspect($v)

start()

start() 

Start the REPL (display the readline prompt).

This method never returns.