Skip to content

Commit 58262be

Browse files
committed
Add whoops error handler
1 parent 2f7471b commit 58262be

28 files changed

+662
-370
lines changed

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
}
4343
},
4444
"require-dev": {
45+
"filp/whoops": "^2.18",
4546
"phpunit/phpunit": "^12.0"
4647
},
4748
"autoload-dev": {
@@ -64,6 +65,9 @@
6465
"*": "dist"
6566
}
6667
},
68+
"suggest": {
69+
"filp/whoops": "Required for friendly error pages in development (^2.18)"
70+
},
6771
"minimum-stability": "dev",
6872
"prefer-stable": true
6973
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\WebView\Api\Schemes\Event {
6+
7+
use Boson\Contracts\Http\RequestInterface;
8+
use Boson\Contracts\Http\ResponseInterface;
9+
use Boson\WebView\WebView;
10+
11+
/**
12+
* @deprecated Please use {@see SchemeRequestReceive} intention instead
13+
*/
14+
final class SchemeRequestReceived extends SchemesApiIntention
15+
{
16+
public function __construct(
17+
WebView $subject,
18+
public readonly RequestInterface $request,
19+
public ?ResponseInterface $response = null,
20+
?int $time = null,
21+
) {
22+
parent::__construct($subject, $time);
23+
}
24+
}
25+
26+
}

src/Application.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Application implements
6969
public readonly ApplicationId $id;
7070

7171
/**
72-
* Gets windows list and methods for working with windows.
72+
* Gets a windows list and methods for working with windows.
7373
*
7474
* @api
7575
*/
@@ -138,7 +138,7 @@ class Application implements
138138
public readonly bool $isDebug;
139139

