Skip to content

Commit 776537a

Browse files
committed
Add WeakClosure
1 parent 5e47725 commit 776537a

File tree

16 files changed

+169
-220
lines changed

16 files changed

+169
-220
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"boson-php/weak-types": "^0.19",
3434
"psr/container": "^2.0",
3535
"psr/event-dispatcher": "^1.0",
36-
"react/promise": "^3.0"
36+
"react/promise": "^3.0",
37+
"internal/destroy": "^1.0"
3738
},
3839
"autoload": {
3940
"psr-4": {

src/Application.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Boson\Poller\PollerInterface;
2424
use Boson\Shared\Marker\BlockingOperation;
2525
use Boson\Shared\Marker\RequiresDealloc;
26+
use Boson\WebView\Manager\WebViewManager;
2627
use Boson\WebView\WebView;
2728
use Boson\Window\Event\WindowClosed;
2829
use Boson\Window\Manager\WindowManager;
@@ -75,11 +76,8 @@ class Application implements
7576
public readonly WindowManager $windows;
7677

7778
/**
78-
* Provides more convenient and faster access to the
79-
* {@see WindowManager::$default} subsystem from
80-
* child {@see $windows} property.
81-
*
82-
* @uses WindowManager::$default Default (first) window of the windows list
79+
* Provides more convenient and faster access to the {@see WindowManager::$default}
80+
* subsystem from child {@see $windows} property.
8381
*
8482
* @api
8583
*/
@@ -94,12 +92,26 @@ class Application implements
9492
?? throw NoDefaultWindowException::becauseNoDefaultWindow();
9593
}
9694

95+
/**
96+
* Provides more convenient and faster access to the {@see Window::$webviews}
97+
* subsystem from child {@see $window} property.
98+
*
99+
* @api
100+
*/
101+
public WebViewManager $webviews {
102+
/**
103+
* Gets the webview manager of the default application window.
104+
*
105+
* @throws NoDefaultWindowException in case the default window was
106+
* already closed and removed earlier
107+
*/
108+
get => $this->window->webviews;
109+
}
110+
97111
/**
98112
* Provides more convenient and faster access to the {@see Window::$webview}
99113
* subsystem from {@see $window} property.
100114
*
101-
* @uses Window::$webview The webview of the default (first) window
102-
*
103115
* @api
104116
*/
105117
public WebView $webview {
@@ -500,6 +512,12 @@ public function quit(): void
500512
*/
501513
public function __destruct()
502514
{
515+
$this->quit();
516+
517+
$this->windows->destroy();
518+
$this->extensions->destroy();
519+
520+
var_dump(__METHOD__);
503521
$this->saucer->saucer_application_quit($this->id->ptr);
504522
}
505523

src/Dispatcher/DelegateEventListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function __construct(
1414
parent::__construct();
1515
}
1616

17+
#[\Override]
1718
public function dispatch(object $event): object
1819
{
1920
$this->delegate->dispatch(parent::dispatch($event));

src/Dispatcher/EventListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public function removeListenersForEvent(object|string $event): void
5656
unset($this->listeners[$event]);
5757
}
5858

59+
public function removeAllEventListeners(): void
60+
{
61+
$this->listeners = [];
62+
}
63+
5964
/**
6065
* @template TArgEvent of object
6166
*

src/Extension/Registry.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
use Boson\Extension\Exception\ExtensionLoadingException;
1111
use Boson\Extension\Exception\ExtensionNotFoundException;
1212
use Boson\Extension\Loader\DependencyGraph;
13+
use Internal\Destroy\Destroyable;
1314
use Psr\Container\ContainerInterface;
1415

1516
/**
1617
* @template TContext of IdentifiableInterface
1718
*/
18-
final class Registry implements ContainerInterface
19+
final class Registry implements ContainerInterface, Destroyable
1920
{
2021
/**
2122
* @var list<object>
@@ -111,4 +112,27 @@ public function has(string $id): bool
111112
{
112113
return isset($this->publicExtensions[$id]);
113114
}
115+
116+
public function destroy(): void
117+
{
118+
foreach ($this->privateExtensions as $extension) {
119+
if ($extension instanceof Destroyable) {
120+
$extension->destroy();
121+
}
122+
}
123+
124+
foreach ($this->publicExtensions as $extension) {
125+
if ($extension instanceof Destroyable) {
126+
$extension->destroy();
127+
}
128+
}
129+
130+
$this->privateExtensions = [];
131+
$this->publicExtensions = [];
132+
}
133+
134+
public function __destruct()
135+
{
136+
$this->destroy();
137+
}
114138
}

src/WebView/Api/Bindings/BindingsApi.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,9 @@ public function count(): int
197197
{
198198
return \count($this->functions);
199199
}
200+
201+
public function __destruct()
202+
{
203+
var_dump(__METHOD__);
204+
}
200205
}

src/WebView/Api/Data/DataRetriever.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,9 @@ private function onFailureReceived(string|int $id, string $error): void
213213

214214
$deferred->reject(new ClientErrorException($error));
215215
}
216+
217+
public function __destruct()
218+
{
219+
var_dump(__METHOD__);
220+
}
216221
}

src/WebView/Api/LifecycleEvents/LifecycleEventsListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,9 @@ private function onSafeLoad(CData $_, int $state): void
283283
{
284284
$this->onLoad($_, $state);
285285
}
286+
287+
public function __destruct()
288+
{
289+
var_dump(__METHOD__);
290+
}
286291
}

src/WebView/Api/Schemes/SchemesProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,9 @@ private function createResponseBodyData(ResponseInterface $response): CData
155155

156156
return $string;
157157
}
158+
159+
public function __destruct()
160+
{
161+
var_dump(__METHOD__);
162+
}
158163
}

src/WebView/Api/Scripts/ScriptsExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Boson\Extension\Attribute\AvailableAs;
1010
use Boson\Extension\Extension;
1111
use Boson\WebView\WebView;
12+
use Internal\Destroy\Destroyable;
1213

1314
/**
1415
* @template-extends Extension<WebView>

0 commit comments

Comments
 (0)