Skip to content

Customizing the output

Tejas Manohar edited this page Feb 28, 2015 · 1 revision

After each expression you enter, Boris passes it through an Inspector to get a representation that is useful for debugging. The default is does some nice highlighting of the data types in the value, to make it easier to read at a glance, but you can change this behaviour.

Any object that has an inspect($variable) method may be used for this purpose.

$boris->setInspector(new BlinkInspector());

Boris comes with three alternatives out of the box:

  • \Boris\ColoredInspector, which does data-type highlighting and is the default
  • \Boris\DumpInspector, which uses a simple, but effective var_dump()
  • \Boris\ExportInspector, which uses var_export()

Note that you can change this from inside the REPL too:

boris> $this->setInspector(new \Boris\ExportInspector());
-> NULL
boris> "Test";
-> 'Test'

To further customize object output within \Boris\ColoredInspector, you may subclass and override the objectVars($value) method:

class MyInspector extends \Boris\ColoredInspector {
    public function objectVars($value) {
        if ($value instanceof User) {
            return array('user_id' => $value->getUserId());
        }

        return parent::objectVars($value);
    }
}

This overrides the default behavior of simply calling get_object_vars() on the object, allowing you to display properties that may be otherwise obfuscated behind magic methods or property visibility.

Clone this wiki locally