Debug
From PHPDevShell
PHPDevShell version 2.7.1 comes with a built-in debugger. It's used all around PHPDevShell core systems, and can be also used by your scripts.
The idea is to sent, at given points of the code, various data in a channel other that the web page, so it doesn't disturb the html, javascript, layout, and so. This channel carry the data to various backends, which can be monitored by the developer.
Note: as any debugging mechanism, it can expose sensitive data, so you're very advised to turn it off on production systems. Furthermore, the flow of debug data takes a considerable amount of time (just enabling the debugger makes your script 4 times slower).
Backends are ways of displaying data; at the moment, the debugger can use the server error log (pretty lame) and the FirePHP plugin for FireBug (pretty cool, you must have it!). These backends can be enabled independently.
Level is a number which sets the verbosity of the data. The higher the number, the more messages will flood your backend. For example, if level is ERROR you'll only messages noted as related to major problems; if level is INFO, you'll have these, plus the warnings and info messages.
Domains are semantic way to group related data. For example, enabling the domain "db" will allow you to see the messages generated by the database subsystem (level filtering still applies, of course). PHPDevShell uses these domains: core, db, navigation, security, template. By default, your scripts run in the "user" domain.
Usage
The basic function is "_log()"; it's meant to be used as static (i.e. permanent) info point. In FirePHP, it appears with a little blue ! icon.
$this->_log('Killroy was here');
It's the shortest form. You can also used several other functions:
$this->debug_instance()->info('Killroy was here');$this->debug_instance()->warning('He seemed to be mad');$this->debug_instance()->error('He broke your code');$this->debug_instance()->log('Time spent: '.$my_time.' seconds');
Each implies the corresponding level of verbosity. The first three can be showed with a corresponding icon. When a structured variable is given (such as an array or an object), it will be expanded.
Another function can be useful:
$this->debug_instance()->dump($my_array);
Similar to log(), but the data is sent regardless of the level setting. In FirePHP, it's showed not in the Console panel, but in the "server" tab of the request in the Network panel.
Configuration
The debugger is configured in the same way as other subsystems. These are the configuration options:
$configuration['debug']['enable'] = true;- The main switch to enable/disable data flow. Note that switching domain can change this setting.
$configuration['debug']['level'] = 4;- Level of verbosity (see above). Possible values: DEBUG = 4, INFO = 3,WARN = 2, ERROR = 1, LOG = 0.
$configuration['debug']['firePHP'] = true;- Wether to activate FirePHP backend or not
$configuration['debug']['serverlog'] = true;- Wether to activate HTTP error log backend or not
$configuration['debug']['domains'] = array('authlib', 'test', 'user', 'core');- An array of string, the list of active semantic domains. A domain MUST be listed here for the data to be sent.
Documentation to Follow
- ->debug
- dump ($data, $label = 'data')
- log ($data, $label = null)
- debug ($data)
- info ($data)
- warn ($data)
- warning ($data)
- error ($datal)
- process ($data)

