jdz / monitor
JDZ html formatter for debug
1.0.3
2026-04-09 16:51 UTC
Requires
- php: >=8.2
Requires (Dev)
- jdz/mailer: ^1.0
- phpunit/phpunit: ^11.0
Suggests
- jdz/mailer: To send the monitoring by mail.
Provides
None
Conflicts
None
Replaces
None
README
Formatted HTML monitoring output for PHP processes. Build structured HTML reports (headings, paragraphs, lists, boxes, preformatted blocks) to display in a browser or send by email via jdz/mailer.
Installation
composer require jdz/monitor
Requirements
- PHP >= 8.2
Usage
Basic Example
use JDZ\Monitor\Monitor; $monitor = new Monitor(); $monitor->h1('Process Report'); $monitor->p('Process completed successfully.'); $monitor->p('42 items processed', 'Total'); echo (string)$monitor;
Headings
$monitor->h1('Title'); // <h1> $monitor->h2('Subtitle'); // <h2> // ... up to h6()
Paragraphs
// Simple paragraph $monitor->p('Some text'); // With a bold label prefix $monitor->p('150ms', 'Duration'); // Output: <p><strong>Duration</strong>: 150ms</p> // With inline style $monitor->p('All good', 'Status', 'color:green;');
Lists
$monitor->list([ 'Step 1: Data fetched', 'Step 2: Data validated', 'Step 3: Data imported', ]);
Preformatted Content
// String (newlines are converted to <br />) $monitor->pre("line 1\nline 2"); // Or an array of lines $monitor->pre(['line 1', 'line 2']);
Colored Boxes
// Simple string box $monitor->box('Some content', '#E8F5E9', '#1B5E20'); // Mixed content box with structured objects $monitor->box([ (object)['h' => 'Details', 'level' => 3], (object)['content' => '150ms', 'label' => 'Duration'], (object)['pre' => "SELECT * FROM users"], (object)['list' => ['cache: HIT', 'db: 2 queries']], 'Plain string line', ]);
Raw HTML
$monitor->addHtmlString('<hr/>');
Checking for Content
if ($monitor->hasContent()) { $html = (string)$monitor; }
Sending by Email
Pair with jdz/mailer to email the report:
use JDZ\Monitor\Monitor; use JDZ\Mailer\Mailer; $monitor = new Monitor(); $monitor->h1('Cron Report'); $monitor->p('Everything OK'); $mail = new Mailer(); $mail->setContent([ 'isHtml' => true, 'content' => (string)$monitor, ]); $mail->addRecipient('admin@example.com'); $mail->set('subject', 'Cron Report'); $mail->send();
Fluent Interface
All content methods return $this, so calls can be chained:
$monitor ->h1('Report') ->p('All systems operational') ->list(['API: OK', 'DB: OK', 'Cache: OK']) ->box('No errors', '#E8F5E9', '#1B5E20');
Testing
composer test # or vendor/bin/phpunit
License
This project is licensed under the MIT License - see the LICENSE file for details.