Skip to content

Commit 901ae30

Browse files
committed
Split phpstan configs to separate packages
1 parent eeaa6ba commit 901ae30

35 files changed

+443
-59
lines changed

phpstan.neon

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
parameters:
2+
level: max
3+
scanFiles:
4+
- resources/stubs/aliases.stub.php
5+
- resources/stubs/saucer-webview-events.stub.php
6+
- resources/stubs/saucer-window-events.stub.php
7+
- resources/stubs/kernel32.stub.php
8+
- resources/stubs/user32.stub.php
9+
excludePaths:
10+
- src/Api/Console/Driver/Windows/Kernel32.php
11+
- src/Api/MessageBox/Driver/Windows/User32.php
12+
strictRules:
13+
allRules: true
14+
fileExtensions:
15+
- php
16+
paths:
17+
- src
18+
tmpDir: vendor/.cache.phpstan
19+
ignoreErrors:
20+
# PHPStan does not support FFI
21+
- '#^Access to an undefined property FFI\\CData#'
22+
- '#does not accept FFI\\CData#'

resources/stubs/kernel32.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Boson\Api\DetachConsole\Driver\Windows;
5+
namespace Boson\Api\Console\Driver\Windows;
66

77
use FFI\CData;
88
use FFI\CType;

src/Api/Autorun/AutorunExtensionProvider.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Boson\Api\Autorun;
66

7+
use Boson\Api\Autorun\Event\ExpectsAutorun;
78
use Boson\Application;
89
use Boson\ApplicationCreateInfo;
910
use Boson\Contracts\EventListener\Subscription\CancellableSubscriptionInterface;
@@ -44,8 +45,8 @@ public function load(IdentifiableInterface $ctx, EventListener $listener): null
4445

4546
$this->listenStartup($ctx, $listener);
4647

