Skip to content

Commit 6b7f46c

Browse files
committed
Fix linter issues
1 parent 8cede06 commit 6b7f46c

File tree

12 files changed

+222
-102
lines changed

12 files changed

+222
-102
lines changed

resources/boson.json

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"name": "app",
3-
"entrypoint": "index.php",
43
"target": [
54
{
65
"type": "windows",
7-
"arch": "amd64"
6+
"arch": "amd64",
7+
"ini": {
8+
"opcache.enable": true,
9+
"opcache.enable_cli": true
10+
}
811
},
912
{
1013
"type": "linux",
@@ -26,10 +29,18 @@
2629
"type": "phar"
2730
}
2831
],
29-
"output": ".\/build",
32+
"entrypoint": "index.php",
33+
"output": "./build",
34+
"extensions": [
35+
"ctype",
36+
"iconv"
37+
],
38+
"mount": [
39+
"public"
40+
],
3041
"build": {
3142
"directories": [
32-
"public"
43+
"assets"
3344
],
3445
"finder": [
3546
{
@@ -38,12 +49,19 @@
3849
},
3950
{
4051
"directory": "vendor",
41-
"not-directory": "vendor\/boson-php\/compiler",
42-
"name": "*.php"
52+
"not-directory": "vendor/boson-php/compiler",
53+
"name": "*.php",
54+
"not-name": [
55+
"*Test.php",
56+
"*TestCase.php",
57+
".phpstorm.meta.php"
58+
]
4359
}
4460
]
4561
},
4662
"ini": {
47-
"memory_limit": "128M"
63+
"memory_limit": "512M",
64+
"opcache.enable": false,
65+
"opcache.enable_cli": false
4866
}
4967
}

