BOSON Help

Functions API

You can register custom PHP functions to call them from the client.

The API is available in the WebView::$functions property.

$app = new Boson\Application(); $app->webview->functions; // Access to Functions API

Binding

You can create a function that can be called directly from WebView.

$app = new Boson\Application(); $app->webview->scrtips->bind('foo', function () { var_dump('Executed!'); });

Or set functions list from configuration.

$app = new Boson\Application( window: new Boson\Window\WindowCreateInfo( webview: new Boson\WebView\WebViewCreateInfo( functions: [ 'foo' => function () { var_dump('Executed!'); }, ], ), ), );

Also, don't forget that PHP has a simple way to pass functions using first class callable syntax. Thus, a simple registration of the var_dump() function looks like this:

$app = new Boson\Application(); $app->webview->bind('var_dump', var_dump(...));

Custom Context

You may have noticed that functions are registered globally, which is not always convenient.

To register functions in a context, you can use the dot-syntax, which allows you to register a function in a specific JavaScript context.

$app = new Boson\Application(); $app->webview->bind('example.some', $example->some(...)); $app->webview->bind('example.any', $example->any(...));

Access to such functions from the client side is also done through a dot.

example.some('hello'); example.any('world');

Unbinding

In some cases, you may need to remove previously registered functions. To do this, use the unbind() method.

$app = new Boson\Application(); $app->webview->scripts->unbind('foo');
08 May 2025