Skip to content

Commit cb38752

Browse files
committed
Rename "extension providers" to "extensions"
1 parent b4dde73 commit cb38752

File tree

77 files changed

+1952
-1944
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1952
-1944
lines changed

resources/.phpstorm.autocomplete.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@
44

55
namespace Boson {
66

7-
use Boson\Api\CentralProcessor\CentralProcessorExtensionInterface;
8-
use Boson\Api\Dialog\DialogExtensionInterface;
9-
use Boson\Api\Alert\AlertExtensionInterface;
10-
use Boson\Api\OperatingSystem\OperatingSystemExtensionInterface;
7+
use Boson\Api\CentralProcessor\CentralProcessorInfoInterface;
8+
use Boson\Api\Dialog\DialogApiInterface;
9+
use Boson\Api\OperatingSystem\OperatingSystemInfoInterface;
1110

1211
class Application
1312
{
1413
/**
1514
* Gets access to the Dialog API of the application.
1615
*/
17-
public readonly DialogExtensionInterface $dialog;
16+
public readonly DialogApiInterface $dialog;
1817

1918
/**
2019
* Gets access to the CPU Information API of the application.
2120
*/
22-
public readonly CentralProcessorExtensionInterface $cpu;
21+
public readonly CentralProcessorInfoInterface $cpu;
2322

2423
/**
2524
* Gets access to the OS Information API of the application.
2625
*/
27-
public readonly OperatingSystemExtensionInterface $os;
26+
public readonly OperatingSystemInfoInterface $os;
2827
}
2928

3029
}
@@ -40,12 +39,11 @@ class Window
4039

