References Getting Started Getting Started Architecture Architecture Application Application Window Window WebView WebView Deployment Deployment Components Components Framework Integrations Framework Integrations Examples Examples Community Community github GitHub github Get Started arrow_up_right
Getting Started Getting Started Architecture Architecture Application Application Window Window WebView WebView Deployment Deployment Components Components Framework Integrations Framework Integrations Examples Examples Community Community

Application

Application Configuration Extensions Events Dialog API OS Info API CPU Info API Alert API Getting Started Architecture Application Window WebView Deployment Components Framework Integrations Examples Community

Alert API

The API provides the ability to create alerts (message boxes) with custom messages.

This extension is NOT included by default in the boson-php/runtime and must be installed separately.

Linux is currently not supported and will throw an exception.

Installation

Via Composer:

composer require boson-php/app-ext-alert

After that, add the extension to the config:

new Boson\ApplicationCreateInfo(
    extensions: [
        ...Boson\ApplicationCreateInfo::DEFAULT_APPLICATION_EXTENSIONS,
        // ...
        new Boson\Api\Alert\AlertExtension(),
    ],
);

Usage

You can access the subsystem using Application::$alert property.

$app = new Boson\Application();

$app->alert; // Access to Alert API

Creating

To create an alert, you should use the create() method, passing there a configuration DTO Boson\Api\Alert\AlertCreateInfo with a title and a message.

use Boson\Application;
use Boson\Api\Alert\AlertCreateInfo;

$app = new Application();

$app->alert->create(new AlertCreateInfo(
    title: 'Title',
    text: 'Message',
));

After the call, you will receive a corresponding message box.

On Windows:

Windows

On macOS:

macOS

The alert call is blocking and stops the application until the user makes a choice (clicks on the button).

Buttons

The alert invocation returns the clicked button as a result. By default, there is only one button, like Boson\Api\Alert\AlertButton::Ok.

$button = $app->alert->create(new AlertCreateInfo( 
    // ...
));

if ($button === Boson\Api\Alert\AlertButton::Ok) {
    echo 'OK button clicked!';
}

The execution result may return null. This indicates an unexpected or abnormal termination of the alert. In most cases, this should not happen.

Cancellation

You can add a second "Cancel" button using the cancel: true configuration option.

$button = $app->alert->create(new AlertCreateInfo(
    // ...
    cancel: true,
));

if ($button === Boson\Api\Alert\AlertButton::Ok) {
    echo 'OK button clicked!';
}

if ($button === Boson\Api\Alert\AlertButton::Cancel) {
    echo 'Cancel button clicked!';
}

Icons

By default, no icon is used when displaying an alert (or the system icon is used). To specify a custom icon, use the icon configuration field.

The icon can contain one of the following possible values:

  • null – Default value (No Icon)

  • Boson\Api\Alert\AlertIcon::Info – Information system icon. Info

  • Boson\Api\Alert\AlertIcon::Warning – Warning system icon Warning

  • Boson\Api\Alert\AlertIcon::Error – Error system icon Error

github discord telegram Get started Documentation Contribution Guide License Release Notes BOSON PHP © 2025. All Rights Reversed.