decodelabs / glitch
Better tools for when things go wrong
Installs: 19 512
Dependents: 3
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: ^8.4
- decodelabs/coercion: ^0.3.5
- decodelabs/enlighten: ^0.9.4
- decodelabs/exceptional: ^0.6.3
- decodelabs/kingdom: ^0.1
- decodelabs/monarch: ^0.2
- decodelabs/nuance: ^0.1.9
- decodelabs/remnant: ^0.1.2
- psr/log: ^3.0.2
- symfony/polyfill-mbstring: ^1.33
Requires (Dev)
- decodelabs/phpstan-decodelabs: ^0.7
- symfony/var-dumper: ^5|^6|^7
- dev-develop / 0.21.x-dev
- v0.21.0
- v0.20.2
- v0.20.1
- v0.20.0
- v0.19.4
- v0.19.3
- v0.19.2
- v0.19.1
- v0.19.0
- v0.18.20
- v0.18.19
- v0.18.18
- v0.18.17
- v0.18.16
- v0.18.15
- v0.18.14
- v0.18.13
- v0.18.12
- v0.18.11
- v0.18.10
- v0.18.9
- v0.18.8
- v0.18.7
- v0.18.6
- v0.18.5
- v0.18.4
- v0.18.3
- v0.18.2
- v0.18.1
- v0.18.0
- v0.17.7
- v0.17.6
- v0.17.5
- v0.17.4
- v0.17.3
- v0.17.2
- v0.17.1
- v0.17.0
- v0.16.5
- v0.16.4
- v0.16.3
- v0.16.2
- v0.16.1
- v0.16.0
- v0.15.10
- v0.15.9
- v0.15.8
- v0.15.7
- v0.15.6
- v0.15.5
- v0.15.4
- v0.15.3
- v0.15.2
- v0.15.1
- v0.15.0
- v0.14.8
- v0.14.7
- v0.14.6
- v0.14.5
- v0.14.4
- v0.14.3
- v0.14.2
- v0.14.1
- v0.14.0
- v0.13.3
- v0.13.2
- v0.13.1
- v0.13.0
- v0.12.0
- v0.11.1
- v0.11.0
- v0.10.0
- v0.9.0
- v0.8.0
- v0.7.0
- v0.6.0
- v0.5.0
- dev-main
This package is auto-updated.
Last update: 2025-08-21 13:43:08 UTC
README
Better tools for when things go wrong
Glitch is a standalone PHP package designed to dramatically improve error handling and inspection when developing your applications.
The project aims to provide deep data inspection tools and an Exception handling interface.
Installation
Glitch should be installed via composer
composer require decodelabs/glitch
Usage
use DecodeLabs\Glitch; use DecodeLabs\Monarch; $glitch = Monarch::getService(Glitch::class); $glitch->dump('hello');
Setup
Otherwise, Glitch works out of the box without any special setup. There are however some optional steps you can take to customise operation.
Register as the default error handler:
$glitch->registerAsErrorHandler();
Pass the microtime()
of initial app launch for timing purposes:
$glitch->setStartTime(microtime(true));
Dumps
Dump anything and everything easily, using simple global functions. The functions mirror those used in Symfony/VarDumper, maintaining compatibility by using Symfony's VarDumper interface if it is already loaded.
class MyThing {} $myObject = new MyThing(); // This will dump the object and carry on dump($myObject); // This will dump the object and exit dd($myObject);
Renderers
The resulting dump UI (when using the HTML renderer, the default option) is injected into an iframe at runtime so can be rendered into any HTML page without breaking anything. If the page is otherwise empty, the iframe will expand to fill the viewport if possible.
The dump output is rendered by an instance of DecodeLabs\Glitch\Renderer
which can be overridden on the default Service at startup. The Html
renderer is loaded under http sapi, the Cli
renderer is used when under the CLI sapi.
Custom renderers may convert Entities
to other output formats depending on where they should be sent, such as Xml or Json for example. The Renderer system uses Nuance to inspect and render the data, please see that project for more information on how to create custom renderers.
Custom colours
The HTML renderer uses css variables to style individual element colours and can be overridden with custom values. Create a custom css file with variable overrides:
:root { --string: purple; --binary: green; }
See colours.scss for all of the current colour override options.
Then load the file into the HTML renderer:
$glitch->getRenderer()->setCustomCssFile('path/to/my/file.css');
Transports
Once rendered, the dump information is delivered via an instance of DecodeLabs\Glitch\Transport
, also overridable on the default Service. It is the responsibility of the Transport
to deliver the rendered dump.
By default, the render is just echoed out to STDOUT
, however custom transports may send information to other interfaces, browser extensions, logging systems, etc.
Custom dumps
You can customise how your own class instances are dumped by implementing DecodeLabs\Nuance\Dumpable
interface.
Please see the Nuance documentation for more information on how to do this.
Licensing
Glitch is licensed under the MIT License. See LICENSE for the full license text.