4140
namespace Boson\WebView {
4241

43-
use Boson\WebView\Api\Bindings\BindingsExtensionInterface;
44-
use Boson\WebView\Api\Data\DataExtensionInterface;
45-
use Boson\WebView\Api\Schemes\SchemesExtensionInterface;
46-
use Boson\WebView\Api\Scripts\ScriptsExtensionInterface;
47-
use Boson\WebView\Api\Security\SecurityExtensionInterface;
48-
use Boson\WebView\Api\WebComponents\WebComponentsExtensionInterface;
42+
use Boson\WebView\Api\Bindings\BindingsApiInterface;
43+
use Boson\WebView\Api\Data\DataRetrieverInterface;
44+
use Boson\WebView\Api\Schemes\SchemesProviderInterface;
45+
use Boson\WebView\Api\Scripts\ScriptsApiInterface;
46+
use Boson\WebView\Api\Security\SecurityInfoInterface;
4947

5048
class WebView
5149
{
@@ -55,33 +53,33 @@ class WebView
5553
* Provides the ability to register PHP functions
5654
* in the webview.
5755
*/
58-
public readonly BindingsExtensionInterface $bindings;
56+
public readonly BindingsApiInterface $bindings;
5957

6058
/**
6159
* Gets access to the Data API of the webview.
6260
*
6361
* Provides the ability to receive variant data from
6462
* the current document.
6563
*/
66-
public readonly DataExtensionInterface $data;
64+
public readonly DataRetrieverInterface $data;
6765

6866
/**
6967
* Gets access to the Schemes API of the webview.
7068
*/
71-
public readonly SchemesExtensionInterface $schemes;
69+
public readonly SchemesProviderInterface $schemes;
7270

7371
/**
7472
* Gets access to the Scripts API of the webview.
7573
*
7674
* Provides the ability to register a JavaScript code
7775
* in the webview.
7876
*/
79-
public readonly ScriptsExtensionInterface $scripts;
77+
public readonly ScriptsApiInterface $scripts;
8078

8179
/**
8280
* Gets access to the Security API of the webview.
8381
*/
84-
public readonly SecurityExtensionInterface $security;
82+
public readonly SecurityInfoInterface $security;
8583

8684
}
8785

src/Api/Autorun/AutorunExtensionProvider.php renamed to src/Api/Autorun/AutorunExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
use Boson\Contracts\Id\IdentifiableInterface;
1212
use Boson\Dispatcher\EventListener;
1313
use Boson\Event\ApplicationStarted;
14-
use Boson\Extension\ExtensionProvider;
14+
use Boson\Extension\Extension;
1515

1616
/**
17-
* @template-extends ExtensionProvider<Application>
17+
* @template-extends Extension<Application>
1818
*/
19-
final class AutorunExtensionProvider extends ExtensionProvider
19+
final class AutorunExtension extends Extension
2020
{
2121
/**
2222
* List of loaded applications that have never been launched

src/Api/CentralProcessor/CentralProcessorExtension.php

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,21 @@
44

55
namespace Boson\Api\CentralProcessor;
66

7-
use Boson\Api\ApplicationExtension;
8-
use Boson\Component\CpuInfo\ArchitectureInterface;
9-
use Boson\Component\CpuInfo\CentralProcessor;
7+
use Boson\Application;
108
use Boson\Component\CpuInfo\CentralProcessorInterface;
9+
use Boson\Contracts\Id\IdentifiableInterface;
10+
use Boson\Dispatcher\EventListener;
11+
use Boson\Extension\Attribute\AvailableAs;
12+
use Boson\Extension\Extension;
1113

1214
/**
13-
* @internal this is an internal library class, please do not use it in your code
14-
* @psalm-internal Boson\Api\CentralProcessor
15+
* @template-extends Extension<Application>
1516
*/
16-
final class CentralProcessorExtension extends ApplicationExtension implements
17-
CentralProcessorExtensionInterface
17+
#[AvailableAs('cpu', CentralProcessorInfoInterface::class, CentralProcessorInterface::class)]
18+
final class CentralProcessorExtension extends Extension
1819
{
19-
private CentralProcessorInterface $cpu {
20-
get => $this->cpu ??= CentralProcessor::createFromGlobals();
21-
}
22-
23-
public ArchitectureInterface $arch {
24-
get => $this->cpu->arch;
25-
}
26-
27-
public string $name {
28-
get => $this->cpu->name;
29-
}
30-
31-
public ?string $vendor {
32-
get => $this->cpu->vendor;
33-
}
34-
35-
public int $physicalCores {
36-
get => $this->cpu->physicalCores;
37-
}
38-
39-
public int $logicalCores {
40-
get => $this->cpu->logicalCores;
41-
}
42-
43-
public iterable $instructionSets {
44-
get => $this->cpu->instructionSets;
20+
public function load(IdentifiableInterface $ctx, EventListener $listener): CentralProcessorInfo
21+
{
22+
return new CentralProcessorInfo();
4523
}
4624
}

src/Api/CentralProcessor/CentralProcessorExtensionProvider.php

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\Api\CentralProcessor;
6+
7+
use Boson\Component\CpuInfo\ArchitectureInterface;
8+
use Boson\Component\CpuInfo\CentralProcessor;
9+
use Boson\Component\CpuInfo\CentralProcessorInterface;
10+
11+
/**
12+
* @internal this is an internal library class, please do not use it in your code
13+
* @psalm-internal Boson\Api\CentralProcessor
14+
*/
15+
final class CentralProcessorInfo implements CentralProcessorInfoInterface
16+
{
17+
private CentralProcessorInterface $cpu {
18+
get => $this->cpu ??= CentralProcessor::createFromGlobals();
19+
}
20+
21+
public ArchitectureInterface $arch {
22+
get => $this->cpu->arch;
23+
}
24+
25+
public string $name {
26+
get => $this->cpu->name;
27+
}
28+
29+
public ?string $vendor {
30+
get => $this->cpu->vendor;
31+
}
32+
33+
public int $physicalCores {
34+
get => $this->cpu->physicalCores;
35+
}
36+
37+
public int $logicalCores {
38+
get => $this->cpu->logicalCores;
39+
}
40+
41+
public iterable $instructionSets {
42+
get => $this->cpu->instructionSets;
43+
}
44+
}

src/Api/CentralProcessor/CentralProcessorExtensionInterface.php renamed to src/Api/CentralProcessor/CentralProcessorInfoInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
/**
1010
* Provides information about the main CPU.
1111
*/
12-
interface CentralProcessorExtensionInterface extends
12+
interface CentralProcessorInfoInterface extends
1313
CentralProcessorInterface {}

src/Api/Console/Driver/ConsoleDriverInterface.php renamed to src/Api/Console/ConsoleApiInterface.php

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

33
declare(strict_types=1);
44

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

7-
interface ConsoleDriverInterface
7+
interface ConsoleApiInterface
88
{
99
public function detach(): void;
1010
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\Api\Console;
6+
7+
use Boson\Api\Console\Driver\VoidConsole;
8+
use Boson\Api\Console\Driver\WindowsConsole;
9+
use Boson\Api\Console\Event\ConsoleDetached;
10+
use Boson\Api\Console\Event\ConsoleDetaching;
11+
use Boson\Api\OperatingSystem\OperatingSystemExtension;
12+
use Boson\Api\OperatingSystem\OperatingSystemInfoInterface;
13+
use Boson\Application;
14+
use Boson\Component\OsInfo\Family;
15+
use Boson\Contracts\Id\IdentifiableInterface;
16+
use Boson\Dispatcher\EventListener;
17+
use Boson\Extension\Attribute\AvailableAs;
18+
use Boson\Extension\Attribute\DependsOn;
19+
use Boson\Extension\Extension;
20+
use FFI\Env\Runtime;
21+
22+
/**
23+
* @template-extends Extension<Application>
24+
*/
25+
#[AvailableAs('console', ConsoleApiInterface::class)]
26+
#[DependsOn(OperatingSystemExtension::class)]
27+
final class ConsoleExtension extends Extension
28+
{
29+
public function load(IdentifiableInterface $ctx, EventListener $listener): ConsoleApiInterface
30+
{
31+
$console = $this->createDriver($ctx->get(OperatingSystemInfoInterface::class));
32+
33+
if ($this->shouldDetachConsole($ctx)) {
34+
$listener->dispatch($intention = new ConsoleDetaching($ctx, $console));
35+
36+
if ($intention->isCancelled) {
37+
return $console;
38+
}
39+
40+
$console->detach();
41+
42+
$listener->dispatch(new ConsoleDetached($ctx, $console));
43+
}
44+
45+
return $console;
46+
}
47+
48+
private function shouldDetachConsole(Application $app): bool
49+
{
50+
return !$app->isDebug
51+
&& $this->isRunningInPhar();
52+
}
53+
54+
private function createDriver(OperatingSystemInfoInterface $operatingSystem): ConsoleApiInterface
55+
{
56+
if (!Runtime::isAvailable()) {
57+
return new VoidConsole();
58+
}
59+
60+
if ($operatingSystem->family->is(Family::Windows)) {
61+
return new WindowsConsole();
62+
}
63+
64+
return new VoidConsole();
65+
}
66+
67+
private function isRunningInPhar(): bool
68+
{
69+
return \class_exists(\Phar::class)
70+
&& \Phar::running() !== '';
71+
}
72+
}

src/Api/Console/ConsoleExtensionProvider.php

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)