PHP code example of jdz / monitor

1. Go to this page and download the library: Download jdz/monitor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jdz / monitor example snippets


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;

$monitor->h1('Title');      // <h1>
$monitor->h2('Subtitle');   // <h2>
// ... up to h6()

// 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;');

$monitor->list([
    'Step 1: Data fetched',
    'Step 2: Data validated',
    'Step 3: Data imported',
]);

// String (newlines are converted to <br />)
$monitor->pre("line 1\nline 2");

// Or an array of lines
$monitor->pre(['line 1', 'line 2']);

// 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',
]);

$monitor->addHtmlString('<hr/>');

if ($monitor->hasContent()) {
    $html = (string)$monitor;
}

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('[email protected]');
$mail->set('subject', 'Cron Report');
$mail->send();

$monitor
    ->h1('Report')
    ->p('All systems operational')
    ->list(['API: OK', 'DB: OK', 'Cache: OK'])
    ->box('No errors', '#E8F5E9', '#1B5E20');