Where code meets community
ALPHA

The Insight API is not supported by the FirePHP Firefox Extension.

The new Insight API takes an object oriented approach and provides many more features than the traditional FirePHP API. See Overview for a comparison:

define('INSIGHT_CONFIG_PATH', '...');
require_once('FirePHP/Init.php');

$inspector = FirePHP::to('page');
$console = $inspector->console();
$console->log('Hello World');

Many methods in the Insight API may be chained and work by successively cloning and augmenting a message object which is finally sent off. In the example above FirePHP::to() creates a message object targeting the page context. The context is further refined to point to a console. One or more messages can now be sent to this same context.

While some of the method names in the new Insight API are called the same as in the FirePHP API they take different arguments.

Activation & Authorization

The Insight API must be activated and authorized to record and send data to the client. It is activated by default and may be deactivated from the client. Authorization occurs on a per-hostname basis. See Authorizing for more information.

If Insight is deactivated from the client the FirePHP API will also be deactivated but only if including FirePHP using the /FirePHP/*.php files.

Contexts: FirePHP::to('<target>')

To record/log any data a context must be initialized by specifying a target:

  • page - Obtain a message context that will send messages to the page target. These messages will show up in the Firebug or DeveloperCompanion consoles.

    $inspector = FirePHP::to('page');
    $console = $inspector->console();
    $console->log('Hello World');

    See Insight/Console API below for how to send different kinds of messages to this target.

  • request - Obtain a message context that will send messages to the request target. These messages will show up in the Companion Window after an *inspect* has been triggered.

    $inspector = FirePHP::to('request');
    $console = $inspector->console('<Tab Label>');
    $console->log('Hello World');

    The <Tab Label> is optional and defaults to Console.

    See Insight/Console API below for how to send different kinds of messages to this target.

  • package - Obtain a message context that will record information about the application package. This info is used in the Companion Window when displaying information about a request.

    See Package API below for how to use this target.

  • controller - Obtain a message context that is used to control the client.

    See Insight/Control API below for how to use this target.

Plugins: FirePHP::plugin('<name>')

Get a plugin by specifying a name. Supported plugins are:

  • firephp - The firephp plugin provides utility functions to make development and monitoring easier.

    See Insight/FirePHP API for how to use this plugin.

Insight/Console API

The Insight/Console API is used to send messages to a given target.

$console = FirePHP::to('<target>')->console('<Tab Label>');

The <Tab Label> is optional and defaults to Console.

The <target> defines where the messages will show up. See FirePHP::to('<target>') above.

Variable Truncation

Large variables are truncated when traversing (nested arrays and object members) by preventing the transmission of data, beyond certain limits, to the client.

By default variables are truncated according to the encoder options. To avoid truncating variables use:

$console = $console->nolimit();

Calling nolimit(false) will reset the option and cause variables to be truncated again.

String Trimming

Large strings are trimmed when displayed in the client console.

By default pure string variables are trimmed to 500 characters and string values as part of arrays or objects to 50 characters. To prevent string trimming use:

$console = $console->notrim();

Calling notrim(false) will reset the option and cause strings to be trimmed again.

Message Expansion

By default logged messages are contracted when displayed in the console. To expand any message use:

$console = $console->expand();

Use this to log expanded tables, groups, traces and general log messages.

Showing the Console

By default logged messages are tracked by the client but not shown to the user unless they already have the console open. To force the console to show use:

$console->show();

If logging to the Firebug Console you must have Firebug open and the Firebug Console and Net panels enabled.

Options

Individual encoder (and other) options can be set as needed:

$console = $console->option('<Name>', <Value>); // or
$console = $console->options(array(
    '<Name>' => <Value>
));

Calling option() or options() without a value argument will return the current value.

Possible options are as follows (default values are shown):

encoder.depthNoLimit : false
encoder.lengthNoLimit : false
encoder.maxDepth : 5
encoder.maxStringLength : 5000
encoder.maxArrayDepth : 3
encoder.maxArrayLength : 25
encoder.maxObjectDepth : 3
encoder.maxObjectLength : 25
encoder.trace.offsetAdjustment : 0  // affects file/line logic
encoder.trace.maxLength : -1  // no maximum
encoder.exception.traceMaxLength : -1  // no maximum
string.trim.enabled : <undefined>  // force/prevent string trimming in UI
string.trim.length : 50  // string trim length
string.trim.newlines : true  // force/prevent string newline expansion
file : <automatic>  // sets file for message
line : <automatic>  // sets line for message

Encoder option defaults may be set by configuration. See Advanced Configuration.

Class Member Filters

Manually setting a class member filter:

$filter = array(
    'classes' => array(
        '<ClassName>' => array('<MemberName>')
    )
);
$console->filter($filter)-> [Console API]

Annotation-based class member filter:

class <Name> {
    /**
     * @insight filter=on
     */
    public $var;
}

