@php-wasm/universal 3.1.32 → 3.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.js +13 -11
- package/index.js.map +1 -1
- package/lib/load-extension.d.ts +2 -2
- package/package.json +6 -6
package/index.cjs
CHANGED
|
@@ -87,7 +87,7 @@ ${JSON.stringify(r.headers,null,2)}
|
|
|
87
87
|
`)),n.push(`\r
|
|
88
88
|
`),c instanceof File?n.push(await fileToUint8Array(c)):n.push(c),n.push(`\r
|
|
89
89
|
`);n.push(`--${e}--\r
|
|
90
|
-
`);const o=n.reduce((l,c)=>l+c.length,0),i=new Uint8Array(o);let a=0;for(const l of n)i.set(typeof l=="string"?s.encode(l):l,a),a+=l.length;return{bytes:i,contentType:t}}function fileToUint8Array(r){return r.arrayBuffer().then(e=>new Uint8Array(e))}const _default="application/octet-stream",asx="video/x-ms-asf",atom="application/atom+xml",avi="video/x-msvideo",avif="image/avif",bin="application/octet-stream",bmp="image/x-ms-bmp",cco="application/x-cocoa",cjs="application/javascript",css="text/css",data="application/octet-stream",deb="application/octet-stream",der="application/x-x509-ca-cert",dmg="application/octet-stream",doc="application/msword",docx="application/vnd.openxmlformats-officedocument.wordprocessingml.document",eot="application/vnd.ms-fontobject",flv="video/x-flv",gif="image/gif",gz="application/gzip",hqx="application/mac-binhex40",htc="text/x-component",html="text/html",ico="image/x-icon",iso="application/octet-stream",jad="text/vnd.sun.j2me.app-descriptor",jar="application/java-archive",jardiff="application/x-java-archive-diff",jng="image/x-jng",jnlp="application/x-java-jnlp-file",jpg="image/jpeg",jpeg="image/jpeg",js="application/javascript",json="application/json",kml="application/vnd.google-earth.kml+xml",kmz="application/vnd.google-earth.kmz",m3u8="application/vnd.apple.mpegurl",m4a="audio/x-m4a",m4v="video/x-m4v",md="text/plain",mid="audio/midi",mjs="application/javascript",mml="text/mathml",mng="video/x-mng",mov="video/quicktime",mp3="audio/mpeg",mp4="video/mp4",mpeg="video/mpeg",msi="application/octet-stream",odg="application/vnd.oasis.opendocument.graphics",odp="application/vnd.oasis.opendocument.presentation",ods="application/vnd.oasis.opendocument.spreadsheet",odt="application/vnd.oasis.opendocument.text",ogg="audio/ogg",otf="font/otf",pdf="application/pdf",pl="application/x-perl",png="image/png",ppt="application/vnd.ms-powerpoint",pptx="application/vnd.openxmlformats-officedocument.presentationml.presentation",prc="application/x-pilot",ps="application/postscript",ra="audio/x-realaudio",rar="application/x-rar-compressed",rpm="application/x-redhat-package-manager",rss="application/rss+xml",rtf="application/rtf",run="application/x-makeself",sea="application/x-sea",sit="application/x-stuffit",svg="image/svg+xml",swf="application/x-shockwave-flash",tcl="application/x-tcl",tar="application/x-tar",tif="image/tiff",ts="video/mp2t",ttf="font/ttf",txt="text/plain",wasm="application/wasm",wbmp="image/vnd.wap.wbmp",webm="video/webm",webp="image/webp",wml="text/vnd.wap.wml",wmlc="application/vnd.wap.wmlc",wmv="video/x-ms-wmv",woff="font/woff",woff2="font/woff2",xhtml="application/xhtml+xml",xls="application/vnd.ms-excel",xlsx="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xml="text/xml",xpi="application/x-xpinstall",xspf="application/xspf+xml",zip="application/zip",mimeTypes={_default,"3gpp":"video/3gpp","7z":"application/x-7z-compressed",asx,atom,avi,avif,bin,bmp,cco,cjs,css,data,deb,der,dmg,doc,docx,eot,flv,gif,gz,hqx,htc,html,ico,iso,jad,jar,jardiff,jng,jnlp,jpg,jpeg,js,json,kml,kmz,m3u8,m4a,m4v,md,mid,mjs,mml,mng,mov,mp3,mp4,mpeg,msi,odg,odp,ods,odt,ogg,otf,pdf,pl,png,ppt,pptx,prc,ps,ra,rar,rpm,rss,rtf,run,sea,sit,svg,swf,tcl,tar,tif,ts,ttf,txt,wasm,wbmp,webm,webp,wml,wmlc,wmv,woff,woff2,xhtml,xls,xlsx,xml,xpi,xspf,zip};var A,Q,re,Y,K,M,Z,$,se,b,be,oe,He,Te,Le;class PHPRequestHandler{constructor(e){x(this,b);x(this,A);x(this,Q);x(this,re);x(this,Y);x(this,K);x(this,M);x(this,Z);x(this,$);x(this,se);const{documentRoot:t="/www/",absoluteUrl:s=typeof location=="object"?location.href:DEFAULT_BASE_URL,rewriteRules:n=[],pathAliases:o=[],getFileNotFoundAction:i=()=>({type:"404"})}=e,a=u=>{u.isDir(t)||u.mkdir(t),u.chdir(t),u.requestHandler=this};if(e.php)a(e.php),this.instanceManager=new SinglePHPInstanceManager({php:e.php});else if(e.phpFactory)this.instanceManager=new PHPProcessManager({phpFactory:async u=>{const d=await e.phpFactory({...u,requestHandler:this});return a(d),d},maxPhpInstances:e.maxPhpInstances});else throw new Error("Either php or phpFactory must be provided in the configuration.");E(this,$,e.cookieStore===void 0?new HttpCookieStore:e.cookieStore),E(this,A,t);const l=new URL(s);E(this,re,l.hostname),E(this,Y,l.port?Number(l.port):l.protocol==="https:"?443:80),E(this,Q,(l.protocol||"").replace(":",""));const c=p(this,Y)!==443&&p(this,Y)!==80;E(this,K,[p(this,re),c?`:${p(this,Y)}`:""].join("")),E(this,M,l.pathname.replace(/\/+$/,"")),E(this,Z,[`${p(this,Q)}://`,p(this,K),p(this,M)].join("")),this.rewriteRules=n,E(this,se,o),this.getFileNotFoundAction=i}async getPrimaryPhp(){return await this.instanceManager.getPrimaryPhp()}pathToInternalUrl(e){return e.startsWith("/")||(e=`/${e}`),`${this.absoluteUrl}${e}`}internalUrlToPath(e){const t=new URL(e,"https://playground.internal");return t.pathname.startsWith(p(this,M))&&(t.pathname=t.pathname.slice(p(this,M).length)),toRelativeUrl(t)}get absoluteUrl(){return p(this,Z)}get documentRoot(){return p(this,A)}async request(e){const t=await this.requestStreamed(e),s=await PHPResponse.fromStreamedResponse(t);return s.ok()&&s.exitCode!==0?new PHPResponse(500,s.headers,s.bytes,s.errors,s.exitCode):s}async requestStreamed(e){const t=looksLikeAbsoluteUrl(e.url),s=new URL(e.url.split("#")[0],t?void 0:DEFAULT_BASE_URL),n=_(this,b,be).call(this,s),o=await this.getPrimaryPhp(),i=removePathPrefix(decodeURIComponent(n.pathname),p(this,M));let a=_(this,b,oe).call(this,i);if(o.isDir(a)){if(!i.endsWith("/"))return StreamedPHPResponse.fromPHPResponse(new PHPResponse(301,{location:[`${n.pathname}/`]},new Uint8Array(0)));for(const l of["index.php","index.html"]){const c=util.joinPaths(a,l);if(o.isFile(c)){a=c,n.pathname=util.joinPaths(n.pathname,l);break}}}if(!o.isFile(a)){let l=i;for(;l.startsWith("/")&&l!==util.dirname(l);){l=util.dirname(l);const c=_(this,b,oe).call(this,l);if(o.isFile(c)&&c.endsWith(".php")){a=_(this,b,oe).call(this,l);break}}}if(!o.isFile(a)){const l=this.getFileNotFoundAction(n.pathname);switch(l.type){case"response":return StreamedPHPResponse.fromPHPResponse(l.response);case"internal-redirect":a=util.joinPaths(p(this,A),l.uri);break;case"404":return StreamedPHPResponse.forHttpCode(404);default:throw new Error(`Unsupported file-not-found action type: '${l.type}'`)}}return o.isFile(a)?a.endsWith(".php")?await _(this,b,Te).call(this,e,s,n,a):StreamedPHPResponse.fromPHPResponse(_(this,b,He).call(this,o,a)):StreamedPHPResponse.forHttpCode(404)}prepare_$_SERVER_superglobal(e,t,s){const n={REMOTE_ADDR:"127.0.0.1",DOCUMENT_ROOT:p(this,A),HTTPS:p(this,Z).startsWith("https://")?"on":""};return n.REQUEST_URI=e.pathname+e.search,s.startsWith(p(this,A))&&(n.SCRIPT_NAME=s.substring(p(this,A).length),n.PHP_SELF=t.pathname,n.REQUEST_URI.startsWith(n.SCRIPT_NAME)&&(n.PATH_INFO=n.REQUEST_URI.substring(n.SCRIPT_NAME.length),n.PATH_INFO.includes("?")&&(n.PATH_INFO=n.PATH_INFO.substring(0,n.PATH_INFO.indexOf("?"))))),n.QUERY_STRING=t.search.substring(1),n}async[Symbol.asyncDispose](){await this.instanceManager[Symbol.asyncDispose]()}}A=new WeakMap,Q=new WeakMap,re=new WeakMap,Y=new WeakMap,K=new WeakMap,M=new WeakMap,Z=new WeakMap,$=new WeakMap,se=new WeakMap,b=new WeakSet,be=function(e){const t=removePathPrefix(decodeURIComponent(e.pathname),p(this,M)),s=applyRewriteRules(t,this.rewriteRules),n=new URL(util.joinPaths(p(this,M),s),e.toString());for(const[o,i]of e.searchParams.entries())n.searchParams.append(o,i);return n},oe=function(e){for(const t of p(this,se))if(e===t.urlPrefix||e.startsWith(t.urlPrefix+"/")){const s=e.slice(t.urlPrefix.length);return util.joinPaths(t.fsPath,s)}return util.joinPaths(p(this,A),e)},He=function(e,t){const s=e.readFileAsBuffer(t);return new PHPResponse(200,{"content-length":[`${s.byteLength}`],"content-type":[inferMimeType(t)],"accept-ranges":["bytes"],"cache-control":["public, max-age=0"]},s)},Te=async function(e,t,s,n){let o;try{o=await this.instanceManager.acquirePHPInstance()}catch(a){return a instanceof MaxPhpInstancesError?StreamedPHPResponse.forHttpCode(502):StreamedPHPResponse.forHttpCode(500)}let i;try{i=await _(this,b,Le).call(this,o.php,e,t,s,n)}catch(a){throw o.reap(),a}return i.finished.finally(()=>{o==null||o.reap()}),i},Le=async function(e,t,s,n,o){let i="GET";const a={host:p(this,K),...normalizeHeaders(t.headers||{})};p(this,$)&&(a.cookie=p(this,$).getCookieRequestHeader());let l=t.body;if(typeof l=="object"&&!(l instanceof Uint8Array)){i="POST";const{bytes:u,contentType:d}=await encodeAsMultipart(l);l=u,a["content-type"]=d}const c=await e.runStream({relativeUri:ensurePathPrefix(toRelativeUrl(new URL(n.toString())),p(this,M)),protocol:p(this,Q),method:t.method||i,$_SERVER:this.prepare_$_SERVER_superglobal(s,n,o),body:l,scriptPath:o,headers:a});if(p(this,$)){const u=await c.headers;p(this,$).rememberCookiesFromResponseHeaders(u)}return c};function inferMimeType(r){const e=r.split(".").pop();return mimeTypes[e]||mimeTypes._default}function applyRewriteRules(r,e){for(const t of e)if(new RegExp(t.match).test(r)){r=r.replace(t.match,t.replacement);break}return r}function looksLikeAbsoluteUrl(r){try{return new URL(r),!0}catch{return!1}}function rotatePHPRuntime({php:r,recreateRuntime:e,maxRequests:t=400}){return r.enableRuntimeRotation({recreateRuntime:e,maxRequests:t})}async function writeFiles(r,e,t,{rmRoot:s=!1}={}){s&&await r.isDir(e)&&await r.rmdir(e,{recursive:!0});for(const[n,o]of Object.entries(t)){const i=util.joinPaths(e,n);await r.fileExists(util.dirname(i))||await r.mkdir(util.dirname(i)),o instanceof Uint8Array||typeof o=="string"?await r.writeFile(i,o):await writeFiles(r,i,o)}}const schema12={properties:{name:{type:"string"},version:{type:"string"},mode:{type:"string",const:"php-extension"},loadWithIniDirective:{$ref:"#/definitions/PHPExtensionLoadDirective",description:"The first directive of the generated startup `.ini` file. Defaults to `extension`; use `zend_extension` for Zend extensions like Xdebug. Use `false` to stage the `.so` without registering it in php.ini."},iniEntries:{type:"object",additionalProperties:{type:"string"},description:"Additional `key=value` lines for the generated startup `.ini` file."},env:{type:"object",additionalProperties:{type:"string"},description:"Environment variables added before the extension is loaded."},extensionDir:{type:"string",description:"VFS directory where PHP.wasm writes the extension `.so` file and its per-extension ini file. Defaults to `PHP_EXTENSIONS_DIR`."},artifacts:{type:"array",items:{type:"object",properties:{phpVersion:{type:"string",description:"PHP major/minor version, e.g. `8.4`."},sourcePath:{type:"string",description:"Relative to the manifest URL/base URL, or an absolute URL."},extraFiles:{$ref:"#/definitions/PHPExtensionManifestExtraFiles",description:"URL-backed files needed only by this artifact."}},required:["phpVersion","sourcePath"],additionalProperties:!1}},extraFiles:{$ref:"#/definitions/PHPExtensionManifestExtraFiles",description:"URL-backed files shared by every artifact in this manifest."}}},schema15={properties:{nodes:{items:{properties:{type:{enum:["file","directory"]}}}}}},func2=Object.prototype.hasOwnProperty,schema14={enum:["extension","zend_extension"]};function validate12(r,{instancePath:e="",parentData:t,parentDataProperty:s,rootData:n=r}={}){let o=null,i=0;const a=i;let l=!1;const c=i;if(typeof r!="string"){const d={instancePath:e,schemaPath:"#/definitions/PHPExtensionIniDirective/type",keyword:"type",params:{type:"string"},message:"must be string"};o===null?o=[d]:o.push(d),i++}if(!(r==="extension"||r==="zend_extension")){const d={instancePath:e,schemaPath:"#/definitions/PHPExtensionIniDirective/enum",keyword:"enum",params:{allowedValues:schema14.enum},message:"must be equal to one of the allowed values"};o===null?o=[d]:o.push(d),i++}var u=c===i;if(l=l||u,!l){const d=i;if(typeof r!="boolean"){const P={instancePath:e,schemaPath:"#/anyOf/1/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};o===null?o=[P]:o.push(P),i++}if(r!==!1){const P={instancePath:e,schemaPath:"#/anyOf/1/const",keyword:"const",params:{allowedValue:!1},message:"must be equal to constant"};o===null?o=[P]:o.push(P),i++}var u=d===i;l=l||u}if(l)i=a,o!==null&&(a?o.length=a:o=null);else{const d={instancePath:e,schemaPath:"#/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};return o===null?o=[d]:o.push(d),i++,validate12.errors=o,!1}return validate12.errors=o,i===0}function validate11(r,{instancePath:e="",parentData:t,parentDataProperty:s,rootData:n=r}={}){let o=null,i=0;if(i===0)if(r&&typeof r=="object"&&!Array.isArray(r)){let L;if(r.name===void 0&&(L="name")||r.artifacts===void 0&&(L="artifacts"))return validate11.errors=[{instancePath:e,schemaPath:"#/required",keyword:"required",params:{missingProperty:L},message:"must have required property '"+L+"'"}],!1;{const O=i;for(const f in r)if(!func2.call(schema12.properties,f))return validate11.errors=[{instancePath:e,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:f},message:"must NOT have additional properties"}],!1;if(O===i){if(r.name!==void 0){const f=i;if(typeof r.name!="string")return validate11.errors=[{instancePath:e+"/name",schemaPath:"#/properties/name/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var a=f===i}else var a=!0;if(a){if(r.version!==void 0){const f=i;if(typeof r.version!="string")return validate11.errors=[{instancePath:e+"/version",schemaPath:"#/properties/version/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var a=f===i}else var a=!0;if(a){if(r.mode!==void 0){let f=r.mode;const R=i;if(typeof f!="string")return validate11.errors=[{instancePath:e+"/mode",schemaPath:"#/properties/mode/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if(f!=="php-extension")return validate11.errors=[{instancePath:e+"/mode",schemaPath:"#/properties/mode/const",keyword:"const",params:{allowedValue:"php-extension"},message:"must be equal to constant"}],!1;var a=R===i}else var a=!0;if(a){if(r.loadWithIniDirective!==void 0){const f=i;validate12(r.loadWithIniDirective,{instancePath:e+"/loadWithIniDirective",parentData:r,parentDataProperty:"loadWithIniDirective",rootData:n})||(o=o===null?validate12.errors:o.concat(validate12.errors),i=o.length);var a=f===i}else var a=!0;if(a){if(r.iniEntries!==void 0){let f=r.iniEntries;const R=i;if(i===R)if(f&&typeof f=="object"&&!Array.isArray(f))for(const D in f){const m=i;if(typeof f[D]!="string")return validate11.errors=[{instancePath:e+"/iniEntries/"+D.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/iniEntries/additionalProperties/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var l=m===i;if(!l)break}else return validate11.errors=[{instancePath:e+"/iniEntries",schemaPath:"#/properties/iniEntries/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var a=R===i}else var a=!0;if(a){if(r.env!==void 0){let f=r.env;const R=i;if(i===R)if(f&&typeof f=="object"&&!Array.isArray(f))for(const D in f){const m=i;if(typeof f[D]!="string")return validate11.errors=[{instancePath:e+"/env/"+D.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/env/additionalProperties/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var c=m===i;if(!c)break}else return validate11.errors=[{instancePath:e+"/env",schemaPath:"#/properties/env/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var a=R===i}else var a=!0;if(a){if(r.extensionDir!==void 0){const f=i;if(typeof r.extensionDir!="string")return validate11.errors=[{instancePath:e+"/extensionDir",schemaPath:"#/properties/extensionDir/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var a=f===i}else var a=!0;if(a){if(r.artifacts!==void 0){let f=r.artifacts;const R=i;if(i===R)if(Array.isArray(f)){var u=!0;const D=f.length;for(let m=0;m<D;m++){let w=f[m];const q=i;if(i===q)if(w&&typeof w=="object"&&!Array.isArray(w)){let W;if(w.phpVersion===void 0&&(W="phpVersion")||w.sourcePath===void 0&&(W="sourcePath"))return validate11.errors=[{instancePath:e+"/artifacts/"+m,schemaPath:"#/properties/artifacts/items/required",keyword:"required",params:{missingProperty:W},message:"must have required property '"+W+"'"}],!1;{const H=i;for(const y in w)if(!(y==="phpVersion"||y==="sourcePath"||y==="extraFiles"))return validate11.errors=[{instancePath:e+"/artifacts/"+m,schemaPath:"#/properties/artifacts/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:y},message:"must NOT have additional properties"}],!1;if(H===i){if(w.phpVersion!==void 0){const y=i;if(typeof w.phpVersion!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/phpVersion",schemaPath:"#/properties/artifacts/items/properties/phpVersion/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var d=y===i}else var d=!0;if(d){if(w.sourcePath!==void 0){const y=i;if(typeof w.sourcePath!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/sourcePath",schemaPath:"#/properties/artifacts/items/properties/sourcePath/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var d=y===i}else var d=!0;if(d)if(w.extraFiles!==void 0){let y=w.extraFiles;const ne=i;if(i===i)if(y&&typeof y=="object"&&!Array.isArray(y)){const ue=i;for(const v in y)if(!(v==="vfsRoot"||v==="nodes"))return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:v},message:"must NOT have additional properties"}],!1;if(ue===i){if(y.vfsRoot!==void 0){const v=i;if(typeof y.vfsRoot!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/vfsRoot",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/vfsRoot/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var h=v===i}else var h=!0;if(h)if(y.nodes!==void 0){let v=y.nodes;const ie=i;if(i===ie)if(Array.isArray(v)){var P=!0;const Me=v.length;for(let C=0;C<Me;C++){let I=v[C];const ye=i;if(i===ye)if(I&&typeof I=="object"&&!Array.isArray(I)){let de;if(I.vfsPath===void 0&&(de="vfsPath"))return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/required",keyword:"required",params:{missingProperty:de},message:"must have required property '"+de+"'"}],!1;{const Ce=i;for(const T in I)if(!(T==="vfsPath"||T==="type"||T==="sourcePath"))return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:T},message:"must NOT have additional properties"}],!1;if(Ce===i){if(I.vfsPath!==void 0){const T=i;if(typeof I.vfsPath!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C+"/vfsPath",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/vfsPath/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var S=T===i}else var S=!0;if(S){if(I.type!==void 0){let T=I.type;const Ae=i;if(typeof T!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C+"/type",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if(!(T==="file"||T==="directory"))return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C+"/type",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/enum",keyword:"enum",params:{allowedValues:schema15.properties.nodes.items.properties.type.enum},message:"must be equal to one of the allowed values"}],!1;var S=Ae===i}else var S=!0;if(S)if(I.sourcePath!==void 0){const T=i;if(typeof I.sourcePath!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C+"/sourcePath",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/sourcePath/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var S=T===i}else var S=!0}}}}else return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var P=ye===i;if(!P)break}}else return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;var h=ie===i}else var h=!0}}else return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var d=ne===i}else var d=!0}}}}else return validate11.errors=[{instancePath:e+"/artifacts/"+m,schemaPath:"#/properties/artifacts/items/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var u=q===i;if(!u)break}}else return validate11.errors=[{instancePath:e+"/artifacts",schemaPath:"#/properties/artifacts/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;var a=R===i}else var a=!0;if(a)if(r.extraFiles!==void 0){let f=r.extraFiles;const R=i;if(i===i)if(f&&typeof f=="object"&&!Array.isArray(f)){const m=i;for(const w in f)if(!(w==="vfsRoot"||w==="nodes"))return validate11.errors=[{instancePath:e+"/extraFiles",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:w},message:"must NOT have additional properties"}],!1;if(m===i){if(f.vfsRoot!==void 0){const w=i;if(typeof f.vfsRoot!="string")return validate11.errors=[{instancePath:e+"/extraFiles/vfsRoot",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/vfsRoot/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var N=w===i}else var N=!0;if(N)if(f.nodes!==void 0){let w=f.nodes;const q=i;if(i===q)if(Array.isArray(w)){var B=!0;const W=w.length;for(let H=0;H<W;H++){let y=w[H];const ne=i;if(i===ne)if(y&&typeof y=="object"&&!Array.isArray(y)){let ce;if(y.vfsPath===void 0&&(ce="vfsPath"))return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/required",keyword:"required",params:{missingProperty:ce},message:"must have required property '"+ce+"'"}],!1;{const ue=i;for(const v in y)if(!(v==="vfsPath"||v==="type"||v==="sourcePath"))return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:v},message:"must NOT have additional properties"}],!1;if(ue===i){if(y.vfsPath!==void 0){const v=i;if(typeof y.vfsPath!="string")return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H+"/vfsPath",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/vfsPath/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var k=v===i}else var k=!0;if(k){if(y.type!==void 0){let v=y.type;const ie=i;if(typeof v!="string")return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H+"/type",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if(!(v==="file"||v==="directory"))return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H+"/type",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/enum",keyword:"enum",params:{allowedValues:schema15.properties.nodes.items.properties.type.enum},message:"must be equal to one of the allowed values"}],!1;var k=ie===i}else var k=!0;if(k)if(y.sourcePath!==void 0){const v=i;if(typeof y.sourcePath!="string")return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H+"/sourcePath",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/sourcePath/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var k=v===i}else var k=!0}}}}else return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var B=ne===i;if(!B)break}}else return validate11.errors=[{instancePath:e+"/extraFiles/nodes",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;var N=q===i}else var N=!0}}else return validate11.errors=[{instancePath:e+"/extraFiles",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var a=R===i}else var a=!0}}}}}}}}}}else return validate11.errors=[{instancePath:e,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;return validate11.errors=o,i===0}function validate10(r,{instancePath:e="",parentData:t,parentDataProperty:s,rootData:n=r}={}){let o=null,i=0;return validate11(r,{instancePath:e,parentData:t,parentDataProperty:s,rootData:n})||(o=o===null?validate11.errors:o.concat(validate11.errors),i=o.length),validate10.errors=o,i===0}const PHP_EXTENSIONS_DIR="/internal/shared/extensions",MAX_EXTENSION_SIDECAR_FILE_REQUESTS=5;async function resolvePHPExtension(r){const e=r.fetch??globalThis.fetch,t=r.source;let s=r.name,n;const o={},i=[];let a,l,c,u;if(t.format==="so"){if(s||(s=t.name),!s)throw new Error("name is required when loading an extension from direct bytes.");n=toUint8Array(t.bytes)}else if(t.format==="url"){let k;try{k=new URL(String(t.url))}catch{throw new Error(`source.url must be an absolute URL when loading a PHP extension from a direct URL. Received: ${String(t.url)}`)}if(s||(s=t.name),!s&&k.pathname.endsWith(".so")&&(s=util.basename(k.pathname).slice(0,-3)),!s)throw new Error("name is required when loading an extension from a direct URL.");n=await fetchBytes(e,k)}else{let k,L;if("manifest"in t?(k=t.manifest,t.baseUrl&&(L=new URL(String(t.baseUrl)))):(L=new URL(String(t.manifestUrl)),k=await(await e(L)).json()),!validate10(k))throw new Error(`Invalid PHP extension manifest: ${JSON.stringify(validate10.errors)}`);const O=k;if(!L)throw new Error("Manifest artifacts require a manifest URL or baseUrl so relative files can be resolved.");const f=O.artifacts.find(m=>m.phpVersion===r.phpVersion);if(!f)throw new Error(`No extension artifact found for PHP ${r.phpVersion}.`);s??(s=O.name),a=O.loadWithIniDirective,l=O.iniEntries,c=O.env,u=O.extensionDir;const R=new util.Semaphore({concurrency:MAX_EXTENSION_SIDECAR_FILE_REQUESTS}),le=[];for(const m of[O.extraFiles,f.extraFiles])for(const w of(m==null?void 0:m.nodes)??[]){const q=util.joinPaths(m.vfsRoot??"",w.vfsPath);if(w.type==="directory"){i.push(q);continue}if(!w.sourcePath)continue;const Ie=new URL(w.sourcePath,L);le.push(R.run(()=>fetchBytes(e,Ie)).then(W=>{o[q]=W}))}const[D]=await Promise.all([fetchBytes(e,new URL(f.sourcePath,L)),...le]);n=D}const d=util.normalizePath(r.extensionDir??u??PHP_EXTENSIONS_DIR);r.extraFiles&&(Object.assign(o,r.extraFiles.files),i.push(...r.extraFiles.directories??[]));const h=r.loadWithIniDirective??a??"extension",P={...l,...r.iniEntries},S=util.joinPaths(d,`${s}.so`),N=createPHPExtensionIniFile({directive:h,extensionDir:d,name:s,soPath:S,iniEntries:P}),B={...c,...r.env};return{soPath:S,soBytes:n,...N,extraFiles:{files:o,directories:i},env:Object.keys(B).length?B:void 0,extensionDir:d}}function withResolvedPHPExtensions(r,e){var s;if(!e.length)return r;const t={...r.ENV};for(const n of e){if(Object.assign(t,n.env),!n.iniPath)continue;const o=((s=t.PHP_INI_SCAN_DIR)==null?void 0:s.split(":"))??[];o.includes(n.extensionDir)||(o.push(n.extensionDir),t.PHP_INI_SCAN_DIR=o.join(":"))}return{...r,ENV:t,onRuntimeInitialized:n=>{var o;(o=r.onRuntimeInitialized)==null||o.call(r,n);for(const i of e)installPHPExtensionFilesSync(n.FS,i)}}}function installPHPExtensionFilesSync(r,e){let t;if("soPath"in e)t=e;else{const s=e.extensionDir??PHP_EXTENSIONS_DIR,n=e.loadWithIniDirective??"extension",o=util.joinPaths(s,`${e.name}.so`),i=createPHPExtensionIniFile({directive:n,extensionDir:s,name:e.name,soPath:o,iniEntries:e.iniEntries});t={soPath:o,soBytes:toUint8Array(e.soBytes),...i,extraFiles:e.extraFiles,env:e.env,extensionDir:s}}if(mkdirIfMissing(r,t.extensionDir),r.writeFile(t.soPath,t.soBytes),t.iniPath&&t.iniContent!==void 0&&r.writeFile(t.iniPath,t.iniContent),t.extraFiles){const{directories:s=[],files:n}=t.extraFiles;for(const o of s)mkdirIfMissing(r,o);for(const[o,i]of Object.entries(n))mkdirIfMissing(r,util.dirname(o)),r.writeFile(o,i)}return t}function createPHPExtensionIniFile(r){if(r.directive===!1)return{};const e=[`${r.directive}=${r.soPath}`,...Object.entries(r.iniEntries??{}).map(([t,s])=>`${t}=${s}`)];return{iniPath:util.joinPaths(r.extensionDir,`${r.name}.ini`),iniContent:e.join(`
|
|
90
|
+
`);const o=n.reduce((l,c)=>l+c.length,0),i=new Uint8Array(o);let a=0;for(const l of n)i.set(typeof l=="string"?s.encode(l):l,a),a+=l.length;return{bytes:i,contentType:t}}function fileToUint8Array(r){return r.arrayBuffer().then(e=>new Uint8Array(e))}const _default="application/octet-stream",asx="video/x-ms-asf",atom="application/atom+xml",avi="video/x-msvideo",avif="image/avif",bin="application/octet-stream",bmp="image/x-ms-bmp",cco="application/x-cocoa",cjs="application/javascript",css="text/css",data="application/octet-stream",deb="application/octet-stream",der="application/x-x509-ca-cert",dmg="application/octet-stream",doc="application/msword",docx="application/vnd.openxmlformats-officedocument.wordprocessingml.document",eot="application/vnd.ms-fontobject",flv="video/x-flv",gif="image/gif",gz="application/gzip",hqx="application/mac-binhex40",htc="text/x-component",html="text/html",ico="image/x-icon",iso="application/octet-stream",jad="text/vnd.sun.j2me.app-descriptor",jar="application/java-archive",jardiff="application/x-java-archive-diff",jng="image/x-jng",jnlp="application/x-java-jnlp-file",jpg="image/jpeg",jpeg="image/jpeg",js="application/javascript",json="application/json",kml="application/vnd.google-earth.kml+xml",kmz="application/vnd.google-earth.kmz",m3u8="application/vnd.apple.mpegurl",m4a="audio/x-m4a",m4v="video/x-m4v",md="text/plain",mid="audio/midi",mjs="application/javascript",mml="text/mathml",mng="video/x-mng",mov="video/quicktime",mp3="audio/mpeg",mp4="video/mp4",mpeg="video/mpeg",msi="application/octet-stream",odg="application/vnd.oasis.opendocument.graphics",odp="application/vnd.oasis.opendocument.presentation",ods="application/vnd.oasis.opendocument.spreadsheet",odt="application/vnd.oasis.opendocument.text",ogg="audio/ogg",otf="font/otf",pdf="application/pdf",pl="application/x-perl",png="image/png",ppt="application/vnd.ms-powerpoint",pptx="application/vnd.openxmlformats-officedocument.presentationml.presentation",prc="application/x-pilot",ps="application/postscript",ra="audio/x-realaudio",rar="application/x-rar-compressed",rpm="application/x-redhat-package-manager",rss="application/rss+xml",rtf="application/rtf",run="application/x-makeself",sea="application/x-sea",sit="application/x-stuffit",svg="image/svg+xml",swf="application/x-shockwave-flash",tcl="application/x-tcl",tar="application/x-tar",tif="image/tiff",ts="video/mp2t",ttf="font/ttf",txt="text/plain",wasm="application/wasm",wbmp="image/vnd.wap.wbmp",webm="video/webm",webp="image/webp",wml="text/vnd.wap.wml",wmlc="application/vnd.wap.wmlc",wmv="video/x-ms-wmv",woff="font/woff",woff2="font/woff2",xhtml="application/xhtml+xml",xls="application/vnd.ms-excel",xlsx="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xml="text/xml",xpi="application/x-xpinstall",xspf="application/xspf+xml",zip="application/zip",mimeTypes={_default,"3gpp":"video/3gpp","7z":"application/x-7z-compressed",asx,atom,avi,avif,bin,bmp,cco,cjs,css,data,deb,der,dmg,doc,docx,eot,flv,gif,gz,hqx,htc,html,ico,iso,jad,jar,jardiff,jng,jnlp,jpg,jpeg,js,json,kml,kmz,m3u8,m4a,m4v,md,mid,mjs,mml,mng,mov,mp3,mp4,mpeg,msi,odg,odp,ods,odt,ogg,otf,pdf,pl,png,ppt,pptx,prc,ps,ra,rar,rpm,rss,rtf,run,sea,sit,svg,swf,tcl,tar,tif,ts,ttf,txt,wasm,wbmp,webm,webp,wml,wmlc,wmv,woff,woff2,xhtml,xls,xlsx,xml,xpi,xspf,zip};var A,Q,re,Y,K,M,Z,$,se,b,be,oe,He,Te,Le;class PHPRequestHandler{constructor(e){x(this,b);x(this,A);x(this,Q);x(this,re);x(this,Y);x(this,K);x(this,M);x(this,Z);x(this,$);x(this,se);const{documentRoot:t="/www/",absoluteUrl:s=typeof location=="object"?location.href:DEFAULT_BASE_URL,rewriteRules:n=[],pathAliases:o=[],getFileNotFoundAction:i=()=>({type:"404"})}=e,a=u=>{u.isDir(t)||u.mkdir(t),u.chdir(t),u.requestHandler=this};if(e.php)a(e.php),this.instanceManager=new SinglePHPInstanceManager({php:e.php});else if(e.phpFactory)this.instanceManager=new PHPProcessManager({phpFactory:async u=>{const d=await e.phpFactory({...u,requestHandler:this});return a(d),d},maxPhpInstances:e.maxPhpInstances});else throw new Error("Either php or phpFactory must be provided in the configuration.");E(this,$,e.cookieStore===void 0?new HttpCookieStore:e.cookieStore),E(this,A,t);const l=new URL(s);E(this,re,l.hostname),E(this,Y,l.port?Number(l.port):l.protocol==="https:"?443:80),E(this,Q,(l.protocol||"").replace(":",""));const c=p(this,Y)!==443&&p(this,Y)!==80;E(this,K,[p(this,re),c?`:${p(this,Y)}`:""].join("")),E(this,M,l.pathname.replace(/\/+$/,"")),E(this,Z,[`${p(this,Q)}://`,p(this,K),p(this,M)].join("")),this.rewriteRules=n,E(this,se,o),this.getFileNotFoundAction=i}async getPrimaryPhp(){return await this.instanceManager.getPrimaryPhp()}pathToInternalUrl(e){return e.startsWith("/")||(e=`/${e}`),`${this.absoluteUrl}${e}`}internalUrlToPath(e){const t=new URL(e,"https://playground.internal");return t.pathname.startsWith(p(this,M))&&(t.pathname=t.pathname.slice(p(this,M).length)),toRelativeUrl(t)}get absoluteUrl(){return p(this,Z)}get documentRoot(){return p(this,A)}async request(e){const t=await this.requestStreamed(e),s=await PHPResponse.fromStreamedResponse(t);return s.ok()&&s.exitCode!==0?new PHPResponse(500,s.headers,s.bytes,s.errors,s.exitCode):s}async requestStreamed(e){const t=looksLikeAbsoluteUrl(e.url),s=new URL(e.url.split("#")[0],t?void 0:DEFAULT_BASE_URL),n=_(this,b,be).call(this,s),o=await this.getPrimaryPhp(),i=removePathPrefix(decodeURIComponent(n.pathname),p(this,M));let a=_(this,b,oe).call(this,i);if(o.isDir(a)){if(!i.endsWith("/"))return StreamedPHPResponse.fromPHPResponse(new PHPResponse(301,{location:[`${n.pathname}/`]},new Uint8Array(0)));for(const l of["index.php","index.html"]){const c=util.joinPaths(a,l);if(o.isFile(c)){a=c,n.pathname=util.joinPaths(n.pathname,l);break}}}if(!o.isFile(a)){let l=i;for(;l.startsWith("/")&&l!==util.dirname(l);){l=util.dirname(l);const c=_(this,b,oe).call(this,l);if(o.isFile(c)&&c.endsWith(".php")){a=_(this,b,oe).call(this,l);break}}}if(!o.isFile(a)){const l=this.getFileNotFoundAction(n.pathname);switch(l.type){case"response":return StreamedPHPResponse.fromPHPResponse(l.response);case"internal-redirect":a=util.joinPaths(p(this,A),l.uri);break;case"404":return StreamedPHPResponse.forHttpCode(404);default:throw new Error(`Unsupported file-not-found action type: '${l.type}'`)}}return o.isFile(a)?a.endsWith(".php")?await _(this,b,Te).call(this,e,s,n,a):StreamedPHPResponse.fromPHPResponse(_(this,b,He).call(this,o,a)):StreamedPHPResponse.forHttpCode(404)}prepare_$_SERVER_superglobal(e,t,s){const n={REMOTE_ADDR:"127.0.0.1",DOCUMENT_ROOT:p(this,A),HTTPS:p(this,Z).startsWith("https://")?"on":""};return n.REQUEST_URI=e.pathname+e.search,s.startsWith(p(this,A))&&(n.SCRIPT_NAME=s.substring(p(this,A).length),n.PHP_SELF=t.pathname,n.REQUEST_URI.startsWith(n.SCRIPT_NAME)&&(n.PATH_INFO=n.REQUEST_URI.substring(n.SCRIPT_NAME.length),n.PATH_INFO.includes("?")&&(n.PATH_INFO=n.PATH_INFO.substring(0,n.PATH_INFO.indexOf("?"))))),n.QUERY_STRING=t.search.substring(1),n}async[Symbol.asyncDispose](){await this.instanceManager[Symbol.asyncDispose]()}}A=new WeakMap,Q=new WeakMap,re=new WeakMap,Y=new WeakMap,K=new WeakMap,M=new WeakMap,Z=new WeakMap,$=new WeakMap,se=new WeakMap,b=new WeakSet,be=function(e){const t=removePathPrefix(decodeURIComponent(e.pathname),p(this,M)),s=applyRewriteRules(t,this.rewriteRules),n=new URL(util.joinPaths(p(this,M),s),e.toString());for(const[o,i]of e.searchParams.entries())n.searchParams.append(o,i);return n},oe=function(e){for(const t of p(this,se))if(e===t.urlPrefix||e.startsWith(t.urlPrefix+"/")){const s=e.slice(t.urlPrefix.length);return util.joinPaths(t.fsPath,s)}return util.joinPaths(p(this,A),e)},He=function(e,t){const s=e.readFileAsBuffer(t);return new PHPResponse(200,{"content-length":[`${s.byteLength}`],"content-type":[inferMimeType(t)],"accept-ranges":["bytes"],"cache-control":["public, max-age=0"]},s)},Te=async function(e,t,s,n){let o;try{o=await this.instanceManager.acquirePHPInstance()}catch(a){return a instanceof MaxPhpInstancesError?StreamedPHPResponse.forHttpCode(502):StreamedPHPResponse.forHttpCode(500)}let i;try{i=await _(this,b,Le).call(this,o.php,e,t,s,n)}catch(a){throw o.reap(),a}return i.finished.finally(()=>{o==null||o.reap()}),i},Le=async function(e,t,s,n,o){let i="GET";const a={host:p(this,K),...normalizeHeaders(t.headers||{})};p(this,$)&&(a.cookie=p(this,$).getCookieRequestHeader());let l=t.body;if(typeof l=="object"&&!(l instanceof Uint8Array)){i="POST";const{bytes:u,contentType:d}=await encodeAsMultipart(l);l=u,a["content-type"]=d}const c=await e.runStream({relativeUri:ensurePathPrefix(toRelativeUrl(new URL(n.toString())),p(this,M)),protocol:p(this,Q),method:t.method||i,$_SERVER:this.prepare_$_SERVER_superglobal(s,n,o),body:l,scriptPath:o,headers:a});if(p(this,$)){const u=await c.headers;p(this,$).rememberCookiesFromResponseHeaders(u)}return c};function inferMimeType(r){const e=r.split(".").pop();return mimeTypes[e]||mimeTypes._default}function applyRewriteRules(r,e){for(const t of e)if(new RegExp(t.match).test(r)){r=r.replace(t.match,t.replacement);break}return r}function looksLikeAbsoluteUrl(r){try{return new URL(r),!0}catch{return!1}}function rotatePHPRuntime({php:r,recreateRuntime:e,maxRequests:t=400}){return r.enableRuntimeRotation({recreateRuntime:e,maxRequests:t})}async function writeFiles(r,e,t,{rmRoot:s=!1}={}){s&&await r.isDir(e)&&await r.rmdir(e,{recursive:!0});for(const[n,o]of Object.entries(t)){const i=util.joinPaths(e,n);await r.fileExists(util.dirname(i))||await r.mkdir(util.dirname(i)),o instanceof Uint8Array||typeof o=="string"?await r.writeFile(i,o):await writeFiles(r,i,o)}}const schema12={properties:{name:{type:"string"},version:{type:"string"},mode:{type:"string",const:"php-extension"},loadWithIniDirective:{$ref:"#/definitions/PHPExtensionLoadDirective",description:"The first directive of the generated startup `.ini` file. Defaults to `extension`; use `zend_extension` for Zend extensions like Xdebug. Use `false` to stage the `.so` without registering it in php.ini."},iniEntries:{type:"object",additionalProperties:{type:"string"},description:"Additional `key=value` lines for the generated startup `.ini` file."},env:{type:"object",additionalProperties:{type:"string"},description:"Environment variables added before the extension is loaded."},extensionDir:{type:"string",description:"VFS directory where PHP.wasm writes the extension `.so` file and its per-extension ini file. Defaults to `PHP_EXTENSIONS_DIR`."},artifacts:{type:"array",items:{type:"object",properties:{phpVersion:{type:"string",description:"PHP major/minor version, e.g. `8.4`."},sourcePath:{type:"string",description:"Relative to the manifest URL/base URL, or an absolute URL."},extraFiles:{$ref:"#/definitions/PHPExtensionManifestExtraFiles",description:"URL-backed files needed only by this artifact."}},required:["phpVersion","sourcePath"],additionalProperties:!1}},extraFiles:{$ref:"#/definitions/PHPExtensionManifestExtraFiles",description:"URL-backed files shared by every artifact in this manifest."}}},schema15={properties:{nodes:{items:{properties:{type:{enum:["file","directory"]}}}}}},func2=Object.prototype.hasOwnProperty,schema14={enum:["extension","zend_extension"]};function validate12(r,{instancePath:e="",parentData:t,parentDataProperty:s,rootData:n=r}={}){let o=null,i=0;const a=i;let l=!1;const c=i;if(typeof r!="string"){const d={instancePath:e,schemaPath:"#/definitions/PHPExtensionIniDirective/type",keyword:"type",params:{type:"string"},message:"must be string"};o===null?o=[d]:o.push(d),i++}if(!(r==="extension"||r==="zend_extension")){const d={instancePath:e,schemaPath:"#/definitions/PHPExtensionIniDirective/enum",keyword:"enum",params:{allowedValues:schema14.enum},message:"must be equal to one of the allowed values"};o===null?o=[d]:o.push(d),i++}var u=c===i;if(l=l||u,!l){const d=i;if(typeof r!="boolean"){const P={instancePath:e,schemaPath:"#/anyOf/1/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};o===null?o=[P]:o.push(P),i++}if(r!==!1){const P={instancePath:e,schemaPath:"#/anyOf/1/const",keyword:"const",params:{allowedValue:!1},message:"must be equal to constant"};o===null?o=[P]:o.push(P),i++}var u=d===i;l=l||u}if(l)i=a,o!==null&&(a?o.length=a:o=null);else{const d={instancePath:e,schemaPath:"#/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};return o===null?o=[d]:o.push(d),i++,validate12.errors=o,!1}return validate12.errors=o,i===0}function validate11(r,{instancePath:e="",parentData:t,parentDataProperty:s,rootData:n=r}={}){let o=null,i=0;if(i===0)if(r&&typeof r=="object"&&!Array.isArray(r)){let L;if(r.name===void 0&&(L="name")||r.artifacts===void 0&&(L="artifacts"))return validate11.errors=[{instancePath:e,schemaPath:"#/required",keyword:"required",params:{missingProperty:L},message:"must have required property '"+L+"'"}],!1;{const O=i;for(const f in r)if(!func2.call(schema12.properties,f))return validate11.errors=[{instancePath:e,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:f},message:"must NOT have additional properties"}],!1;if(O===i){if(r.name!==void 0){const f=i;if(typeof r.name!="string")return validate11.errors=[{instancePath:e+"/name",schemaPath:"#/properties/name/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var a=f===i}else var a=!0;if(a){if(r.version!==void 0){const f=i;if(typeof r.version!="string")return validate11.errors=[{instancePath:e+"/version",schemaPath:"#/properties/version/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var a=f===i}else var a=!0;if(a){if(r.mode!==void 0){let f=r.mode;const R=i;if(typeof f!="string")return validate11.errors=[{instancePath:e+"/mode",schemaPath:"#/properties/mode/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if(f!=="php-extension")return validate11.errors=[{instancePath:e+"/mode",schemaPath:"#/properties/mode/const",keyword:"const",params:{allowedValue:"php-extension"},message:"must be equal to constant"}],!1;var a=R===i}else var a=!0;if(a){if(r.loadWithIniDirective!==void 0){const f=i;validate12(r.loadWithIniDirective,{instancePath:e+"/loadWithIniDirective",parentData:r,parentDataProperty:"loadWithIniDirective",rootData:n})||(o=o===null?validate12.errors:o.concat(validate12.errors),i=o.length);var a=f===i}else var a=!0;if(a){if(r.iniEntries!==void 0){let f=r.iniEntries;const R=i;if(i===R)if(f&&typeof f=="object"&&!Array.isArray(f))for(const D in f){const m=i;if(typeof f[D]!="string")return validate11.errors=[{instancePath:e+"/iniEntries/"+D.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/iniEntries/additionalProperties/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var l=m===i;if(!l)break}else return validate11.errors=[{instancePath:e+"/iniEntries",schemaPath:"#/properties/iniEntries/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var a=R===i}else var a=!0;if(a){if(r.env!==void 0){let f=r.env;const R=i;if(i===R)if(f&&typeof f=="object"&&!Array.isArray(f))for(const D in f){const m=i;if(typeof f[D]!="string")return validate11.errors=[{instancePath:e+"/env/"+D.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/env/additionalProperties/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var c=m===i;if(!c)break}else return validate11.errors=[{instancePath:e+"/env",schemaPath:"#/properties/env/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var a=R===i}else var a=!0;if(a){if(r.extensionDir!==void 0){const f=i;if(typeof r.extensionDir!="string")return validate11.errors=[{instancePath:e+"/extensionDir",schemaPath:"#/properties/extensionDir/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var a=f===i}else var a=!0;if(a){if(r.artifacts!==void 0){let f=r.artifacts;const R=i;if(i===R)if(Array.isArray(f)){var u=!0;const D=f.length;for(let m=0;m<D;m++){let w=f[m];const q=i;if(i===q)if(w&&typeof w=="object"&&!Array.isArray(w)){let W;if(w.phpVersion===void 0&&(W="phpVersion")||w.sourcePath===void 0&&(W="sourcePath"))return validate11.errors=[{instancePath:e+"/artifacts/"+m,schemaPath:"#/properties/artifacts/items/required",keyword:"required",params:{missingProperty:W},message:"must have required property '"+W+"'"}],!1;{const H=i;for(const y in w)if(!(y==="phpVersion"||y==="sourcePath"||y==="extraFiles"))return validate11.errors=[{instancePath:e+"/artifacts/"+m,schemaPath:"#/properties/artifacts/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:y},message:"must NOT have additional properties"}],!1;if(H===i){if(w.phpVersion!==void 0){const y=i;if(typeof w.phpVersion!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/phpVersion",schemaPath:"#/properties/artifacts/items/properties/phpVersion/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var d=y===i}else var d=!0;if(d){if(w.sourcePath!==void 0){const y=i;if(typeof w.sourcePath!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/sourcePath",schemaPath:"#/properties/artifacts/items/properties/sourcePath/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var d=y===i}else var d=!0;if(d)if(w.extraFiles!==void 0){let y=w.extraFiles;const ne=i;if(i===i)if(y&&typeof y=="object"&&!Array.isArray(y)){const ue=i;for(const v in y)if(!(v==="vfsRoot"||v==="nodes"))return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:v},message:"must NOT have additional properties"}],!1;if(ue===i){if(y.vfsRoot!==void 0){const v=i;if(typeof y.vfsRoot!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/vfsRoot",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/vfsRoot/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var h=v===i}else var h=!0;if(h)if(y.nodes!==void 0){let v=y.nodes;const ie=i;if(i===ie)if(Array.isArray(v)){var P=!0;const Me=v.length;for(let C=0;C<Me;C++){let I=v[C];const ye=i;if(i===ye)if(I&&typeof I=="object"&&!Array.isArray(I)){let de;if(I.vfsPath===void 0&&(de="vfsPath"))return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/required",keyword:"required",params:{missingProperty:de},message:"must have required property '"+de+"'"}],!1;{const Ce=i;for(const T in I)if(!(T==="vfsPath"||T==="type"||T==="sourcePath"))return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:T},message:"must NOT have additional properties"}],!1;if(Ce===i){if(I.vfsPath!==void 0){const T=i;if(typeof I.vfsPath!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C+"/vfsPath",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/vfsPath/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var S=T===i}else var S=!0;if(S){if(I.type!==void 0){let T=I.type;const Ae=i;if(typeof T!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C+"/type",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if(!(T==="file"||T==="directory"))return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C+"/type",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/enum",keyword:"enum",params:{allowedValues:schema15.properties.nodes.items.properties.type.enum},message:"must be equal to one of the allowed values"}],!1;var S=Ae===i}else var S=!0;if(S)if(I.sourcePath!==void 0){const T=i;if(typeof I.sourcePath!="string")return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C+"/sourcePath",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/sourcePath/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var S=T===i}else var S=!0}}}}else return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes/"+C,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var P=ye===i;if(!P)break}}else return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles/nodes",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;var h=ie===i}else var h=!0}}else return validate11.errors=[{instancePath:e+"/artifacts/"+m+"/extraFiles",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var d=ne===i}else var d=!0}}}}else return validate11.errors=[{instancePath:e+"/artifacts/"+m,schemaPath:"#/properties/artifacts/items/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var u=q===i;if(!u)break}}else return validate11.errors=[{instancePath:e+"/artifacts",schemaPath:"#/properties/artifacts/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;var a=R===i}else var a=!0;if(a)if(r.extraFiles!==void 0){let f=r.extraFiles;const R=i;if(i===i)if(f&&typeof f=="object"&&!Array.isArray(f)){const m=i;for(const w in f)if(!(w==="vfsRoot"||w==="nodes"))return validate11.errors=[{instancePath:e+"/extraFiles",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:w},message:"must NOT have additional properties"}],!1;if(m===i){if(f.vfsRoot!==void 0){const w=i;if(typeof f.vfsRoot!="string")return validate11.errors=[{instancePath:e+"/extraFiles/vfsRoot",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/vfsRoot/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var N=w===i}else var N=!0;if(N)if(f.nodes!==void 0){let w=f.nodes;const q=i;if(i===q)if(Array.isArray(w)){var B=!0;const W=w.length;for(let H=0;H<W;H++){let y=w[H];const ne=i;if(i===ne)if(y&&typeof y=="object"&&!Array.isArray(y)){let ce;if(y.vfsPath===void 0&&(ce="vfsPath"))return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/required",keyword:"required",params:{missingProperty:ce},message:"must have required property '"+ce+"'"}],!1;{const ue=i;for(const v in y)if(!(v==="vfsPath"||v==="type"||v==="sourcePath"))return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:v},message:"must NOT have additional properties"}],!1;if(ue===i){if(y.vfsPath!==void 0){const v=i;if(typeof y.vfsPath!="string")return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H+"/vfsPath",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/vfsPath/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var k=v===i}else var k=!0;if(k){if(y.type!==void 0){let v=y.type;const ie=i;if(typeof v!="string")return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H+"/type",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;if(!(v==="file"||v==="directory"))return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H+"/type",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/enum",keyword:"enum",params:{allowedValues:schema15.properties.nodes.items.properties.type.enum},message:"must be equal to one of the allowed values"}],!1;var k=ie===i}else var k=!0;if(k)if(y.sourcePath!==void 0){const v=i;if(typeof y.sourcePath!="string")return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H+"/sourcePath",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/sourcePath/type",keyword:"type",params:{type:"string"},message:"must be string"}],!1;var k=v===i}else var k=!0}}}}else return validate11.errors=[{instancePath:e+"/extraFiles/nodes/"+H,schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var B=ne===i;if(!B)break}}else return validate11.errors=[{instancePath:e+"/extraFiles/nodes",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/type",keyword:"type",params:{type:"array"},message:"must be array"}],!1;var N=q===i}else var N=!0}}else return validate11.errors=[{instancePath:e+"/extraFiles",schemaPath:"#/definitions/PHPExtensionManifestExtraFiles/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;var a=R===i}else var a=!0}}}}}}}}}}else return validate11.errors=[{instancePath:e,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"}],!1;return validate11.errors=o,i===0}function validate10(r,{instancePath:e="",parentData:t,parentDataProperty:s,rootData:n=r}={}){let o=null,i=0;return validate11(r,{instancePath:e,parentData:t,parentDataProperty:s,rootData:n})||(o=o===null?validate11.errors:o.concat(validate11.errors),i=o.length),validate10.errors=o,i===0}const PHP_EXTENSIONS_DIR="/internal/shared/extensions",MAX_EXTENSION_SIDECAR_FILE_REQUESTS=5;async function resolvePHPExtension(r){const e=r.fetch??globalThis.fetch,t=r.source;let s=r.name,n;const o={},i=[];let a,l,c,u;if(t.format==="so"){if(s||(s=t.name),!s)throw new Error("name is required when loading an extension from direct bytes.");n=toUint8Array(t.bytes)}else if(t.format==="url"){let k;try{k=new URL(String(t.url))}catch{throw new Error(`source.url must be an absolute URL when loading a PHP extension from a direct URL. Received: ${String(t.url)}`)}if(s||(s=t.name),!s&&k.pathname.endsWith(".so")&&(s=util.basename(k.pathname).slice(0,-3)),!s)throw new Error("name is required when loading an extension from a direct URL.");n=await fetchBytes(e,k)}else{let k,L;if("manifest"in t?(k=t.manifest,t.baseUrl&&(L=new URL(String(t.baseUrl)))):(L=new URL(String(t.manifestUrl)),k=await(await e(L)).json()),!validate10(k))throw new Error(`Invalid PHP extension manifest: ${JSON.stringify(validate10.errors)}`);const O=k;if(!L)throw new Error("Manifest artifacts require a manifest URL or baseUrl so relative files can be resolved.");const f=O.artifacts.find(m=>m.phpVersion===r.phpVersion);if(!f)throw new Error(`No extension artifact found for PHP ${r.phpVersion}.`);s??(s=O.name),a=O.loadWithIniDirective,l=O.iniEntries,c=O.env,u=O.extensionDir;const R=new util.Semaphore({concurrency:MAX_EXTENSION_SIDECAR_FILE_REQUESTS}),le=[];for(const m of[O.extraFiles,f.extraFiles])for(const w of(m==null?void 0:m.nodes)??[]){const q=util.joinPaths(m.vfsRoot??"",w.vfsPath);if(w.type==="directory"){i.push(q);continue}if(!w.sourcePath)continue;const Ie=new URL(w.sourcePath,L);le.push(R.run(()=>fetchBytes(e,Ie)).then(W=>{o[q]=W}))}const[D]=await Promise.all([fetchBytes(e,new URL(f.sourcePath,L)),...le]);n=D}const d=util.normalizePath(r.extensionDir??u??PHP_EXTENSIONS_DIR);r.extraFiles&&(Object.assign(o,r.extraFiles.files),i.push(...r.extraFiles.directories??[]));const h=r.loadWithIniDirective??a??"extension",P={...l,...r.iniEntries},S=util.joinPaths(d,`${s}.so`),N=createPHPExtensionIniFile({directive:h,extensionDir:d,name:s,soPath:S,iniEntries:P}),B={...c,...r.env};return{soPath:S,soBytes:n,...N,extraFiles:{files:o,directories:i},env:Object.keys(B).length?B:void 0,extensionDir:d}}function withResolvedPHPExtensions(r,e){var n;if(!e.length)return r;const t={...r.ENV};for(const o of e){if(Object.assign(t,o.env),!o.iniPath)continue;const i=((n=t.PHP_INI_SCAN_DIR)==null?void 0:n.split(":"))??[];i.includes(o.extensionDir)||(i.push(o.extensionDir),t.PHP_INI_SCAN_DIR=i.join(":"))}const s=r.preRun??[];return{...r,ENV:t,preRun:[...s,o=>{for(const i of e)installPHPExtensionFilesSync(o.FS,i)}]}}function installPHPExtensionFilesSync(r,e){let t;if("soPath"in e)t=e;else{const s=e.extensionDir??PHP_EXTENSIONS_DIR,n=e.loadWithIniDirective??"extension",o=util.joinPaths(s,`${e.name}.so`),i=createPHPExtensionIniFile({directive:n,extensionDir:s,name:e.name,soPath:o,iniEntries:e.iniEntries});t={soPath:o,soBytes:toUint8Array(e.soBytes),...i,extraFiles:e.extraFiles,env:e.env,extensionDir:s}}if(mkdirIfMissing(r,t.extensionDir),r.writeFile(t.soPath,t.soBytes),t.iniPath&&t.iniContent!==void 0&&r.writeFile(t.iniPath,t.iniContent),t.extraFiles){const{directories:s=[],files:n}=t.extraFiles;for(const o of s)mkdirIfMissing(r,o);for(const[o,i]of Object.entries(n))mkdirIfMissing(r,util.dirname(o)),r.writeFile(o,i)}return t}function createPHPExtensionIniFile(r){if(r.directive===!1)return{};const e=[`${r.directive}=${r.soPath}`,...Object.entries(r.iniEntries??{}).map(([t,s])=>`${t}=${s}`)];return{iniPath:util.joinPaths(r.extensionDir,`${r.name}.ini`),iniContent:e.join(`
|
|
91
91
|
`)}}function mkdirIfMissing(r,e){FSHelpers.fileExists(r,e)||r.mkdirTree(e)}async function fetchBytes(r,e){const t=await r(e);if(!t.ok)throw new Error(`Failed to fetch ${String(e)}: ${t.status}`);return new Uint8Array(await t.arrayBuffer())}function toUint8Array(r){return r instanceof Uint8Array?r:new Uint8Array(r)}function isLegacyPhpInstance(r){var n;const e=Object.getOwnPropertySymbols(r)[0],t=r[e],s=(n=t==null?void 0:t.phpVersion)==null?void 0:n.major;return typeof s=="number"&&s<7}function ensureProxyFSHasMmapSupport(r){const e=Object.getOwnPropertySymbols(r)[0],t=r[e],s=t.PROXYFS,n=t.FS;s.stream_ops.mmap||(s.stream_ops.mmap=function(o,i,a,l,c){if(!n.isFile(o.node.mode))throw new n.ErrnoError(19);if(a!==0)throw new n.ErrnoError(22);const u=t.malloc(i);if(!u)throw new n.ErrnoError(48);const d=t.HEAPU8.subarray(u,u+i);let h=0;for(;h<i;){const P=o.stream_ops.read(o,d,h,i-h,h);if(P<=0)break;h+=P}if(h!==i)throw t.free(u),new n.ErrnoError(5);return{ptr:u,allocated:!0}},s.stream_ops.msync=function(o,i,a,l,c){return c&2||o.stream_ops.write(o,i,a,l,a,!1),0})}async function proxyFileSystem(r,e,t){const s=isLegacyPhpInstance(e),n=Object.getOwnPropertySymbols(r)[0];for(const o of t)r.fileExists(o)||r.mkdir(o),e.mkdir(o),await e.mount(o,i=>{s||ensureProxyFSHasMmapSupport(i);const a=Object.getOwnPropertySymbols(i)[0];return i[a].FS.mount(i[a].PROXYFS,{root:o,fs:r[n].FS},o),()=>{try{i[a].FS.unmount(o)}catch{}}})}function isPathToSharedFS(r,e){var o;const t=Object.getOwnPropertySymbols(r)[0],n=r[t].FS.lookupPath(e,{noent_okay:!0});return((o=n==null?void 0:n.node)==null?void 0:o.isSharedFS)??!1}function sandboxedSpawnHandlerFactory(r){return util.createSpawnHandler(async function(e,t,s){t.notifySpawn(),(e==null?void 0:e[0])==="/bin/sh"&&(e==null?void 0:e[1])==="-c"&&typeof e[2]=="string"&&(e=util.splitShellCommand(e[2])),e[0]==="exec"&&e.shift(),(e[0].endsWith(".php")||e[0].endsWith(".phar"))&&e.unshift("php");const n=e[0].split("/").pop();if(e[0]==="/usr/bin/env"&&e[1]==="stty"&&e[2]==="size")t.stdout("18 140"),t.exit(0);else if(n==="tput"&&e[1]==="cols")t.stdout("140"),t.exit(0);else if(n==="less"){t.on("stdin",a=>{t.stdout(a)}),await new Promise(a=>{t.childProcess.stdin.on("finish",()=>{a(!0)})}),t.exit(0);return}if(!["php","ls","pwd"].includes(n??"")){t.exit(127);return}if(!r){logger.logger.warn("Tried to spawn a PHP subprocess, but the sandboxed spawn handler was created without a getPHPInstance function."),t.exit(127);return}const{php:o,reap:i}=await r();try{s.cwd&&await o.chdir(s.cwd);const a=await o.cwd();switch(n){case"php":{const l=await o.cli(e,{env:{...s.env,SCRIPT_PATH:e[1],SHELL_PIPE:"0"}});l.stdout.pipeTo(new WritableStream({write(c){t.stdout(c)}})),l.stderr.pipeTo(new WritableStream({write(c){t.stderr(c)}})),t.exit(await l.exitCode);break}case"ls":{const l=await o.listFiles(e[1]??a);for(const c of l)t.stdout(c+`
|
|
92
92
|
`);await new Promise(c=>setTimeout(c,10)),t.exit(0);break}case"pwd":{t.stdout(a+`
|
|
93
93
|
`),await new Promise(l=>setTimeout(l,10)),t.exit(0);break}}}catch(a){const l=a instanceof Error?a.message+`
|