Skip to content

Commit c1899aa

Browse files
committed
Actualize readme
1 parent 6afb3ed commit c1899aa

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ And much easier than that =)
4848
- [HTML Content](#webview-html-content)
4949
- [Navigation to URL](#webview-url-navigation)
5050
- [Navigation URL info](#webview-url-info)
51+
- [Custom Protocols](#webview-custom-protocols)
5152
- **JavaScript**
5253
- [Scripts](#webview-scripts)
5354
- [Code Evaluation](#webview-code-evaluation)
@@ -602,6 +603,67 @@ $app->events->addEventListener(WebViewNavigated::class, function () use ($app) {
602603
```
603604

604605

606+
### WebView Custom Protocols
607+
608+
You can register custom scheme/protocols and intercept standard one.
609+
610+
To register global application middleware you may define list of middleware
611+
for the given protocol.
612+
613+
```php
614+
use Boson\Application;
615+
use Boson\ApplicationCreateInfo;
616+
use Boson\Http\Middleware\HandlerInterface;
617+
use Boson\Http\Middleware\MiddlewareInterface;
618+
use Boson\Http\RequestInterface;
619+
use Boson\Http\Response;
620+
621+
$middleware = new class implements MiddlewareInterface {
622+
public function handle(RequestInterface $request, HandlerInterface $handler): Response
623+
{
624+
return new Response('<h1>Hello from "' . $request->url . '"!</h1>');
625+
}
626+
};
627+
628+
$app = new Application(new ApplicationCreateInfo(
629+
// List of middleware for "https" protocol
630+
schemes: [ 'https' => [$middleware] ],
631+
));
632+
633+
$app->webview->url = 'https://hello.world/';
634+
```
635+
636+
To register middleware for a specific window (webview) for a specified protocol,
637+
you should use direct addition of middleware to the middleware list for webview.
638+
639+
```php
640+
use Boson\Application;
641+
use Boson\ApplicationCreateInfo;
642+
use Boson\Http\Middleware\HandlerInterface;
643+
use Boson\Http\Middleware\MiddlewareInterface;
644+
use Boson\Http\RequestInterface;
645+
use Boson\Http\Response;
646+
647+
$app = new Application(new ApplicationCreateInfo(
648+
// Adding "https" protocol interception support
649+
schemes: [ 'https' ],
650+
));
651+
652+
// Select pipeline for "https" protocol
653+
$pipeline = $app->webview->schemes->find('https');
654+
655+
// Add middleware for "https" protocol for main window
656+
$pipeline?->append(new class implements MiddlewareInterface {
657+
public function handle(RequestInterface $request, HandlerInterface $handler): Response
658+
{
659+
return new Response('<h1>Hello from "' . $request->url . '"!</h1>');
660+
}
661+
});
662+
663+
$app->webview->url = 'https://hello.world/';
664+
```
665+
666+
605667
### WebView Code Evaluation
606668

607669
You can execute arbitrary code directly on current WebView

0 commit comments

Comments
 (0)