Skip to content

Commit 06914a4

Browse files
committed
Detect phpFactory vs php
1 parent 56a6030 commit 06914a4

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

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

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -88,30 +88,28 @@ export type PHPRequestHandlerFactoryArgs = PHPFactoryOptions & {
8888

8989
export type PHPRequestHandlerConfiguration = BaseConfiguration & {
9090
cookieStore?: CookieStore | false;
91-
} & (
92-
| {
93-
/**
94-
* Provide a single PHP instance directly.
95-
* PHPRequestHandler will create a SinglePHPInstanceManager internally.
96-
* This is the simplest option for CLI contexts with a single PHP instance.
97-
*/
98-
php: PHP;
99-
}
100-
| {
101-
/**
102-
* Provide a factory function to create PHP instances.
103-
* PHPRequestHandler will create a PHPProcessManager internally.
104-
*/
105-
phpFactory: (
106-
requestHandler: PHPRequestHandlerFactoryArgs
107-
) => Promise<PHP>;
108-
/**
109-
* The maximum number of PHP instances that can exist at
110-
* the same time. Only used when phpFactory is provided.
111-
*/
112-
maxPhpInstances?: number;
113-
}
114-
);
91+
92+
// One of the following must be provided:
93+
94+
/**
95+
* Provide a single PHP instance directly.
96+
* PHPRequestHandler will create a SinglePHPInstanceManager internally.
97+
* This is the simplest option for CLI contexts with a single PHP instance.
98+
*/
99+
php?: PHP;
100+
101+
/**
102+
* Provide a factory function to create PHP instances.
103+
* PHPRequestHandler will create a PHPProcessManager internally.
104+
*/
105+
phpFactory?: (requestHandler: PHPRequestHandlerFactoryArgs) => Promise<PHP>;
106+
107+
/**
108+
* The maximum number of PHP instances that can exist at
109+
* the same time. Only used when phpFactory is provided.
110+
*/
111+
maxPhpInstances?: number;
112+
};
115113

116114
/**
117115
* Handles HTTP requests using PHP runtime as a backend.
@@ -217,15 +215,15 @@ export class PHPRequestHandler implements AsyncDisposable {
217215
(php as any).requestHandler = this;
218216
};
219217

220-
if ('php' in config) {
218+
if (config.php) {
221219
setChroot(config.php);
222220
this.instanceManager = new SinglePHPInstanceManager({
223221
php: config.php,
224222
});
225-
} else {
223+
} else if (config.phpFactory) {
226224
this.instanceManager = new PHPProcessManager({
227225
phpFactory: async (info) => {
228-
const php = await config.phpFactory({
226+
const php = await config.phpFactory!({
229227
...info,
230228
requestHandler: this,
231229
});
@@ -234,6 +232,10 @@ export class PHPRequestHandler implements AsyncDisposable {
234232
},
235233
maxPhpInstances: config.maxPhpInstances,
236234
});
235+
} else {
236+
throw new Error(
237+
'Either php or phpFactory must be provided in the configuration.'
238+
);
237239
}
238240

239241
/**

0 commit comments

Comments
 (0)