PHP code example of soloterm / notify

1. Go to this page and download the library: Download soloterm/notify 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/ */

    

soloterm / notify example snippets


use SoloTerm\Notify\Notify;

// Simple notification (message only)
Notify::send('Build complete!');

// Notification with title and body
Notify::send('All 142 tests passed in 3.2s', 'Tests Passed');

// Check if notifications are supported
if (Notify::canNotify()) {
    Notify::send('This will work!');
}

// Get detected terminal
$terminal = Notify::getTerminal(); // 'iterm2', 'kitty', 'wezterm', etc.

// Get selected protocol
$protocol = Notify::getProtocol(); // 'osc9', 'osc777', 'osc99'

// After a long build process
$startTime = microtime(true);
// ... build logic ...
$duration = round(microtime(true) - $startTime, 2);
Notify::send("Completed in {$duration}s", 'Build Finished');

// After running tests
$result = $testsPassed ? 'All tests passed!' : 'Some tests failed';
$title = $testsPassed ? 'Tests Passed' : 'Tests Failed';
Notify::send($result, $title);

// In a queue worker
while ($job = $queue->pop()) {
    $job->process();
    Notify::send("Processed: {$job->name}", 'Queue');
}

use SoloTerm\Notify\Notify;

// Send with explicit urgency
Notify::send('Background task done', 'Info', Notify::URGENCY_LOW);
Notify::send('Build complete', 'Success', Notify::URGENCY_NORMAL);
Notify::send('Server down!', 'Alert', Notify::URGENCY_CRITICAL);

// Convenience methods
Notify::sendLow('Low priority message');
Notify::sendCritical('Critical alert!');

// Set default urgency for all notifications
Notify::setDefaultUrgency(Notify::URGENCY_LOW);

// Send notification with an ID
Notify::send('Building... 0%', 'Build', id: 'build-progress');

// Update the same notification
Notify::send('Building... 50%', 'Build', id: 'build-progress');
Notify::send('Building... 100%', 'Build', id: 'build-progress');

// Close/dismiss a notification by ID
Notify::close('build-progress');

// Check if the terminal supports IDs
$caps = Notify::capabilities();
if ($caps['supports_id']) {
    // Use notification IDs
}

// Fallback is enabled by default - disable it if needed
Notify::disableFallback();

// Re-enable fallback
Notify::enableFallback();

// Check if fallback is available
if (Notify::canFallback()) {
    echo "System notifications available as fallback\n";
}

// Send using any available method (OSC or fallback)
Notify::sendAny('This works everywhere!', 'Hello');

// Send directly via external tools (bypassing OSC)
Notify::sendExternal('Message', 'Title');

// Send bell character (works everywhere)
Notify::bell();

// Try notification first, then external fallback, then bell
Notify::sendOrBell('Task complete', 'Done');

$caps = Notify::capabilities();
// Returns:
// [
//     'terminal' => 'kitty',
//     'protocol' => 'osc99',
//     'supports_title' => true,
//     'supports_urgency' => true,
//     'supports_id' => true,
//     'supports_progress' => true,
//     'in_multiplexer' => false,
//     'fallback_available' => true,
// ]

// List all known terminals and their support
$terminals = Notify::supportedTerminals();
// ['kitty' => 'osc99', 'iterm2' => 'osc9', 'alacritty' => null, ...]

// Force OSC 777 regardless of detected terminal
Notify::forceProtocol('osc777');
Notify::send('Using OSC 777', 'Forced');

// Reset to auto-detection
Notify::forceProtocol(null);

if (Notify::inTmux()) {
    echo "Running inside tmux\n";
}

if (Notify::inScreen()) {
    echo "Running inside GNU Screen\n";
}

// Useful for testing or when terminal changes
Notify::reset();

// Check if supported
if (Notify::supportsProgress()) {
    // Show progress (0-100)
    Notify::progress(50);

    // Different states
    Notify::progressError(75);        // Red - error state
    Notify::progressPaused(60);       // Yellow - paused
    Notify::progressIndeterminate();  // Pulsing - unknown duration

    // Clear when done
    Notify::progressClear();
}

echo Notify::hyperlink('https://example.com', 'Click here');
echo Notify::hyperlink('https://example.com'); // URL as display text

Notify::requestAttention();           // Bounce dock icon
Notify::fireworks();                  // Fireworks animation
Notify::stealFocus();                 // Bring window to front