Logging Variables

$console->log($Variable);

Message Priorities

$console->log($Variable);
$console->info($Variable);
$console->warn($Variable);
$console->error($Variable);

Message Labels

$console->label('<Label>')-> [Console API]

Tables

$header = array('Column 1 Heading', 'Column 2 Heading');
$table = array(
    array('Row 1 Column 1 Value', 'Row 1 Column 2 Value'),
    array($Variable_r2c1, $Variable_r2c2)
);
$console->table('<Title>', $table);
$console->table('<Title>', $table, $header);

Stack Traces

$console->trace('<Label>');

Groups

Logging to a group by name:

$console->group('<Name>', '<Title>')-> [Console API]

Directing multiple messages to a group context:

$group = $console->group('<Name>', '<Title>')->open();
$console-> [Console API]
$group->close();

Specifying a <Name> is optional.

If the <Title> argument is not provided the first message logged to the group becomes the title.

When opening groups they must be closed in the same order!

You can log to the same group in different parts of an application without keeping track of the $group variable as long as the group name is the same. The group will appear in the group hierarchy (if multiple nested groups) depending on where a group is first logged.

Conditional Logging

Conditional logging is currently only supported by DeveloperCompanion when logging to the request target and inspecting via the Companion Window!

By default all logged messages are sent to the client. To conditionally send specific messages, only if requested by client, one or multiple messages may be wrapped in an on() handler.

Conditional logging by name:

$console->on('<Name>')-> [Console API]

Directing multiple messages to a conditional context:

$on = $console->on('<Name>')->open();
$console-> [Console API]
$on->close();

When opening contexts they must be closed in the same order!

Declared conditions may be used for flow control:

if($console->on('<Name>')->is(true)) {
    // conditionally execute
}

It is imperative that this feature is only used for debugging and development related purposes. It will only ever evaluate to TRUE if an authorized client is detected and the condition is enabled on the client.

Insight/Package API

The Insight/Package API is used to record information about the application package.

$package = FirePHP::to('package');

Quick Links

To add links for a package that will be displayed as buttons in the Companion Window use:

$package->addQuickLink('Link 1', 'http://www.firephp.org/');
// or
$package->addQuickLink('Link 2', array(
    'target' => 'window',  // tab (default), window or hidden
    'url' => 'http://www.firephp.org/'
));

Links added this way will augment links already added via the package.json config file. See here for more info.

Insight/Control API

The Insight/Control API is used to control the client in the context of the request.

$controller = FirePHP::to('controller');

Triggers

Schedule an inspect event for the current request which will be executed by the client once the entire response is received by the browser. This will cause the client to focus on the data sent while the request executed.

$controller->triggerInspect();

This is equivalent to $console->show();

There are several ways to inspect a given request.

Insight/FirePHP API

The Insight/FirePHP API provides utility functions to make development and monitoring easier.

$firephp = FirePHP::plugin('firephp');

Convenience Logging for Ad-hock Debugging

Fumbling with $console objects can become tedious if you just want to quickly log a variable during development. A p() shortcut function can be made available to easily print variables to a console.

// Log p() messages to the Firebug Console
$firephp->declareP();

// Log p() messages to a request console called Ad-hock
$firephp->declareP('Ad-hock', true);

// Log p() messages to the provided $console
$console = FirePHP::to('request')->console('Debug');
$firephp->declareP($console, true);

The second argument to declareP() specifies whether an inspect for the request should be triggered. This will automatically open the Companion Window and load the request data as soon as the p() function is used.

Once declared, to print variables simply use:

p($variable); // or
p($variable, 'Label');

The p() calls should not stay in your code and are intended for use during development only!

Information

Log the current FirePHP version to a FirePHP console.

$firephp->logVersion(); // or
$firephp->logVersion($console);

Recording Environment

Send information about the PHP environment to an Environment console.

$firephp->recordEnvironment(); // or
$firephp->recordEnvironment($console);

Constants

Insight Constants

define('INSIGHT_CONFIG_PATH', <string>);
define('INSIGHT_IPS', <string>);
define('INSIGHT_AUTHKEYS', <string>);
define('INSIGHT_PATHS', <string>);
define('INSIGHT_SERVER_PATH', <string>);