resources/boson.schema.json

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,8 @@
120120
},
121121
"ini": {
122122
"type": "object",
123-
"description": "List of additional compile target php.ini config variables",
124-
"additionalProperties": false,
125-
"patternProperties": {
126-
"^.+$": {
127-
"$ref": "#/$defs/ini-value",
128-
"description": "Additional compile target php.ini config value"
129-
}
130-
}
123+
"description": "List of common additional compile target php.ini config variables",
124+
"$ref": "#/$defs/ini-values"
131125
},
132126
"box-version": {
133127
"type": "string",
@@ -139,19 +133,73 @@
139133
"compilation-target": {
140134
"type": "object",
141135
"required": ["type"],
136+
"anyOf": [
137+
{"$ref": "#/$defs/builtin-compilation-target"},
138+
{"$ref": "#/$defs/phar-compilation-target"},
139+
{"$ref": "#/$defs/generic-compilation-target"}
140+
],
142141
"properties": {
143142
"output": {
144143
"type": "string",
145144
"minLength": 1,
146145
"description": "The compilation output directory name"
147-
},
148-
"type": {
146+
}
147+
}
148+
},
149+
"generic-compilation-target": {
150+
"type": "object",
151+
"patternProperties": {
152+
"^type$": {
149153
"type": "string",
150154
"minLength": 1,
151155
"description": "The compilation target type"
152156
}
153157
}
154158
},
159+
"phar-compilation-target": {
160+
"type": "object",
161+
"patternProperties": {
162+
"^type$": {
163+
"type": "string",
164+
"enum": ["phar"],
165+
"description": "The compilation target type (expected: phar)"
166+
}
167+
}
168+
},
169+
"builtin-compilation-target": {
170+
"type": "object",
171+
"patternProperties": {
172+
"^type$": {
173+
"type": "string",
174+
"enum": [
175+
"windows", "win32", "win64", "win",
176+
"linux", "nix",
177+
"macos", "darwin", "mac", "osx"
178+
],
179+
"description": "The compilation target type (expected: windows|linux|macos)"
180+
}
181+
},
182+
"properties": {
183+
"arch": {
184+
"type": "string",
185+
"enum": [
186+
"amd64", "x86_64", "x64",
187+
"aarch64", "arm64", "arm64ilp32"
188+
],
189+
"description": "The compilation target architecture"
190+
},
191+
"ini": {
192+
"type": "object",
193+
"description": "List of specific compile target php.ini config variables",
194+
"$ref": "#/$defs/ini-values"
195+
},
196+
"sfx": {
197+
"type": "string",
198+
"minLength": 1,
199+
"description": "User defined SFX pathname for this target"
200+
}
201+
}
202+
},
155203
"filter-reference": {
156204
"oneOf": [
157205
{
@@ -170,8 +218,19 @@
170218
}
171219
]
172220
},
221+
"ini-values": {
222+
"type": "object",
223+
"description": "List of compile target php.ini config variables",
224+
"additionalProperties": false,
225+
"patternProperties": {
226+
"^.+$": {
227+
"$ref": "#/$defs/ini-value",
228+
"description": "Additional compile target php.ini config value"
229+
}
230+
}
231+
},
173232
"ini-value": {
174-
"oneOf": [
233+
"anyOf": [
175234
{"$ref": "#/$defs/ini-string-value"},
176235
{"$ref": "#/$defs/ini-number-value"},
177236
{"$ref": "#/$defs/ini-boolean-value"}

src/Action/CompileAction.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* @var non-empty-string
1717
*/
1818
private const string DEFAULT_INI_CONFIG = <<<'INI'
19-
ffi.enable=1
20-
INI;
19+
ffi.enable=1
20+
INI;
2121

2222
public function __construct(
2323
/**
@@ -28,7 +28,6 @@ public function __construct(
2828
* @var non-empty-string
2929
*/
3030
private string $targetFilename,
31-
private bool $opcache,
3231
TargetInterface $target,
3332
) {
3433
parent::__construct($target);
@@ -57,7 +56,7 @@ public function process(Configuration $config): iterable
5756
$this->appendSfxArchive($targetStream);
5857

5958
yield $this->target => CompileStatus::Progress;
60-
$this->appendPhpConfig($targetStream, $config);
59+
yield $this->appendPhpConfig($targetStream, $config) => CompileStatus::BuildConfiguration;
6160

6261
yield $this->target => CompileStatus::Progress;
6362
$this->appendSource($targetStream, $config);
@@ -75,14 +74,12 @@ private function getPhpConfigString(Configuration $config): string
7574
{
7675
$ini = self::DEFAULT_INI_CONFIG;
7776

78-
if ($this->opcache) {
79-
$ini .= "\n" . \implode("\n", [
80-
'opcache.enable=1',
81-
'opcache.enable_cli=1',
82-
]);
83-
}
84-
85-
foreach ($config->ini as $key => $value) {
77+
/**
78+
* @var non-empty-string $key
79+
* @var scalar $value
80+
* @phpstan-ignore-next-line : Additional target's ini configuration is valid array (checked by json schema)
81+
*/
82+
foreach ([...$config->ini, ...$this->target->config['ini'] ?? []] as $key => $value) {
8683
$ini .= "\n$key=" . match ($value) {
8784
false => '0',
8885
true => '1',
@@ -115,13 +112,15 @@ private function appendSource(mixed $stream, Configuration $config): void
115112
/**
116113
* @param resource $stream
117114
*/
118-
private function appendPhpConfig(mixed $stream, Configuration $config): void
115+
private function appendPhpConfig(mixed $stream, Configuration $config): string
119116
{
120117
$ini = $this->getPhpConfigString($config);
121118

122119
\fwrite($stream, "\xfd\xf6\x69\xe6");
123120
\fwrite($stream, \pack('N', \strlen($ini)));
124121
\fwrite($stream, $ini);
122+
123+
return $ini;
125124
}
126125

127126
/**

src/Action/CompileStatus.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ enum CompileStatus
88
{
99
case ReadyToCompile;
1010
case Progress;
11+
case BuildConfiguration;
1112
case Compiled;
1213
}

0 commit comments

Comments
 (0)