Skip to content

Commit f6a916c

Browse files
committed
Extract setChroot helper to reduce duplication in PHPRequestHandler
1 parent 398e0c7 commit f6a916c

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

packages/php-wasm/universal/src/lib/php-request-handler.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ export class PHPRequestHandler implements AsyncDisposable {
206206
getFileNotFoundAction = () => ({ type: '404' }),
207207
} = config;
208208

209-
if ('php' in config) {
210-
const php = config.php;
211-
209+
const setChroot = (php: PHP) => {
212210
// Always set managed PHP's cwd to the document root.
213211
if (!php.isDir(documentRoot)) {
214212
php.mkdir(documentRoot);
@@ -217,24 +215,21 @@ export class PHPRequestHandler implements AsyncDisposable {
217215

218216
// @TODO: Decouple PHP and request handler
219217
(php as any).requestHandler = this;
218+
};
220219

221-
this.processManager = new SinglePHPInstanceManager({ php });
220+
if ('php' in config) {
221+
setChroot(config.php);
222+
this.processManager = new SinglePHPInstanceManager({
223+
php: config.php,
224+
});
222225
} else {
223226
this.processManager = new PHPProcessManager({
224227
phpFactory: async (info) => {
225228
const php = await config.phpFactory({
226229
...info,
227230
requestHandler: this,
228231
});
229-
230-
// Always set managed PHP's cwd to the document root.
231-
if (!php.isDir(documentRoot)) {
232-
php.mkdir(documentRoot);
233-
}
234-
php.chdir(documentRoot);
235-
236-
// @TODO: Decouple PHP and request handler
237-
(php as any).requestHandler = this;
232+
setChroot(php);
238233
return php;
239234
},
240235
maxPhpInstances: config.maxPhpInstances,

0 commit comments

Comments
 (0)