140140
/**
141-
* Gets running state of an application.
141+
* Gets the running state of an application.
142142
*
143143
* Contains {@see true} in case of application is running
144144
* or {@see false} instead.
@@ -182,7 +182,7 @@ class Application implements
182182
*/
183183
public function __construct(
184184
/**
185-
* Gets an information DTO about the application
185+
* Gets information DTO about the application
186186
* with which it was created.
187187
*/
188188
public readonly ApplicationCreateInfo $info = new ApplicationCreateInfo(),
@@ -202,7 +202,7 @@ public function __construct(
202202
$this->extensions = new Registry($this->listener, $info->extensions);
203203
foreach ($this->extensions->boot($this) as $property => $extension) {
204204
// Direct access to dynamic property is 5+ times
205-
// faster than magic `__get` call.
205+
// faster than the magic `__get` call.
206206
$this->__set($property, $extension);
207207
}
208208

@@ -311,7 +311,7 @@ protected function createWindowManager(
311311
}
312312

313313
/**
314-
* Register list of protocol names that will be
314+
* Register a list of protocol names that will be
315315
* intercepted by the application.
316316
*/
317317
private function registerSchemes(): void
@@ -348,15 +348,15 @@ private function onWindowClose(): void
348348
/**
349349
* Handles an application started event.
350350
*
351-
* Resolve main window lazy proxy (facade).
351+
* Resolve the main window lazy proxy (facade).
352352
*/
353353
private function onApplicationStarted(): void
354354
{
355355
$this->windows->boot();
356356
}
357357

358358
/**
359-
* Creates local (application-aware) event listener
359+
* Creates a local (application-aware) event listener
360360
* based on the provided dispatcher.
361361
*/
362362
protected function createEventListener(?EventDispatcherInterface $dispatcher): EventListener
@@ -439,7 +439,7 @@ private function shouldNotStart(): bool
439439
/**
440440
* Runs the application, starting the main event loop.
441441
*
442-
* This method blocks main thread until the
442+
* This method blocks the main thread until the
443443
* application is quit.
444444
*
445445
* @api

src/ApplicationCreateInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//
1818
// Note:
1919
// 1) This "$_" assign hack removes these constants from IDE autocomplete.
20-
// 2) Only define-like constants allows object instances.
20+
// 2) Only define-like constants allow object instances.
2121
//
2222
\define($_ = 'Boson\DEFAULT_APPLICATION_EXTENSIONS', [
2323
new CentralProcessorExtension(),

src/WebView/Api/LifecycleEvents/LifecycleEventsListener.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,17 @@ private function onSafeNavigated(CData $_, CData $url): void
181181

182182
private function urlToString(CData $url): string
183183
{
184-
$value = $this->app->saucer->new('char');
185-
$size = $this->app->saucer->new('size_t');
184+
$length = $this->app->saucer->new('size_t');
185+
$this->app->saucer->saucer_url_string($url, null, \FFI::addr($length));
186186

187-
$this->app->saucer->saucer_url_string($url, \FFI::addr($value), \FFI::addr($size));
188-
189-
if ($size->cdata === 0) {
187+
if ($length->cdata === 0) {
190188
return '';
191189
}
192190

193-
return \FFI::string($value, $size->cdata);
191+
$value = $this->app->saucer->new("char[{$length->cdata}]");
192+
$this->app->saucer->saucer_url_string($url, \FFI::addr($value[0]), \FFI::addr($length));
193+
194+
return \FFI::string(\FFI::addr($value[0]), $length->cdata);
194195
}
195196

196197
private function onNavigating(CData $_, CData $navigation): int
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\WebView\Api\Schemes\Event;
6+
7+
use Boson\Contracts\Http\RequestInterface;
8+
use Boson\Contracts\Http\ResponseInterface;
9+
use Boson\Shared\Marker\AsWebViewIntention;
10+
use Boson\WebView\WebView;
11+
12+
#[AsWebViewIntention]
13+
final class SchemeRequestFail extends SchemesApiIntention
14+
{
15+
public function __construct(
16+
WebView $subject,
17+
public readonly RequestInterface $request,
18+
public readonly \Throwable $exception,
19+
public ?ResponseInterface $response = null,
20+
?int $time = null,
21+
) {
22+
parent::__construct($subject, $time);
23+
}
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\WebView\Api\Schemes\Event;
6+
7+
use Boson\Contracts\Http\RequestInterface;
8+
use Boson\Contracts\Http\ResponseInterface;
9+
use Boson\Shared\Marker\AsWebViewIntention;
10+
use Boson\WebView\WebView;
11+
12+
#[AsWebViewIntention]
13+
final class SchemeRequestReceive extends SchemesApiIntention
14+
{
15+
public function __construct(
16+
WebView $subject,
17+
public readonly RequestInterface $request,
18+
public ?ResponseInterface $response = null,
19+
?int $time = null,
20+
) {
21+
parent::__construct($subject, $time);
22+
}
23+
}

src/WebView/Api/Schemes/Event/SchemeRequestReceived.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,6 @@
44

55
namespace Boson\WebView\Api\Schemes\Event;
66

7-
use Boson\Contracts\Http\RequestInterface;
8-
use Boson\Contracts\Http\ResponseInterface;
9-
use Boson\Shared\Marker\AsWebViewIntention;
10-
use Boson\WebView\WebView;
11-
12-
#[AsWebViewIntention]
13-
final class SchemeRequestReceived extends SchemesApiIntention
14-
{
15-
public function __construct(
16-
WebView $subject,
17-
public readonly RequestInterface $request,
18-
public ?ResponseInterface $response = null,
19-
?int $time = null,
20-
) {
21-
parent::__construct($subject, $time);
22-
}
7+
if (!\class_exists(SchemeRequestReceived::class)) {
8+
\class_alias(SchemeRequestReceive::class, SchemeRequestReceived::class);
239
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\WebView\Api\Schemes\Event;
6+
7+
use Boson\Contracts\Http\Component\StatusCodeInterface;
8+
use Boson\Contracts\Http\RequestInterface;
9+
use Boson\Shared\Marker\AsWebViewIntention;
10+
use Boson\WebView\WebView;
11+
12+
#[AsWebViewIntention]
13+
final class SchemeRequestReject extends SchemesApiIntention
14+
{
15+
public function __construct(
16+
WebView $subject,
17+
public readonly RequestInterface $request,
18+
public StatusCodeInterface $status,
19+
?int $time = null,
20+
) {
21+
parent::__construct($subject, $time);
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\WebView\Api\Schemes\Event;
6+
7+
use Boson\Contracts\Http\RequestInterface;
8+
use Boson\Contracts\Http\ResponseInterface;
9+
use Boson\Shared\Marker\AsWebViewEvent;
10+
use Boson\WebView\WebView;
11+
12+
#[AsWebViewEvent]
13+
final class SchemeResponseProceed extends SchemesApiEvent
14+
{
15+
public function __construct(
16+
WebView $subject,
17+
public readonly RequestInterface $request,
18+
public readonly ResponseInterface $response,
19+
?int $time = null,
20+
) {
21+
parent::__construct($subject, $time);
22+
}
23+
}

0 commit comments

Comments
 (0)