47-
$callback = function () use ($ctx): void {
48-
$this->onApplicationShouldStart($ctx);
48+
$callback = function () use ($ctx, $listener): void {
49+
$this->onApplicationShouldStart($ctx, $listener);
4950
};
5051

5152
foreach ($this->info->handlers as $handler) {
@@ -85,14 +86,20 @@ private function onApplicationStarted(ApplicationStarted $event): void
8586
* A callback that is called when the application WANTS to start (using
8687
* autorun features).
8788
*/
88-
private function onApplicationShouldStart(Application $app): void
89+
private function onApplicationShouldStart(Application $app, EventListener $listener): void
8990
{
9091
if (!$this->shouldStart($app)) {
9192
return;
9293
}
9394

9495
$this->shouldNotRunAnymore($app);
9596

97+
$listener->dispatch($intention = new ExpectsAutorun($app));
98+
99+
if ($intention->isCancelled) {
100+
return;
101+
}
102+
96103
$app->run();
97104
}
98105

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\Api\Autorun\Event;
6+
7+
use Boson\Event\ApplicationApiIntention;
8+
9+
abstract class AutorunIntention extends ApplicationApiIntention {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\Api\Autorun\Event;
6+
7+
use Boson\Shared\Marker\AsApplicationEvent;
8+
9+
#[AsApplicationEvent]
10+
final class ExpectsAutorun extends AutorunIntention {}

src/Api/DetachConsole/DetachConsoleExtensionProvider.php renamed to src/Api/Console/ConsoleExtensionProvider.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace Boson\Api\DetachConsole;
5+
namespace Boson\Api\Console;
66

7-
use Boson\Api\DetachConsole\Driver\DetachConsoleDriverInterface;
8-
use Boson\Api\DetachConsole\Driver\WindowsDetachConsoleDriver;
7+
use Boson\Api\Console\Driver\ConsoleDriverInterface;
8+
use Boson\Api\Console\Driver\WindowsConsoleDriver;
9+
use Boson\Api\Console\Event\ConsoleDetached;
10+
use Boson\Api\Console\Event\ConsoleDetaching;
911
use Boson\Api\OperatingSystem\OperatingSystemExtensionInterface;
1012
use Boson\Api\OperatingSystem\OperatingSystemExtensionProvider;
1113
use Boson\Application;
@@ -20,7 +22,7 @@
2022
* @template-extends ExtensionProvider<Application>
2123
*/
2224
#[DependsOn(OperatingSystemExtensionProvider::class)]
23-
final class DetachConsoleExtensionProvider extends ExtensionProvider
25+
final class ConsoleExtensionProvider extends ExtensionProvider
2426
{
2527
public function load(IdentifiableInterface $ctx, EventListener $listener): null
2628
{
@@ -29,21 +31,29 @@ public function load(IdentifiableInterface $ctx, EventListener $listener): null
2931
// Detach console in case of:
3032
// 1) Debug mode is disabled
3133
// 2) And application running in PHAR
32-
if ($ctx->isDebug && $this->isRunningInPhar()) {
33-
$driver?->detach();
34+
if ($driver !== null && $ctx->isDebug && $this->isRunningInPhar()) {
35+
$listener->dispatch($intention = new ConsoleDetaching($ctx, $driver));
36+
37+
if ($intention->isCancelled) {
38+
return null;
39+
}
40+
41+
$driver->detach();
42+
43+
$listener->dispatch(new ConsoleDetached($ctx, $driver));
3444
}
3545

3646
return null;
3747
}
3848

39-
private function createDriver(OperatingSystemExtensionInterface $operatingSystem): ?DetachConsoleDriverInterface
49+
private function createDriver(OperatingSystemExtensionInterface $operatingSystem): ?ConsoleDriverInterface
4050
{
4151
if (!Runtime::isAvailable()) {
4252
return null;
4353
}
4454

4555
if ($operatingSystem->family->is(Family::Windows)) {
46-
return new WindowsDetachConsoleDriver();
56+
return new WindowsConsoleDriver();
4757
}
4858

4959
return null;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\Api\Console\Driver;
6+
7+
interface ConsoleDriverInterface
8+
{
9+
public function detach(): void;
10+
}

src/Api/DetachConsole/Driver/Windows/Kernel32.php renamed to src/Api/Console/Driver/Windows/Kernel32.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
declare(strict_types=1);
44

5-
namespace Boson\Api\DetachConsole\Driver\Windows;
5+
namespace Boson\Api\Console\Driver\Windows;
66

77
use FFI\Env\Runtime;
88

99
/**
1010
* @mixin \FFI
1111
*
1212
* @internal this is an internal library class, please do not use it in your code
13-
* @psalm-internal Boson\Api\DetachConsole\Driver
13+
* @psalm-internal Boson\Api\Console\Driver
1414
*/
1515
final readonly class Kernel32
1616
{

src/Api/DetachConsole/Driver/WindowsDetachConsoleDriver.php renamed to src/Api/Console/Driver/WindowsConsoleDriver.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
declare(strict_types=1);
44

5-
namespace Boson\Api\DetachConsole\Driver;
5+
namespace Boson\Api\Console\Driver;
66

7-
use Boson\Api\DetachConsole\Driver\Windows\Kernel32;
7+
use Boson\Api\Console\Driver\Windows\Kernel32;
88

99
/**
10+
* @api
11+
*
1012
* @internal this is an internal library class, please do not use it in your code
11-
* @psalm-internal Boson\Api\DetachConsole
13+
* @psalm-internal Boson\Api\Console
1214
*/
13-
final readonly class WindowsDetachConsoleDriver implements DetachConsoleDriverInterface
15+
final readonly class WindowsConsoleDriver implements ConsoleDriverInterface
1416
{
1517
public function __construct(
1618
private Kernel32 $kernel32 = new Kernel32(),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\Api\Console\Event;
6+
7+
use Boson\Shared\Marker\AsApplicationEvent;
8+
9+
#[AsApplicationEvent]
10+
final class ConsoleDetached extends ConsoleEvent {}

0 commit comments

Comments
 (0)