See Install for more information.

FirePHP Constants

define('FIREPHP_ACTIVATED', <boolean>);

May be set to FALSE prior to including FirePHP to force-deactivate FirePHP. This will cause all logging calls to be ignored on the server and no data will be sent to the client as if FirePHP was never installed on the server.

If the constant is not set prior to including FirePHP it will be automatically set to TRUE (if client detected, FALSE otherwise) when FirePHP loads and can be used in application code to enable logging and debugging facilities as needed if applicable.

if(FIREPHP_ACTIVATED) ...

If set to TRUE prior to including FirePHP, FirePHP will be force-activated even if no authorized client is detected. If no authorized client is detected, data will be collected but not exposed. This is useful when using a payload listener to write the data to disk (or alternate storage) for later access. See Advanced Features below for more information.

Advanced Features

Payload Listener

A payload listener may be registered that will fire at the end of the request. The listener will be provided with all the data collected during the request. This is useful in cases where the data should be written to disk or alternate storage for later debugging purposes.

Typically data will only be collected if an authorized client is detected. To force-activate data collection use the FIREPHP_ACTIVATED constant. See Constants.

define('FIREPHP_ACTIVATED', true);
require_once('FirePHP/Init.php');        
class PayloadListener {
    public function onPayload($request, $payload) {
        echo($payload);
    }
}
Insight_Helper::getInstance()->registerListener('payload', new PayloadListener());

To send the collected payload to a client (at a later point in time) see Send Raw Payload below.

Send Raw Payload

Previously collected payload data (see Payload Listener above) may be relayed to a client as follows:

require_once('FirePHP/Init.php');
Insight_Helper::getInstance()->relayPayload($payload)

Homepage: Sourcemint.com

Status

Sourcemint is incomplete ALPHA technology and continuously evolving in sync with underlying and related projects. Production ready aspects will be documented and made available in time. Your Feedback is welcome and appreciated!

Who

Sourcemint is one of the results of intense focus by Christoph Dorn over the past several years and continuous exploration throughout Christoph's interest in software development over the past 15+ years.

Sourcemint is the love child of one person guided by the voices of passionate developers at the top of their game who are leading the industry into a new era of software development.

What

Sourcemint is an integral part of Christoph's work intended to realize his dream of one global toolchain under which components may be arbitrarily combined into maintainable mission critical systems by providing an all-encompassing and organized package repository from which consistent and autonomic systems may be built.

Sourcemint provides an automated software building and integration service as well as an intelligent software delivery network to distribute built software to all deployed systems and Internet users.

This means an arbitrary (code, configuration, network, ...) change may be made to a software system which can then be automatically built, tested, distributed and deployed. Every change constitutes a completely new system made possible by the fact that changes, any changes, are cheap and fully tested in every way before going live.

Just imagine what this means in your daily work.

Why

Automated software builds, continuous integration processes, streamlined issue trackers, community supported software, source control, online collaboration and automated cloud deployment have wet our appetite but hardly scratch the surface of what it actually means to have a completely automated production cycle from idea to delivery. The full potential is only realized once these separate solutions addressing different areas work together harmoniously.

What has been missing is new ways of looking at how to build software.

How

Christoph's work provides a new way to build software that is not necessarily new in the sense of ideas or technology but rather arrangement and timing. Christoph has through exploration and experimentation distilled current cutting edge technology, knowledge and wisdom into a toolchain platform called PINF available open source under the MIT license to realize a new breed of software.

Imagine software and systems that just work and are a pleasure to maintain.

Sourcemint is built entirely on PINF, as is all of Christoph's work, and can be used by any developer to tap into the power of the PINF approach to build open source or commercial libraries, frameworks, applications, systems and services.

Christoph's hope is that PINF and related projects will provide a foundation for developers to cooperate more widely and experiment with new ideas by eliminating some of the major constraints imposed by traditional toolchains. Traditional toolchains create systems that typically rot because they are practically impossible to refactor. We need a toolchain such as PINF which has refactorability designed into its core.

Let's create software that breathes with life and is in large part self-sustaining!

You

Join Christoph in his mission to help you, the developer, and help yourself by broadly applying the tools and approaches you know work to all of your work. Lean on PINF, your mind is begging you. Learn it, teach others, and let your inspiration soar!

Follow Sourcemint and PINF on twitter to watch for news of cutting-edge tools, tutorials and services coming online. You can also follow Christoph's work directly.