@php-wasm/universal 0.5.2 → 0.5.3

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 CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";var se=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var i=(s,e,t)=>(se(s,e,"read from private field"),t?t.call(s):e.get(s)),c=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)},p=(s,e,t,r)=>(se(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t);var m=(s,e,t)=>(se(s,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const le=Symbol("error"),ce=Symbol("message");class oe extends Event{constructor(e,t={}){super(e),this[le]=t.error===void 0?null:t.error,this[ce]=t.message===void 0?"":t.message}get error(){return this[le]}get message(){return this[ce]}}Object.defineProperty(oe.prototype,"error",{enumerable:!0});Object.defineProperty(oe.prototype,"message",{enumerable:!0});const qe=typeof globalThis.ErrorEvent=="function"?globalThis.ErrorEvent:oe;function ye(s){return s instanceof Error?"exitCode"in s&&(s==null?void 0:s.exitCode)===0||(s==null?void 0:s.name)==="ExitStatus"&&"status"in s&&s.status===0:!1}class ge extends EventTarget{constructor(){super(...arguments),this.listenersCount=0}addEventListener(e,t){++this.listenersCount,super.addEventListener(e,t)}removeEventListener(e,t){--this.listenersCount,super.removeEventListener(e,t)}hasListeners(){return this.listenersCount>0}}function je(s){s.asm={...s.asm};const e=new ge;for(const t in s.asm)if(typeof s.asm[t]=="function"){const r=s.asm[t];s.asm[t]=function(...n){var o;try{return r(...n)}catch(a){if(!(a instanceof Error))throw a;const h=We(a,(o=s.lastAsyncifyStackSource)==null?void 0:o.stack);if(s.lastAsyncifyStackSource&&(a.cause=s.lastAsyncifyStackSource),e.hasListeners()){e.dispatchEvent(new qe("error",{error:a,message:h}));return}throw ye(a)||Ve(h),a}}}return e}let re=[];function De(){return re}function We(s,e){if(s.message==="unreachable"){let t=ze;e||(t+=`
1
+ "use strict";var se=(r,e,t)=>{if(!e.has(r))throw TypeError("Cannot "+t)};var a=(r,e,t)=>(se(r,e,"read from private field"),t?t.call(r):e.get(r)),u=(r,e,t)=>{if(e.has(r))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(r):e.set(r,t)},p=(r,e,t,s)=>(se(r,e,"write to private field"),s?s.call(r,t):e.set(r,t),t);var m=(r,e,t)=>(se(r,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});if(typeof File>"u"){class r extends Blob{constructor(t,s,n){super(t);let i;n!=null&&n.lastModified&&(i=new Date),(!i||isNaN(i.getFullYear()))&&(i=new Date),this.lastModifiedDate=i,this.lastModified=i.getMilliseconds(),this.name=s||""}}global.File=r}function we(r){return new Promise(function(e,t){r.onload=r.onerror=function(s){r.onload=r.onerror=null,s.type==="load"?e(r.result):t(new Error("Failed to read the blob/file"))}})}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const e=new FileReader;return e.readAsArrayBuffer(this),we(e)});typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const e=new FileReader;return e.readAsText(this),we(e)});function We(){const r=new Uint8Array([1,2,3,4]),t=new File([r],"test").stream();try{return t.getReader({mode:"byob"}),t.getReader({mode:"byob"}),!0}catch{return!1}}(typeof Blob.prototype.stream>"u"||!We())&&(Blob.prototype.stream=function(){let r=0;const e=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(t){const s=t.byobRequest.view,i=await e.slice(r,r+s.byteLength).arrayBuffer(),o=new Uint8Array(i);new Uint8Array(s.buffer).set(o);const l=o.byteLength;t.byobRequest.respond(l),r+=l,r>=e.size&&t.close()}})});if(typeof CustomEvent>"u"){class r extends Event{constructor(t,s={}){super(t,s),this.detail=s.detail}initCustomEvent(){}}globalThis.CustomEvent=r}const ue=Symbol("error"),he=Symbol("message");class ae extends Event{constructor(e,t={}){super(e),this[ue]=t.error===void 0?null:t.error,this[he]=t.message===void 0?"":t.message}get error(){return this[ue]}get message(){return this[he]}}Object.defineProperty(ae.prototype,"error",{enumerable:!0});Object.defineProperty(ae.prototype,"message",{enumerable:!0});const ze=typeof globalThis.ErrorEvent=="function"?globalThis.ErrorEvent:ae;function ge(r){return r instanceof Error?"exitCode"in r&&(r==null?void 0:r.exitCode)===0||(r==null?void 0:r.name)==="ExitStatus"&&"status"in r&&r.status===0:!1}class Pe extends EventTarget{constructor(){super(...arguments),this.listenersCount=0}addEventListener(e,t){++this.listenersCount,super.addEventListener(e,t)}removeEventListener(e,t){--this.listenersCount,super.removeEventListener(e,t)}hasListeners(){return this.listenersCount>0}}function Ge(r){r.asm={...r.asm};const e=new Pe;for(const t in r.asm)if(typeof r.asm[t]=="function"){const s=r.asm[t];r.asm[t]=function(...n){var i;try{return s(...n)}catch(o){if(!(o instanceof Error))throw o;const l=Je(o,(i=r.lastAsyncifyStackSource)==null?void 0:i.stack);if(r.lastAsyncifyStackSource&&(o.cause=r.lastAsyncifyStackSource),e.hasListeners()){e.dispatchEvent(new ze("error",{error:o,message:l}));return}throw ge(o)||Ze(l),o}}}return e}let ne=[];function Ve(){return ne}function Je(r,e){if(r.message==="unreachable"){let t=Ye;e||(t+=`
2
2
 
3
3
  This stack trace is lacking. For a better one initialize
4
4
  the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
5
5
 
6
- `),re=Je(e||s.stack||"");for(const r of re)t+=` * ${r}
7
- `;return t}return s.message}const ze=`
6
+ `),ne=Qe(e||r.stack||"");for(const s of ne)t+=` * ${s}
7
+ `;return t}return r.message}const Ye=`
8
8
  "unreachable" WASM instruction executed.
9
9
 
10
10
  The typical reason is a PHP function missing from the ASYNCIFY_ONLY
@@ -28,13 +28,13 @@ the Dockerfile, you'll need to trigger this error again with long stack
28
28
  traces enabled. In node.js, you can do it using the --stack-trace-limit=100
29
29
  CLI option:
30
30
 
31
- `,he="\x1B[41m",Ge="\x1B[1m",ue="\x1B[0m",de="\x1B[K";let pe=!1;function Ve(s){if(!pe){pe=!0,console.log(`${he}
32
- ${de}
33
- ${Ge} WASM ERROR${ue}${he}`);for(const e of s.split(`
34
- `))console.log(`${de} ${e} `);console.log(`${ue}`)}}function Je(s){try{const e=s.split(`
35
- `).slice(1).map(t=>{const r=t.trim().substring(3).split(" ");return{fn:r.length>=2?r[0]:"<unknown>",isWasm:t.includes("wasm://")}}).filter(({fn:t,isWasm:r})=>r&&!t.startsWith("dynCall_")&&!t.startsWith("invoke_")).map(({fn:t})=>t);return Array.from(new Set(e))}catch{return[]}}class C{constructor(e,t,r,n="",o=0){this.httpStatusCode=e,this.headers=t,this.bytes=r,this.exitCode=o,this.errors=n}static fromRawData(e){return new C(e.httpStatusCode,e.headers,e.bytes,e.errors,e.exitCode)}toRawData(){return{headers:this.headers,bytes:this.bytes,errors:this.errors,exitCode:this.exitCode,httpStatusCode:this.httpStatusCode}}get json(){return JSON.parse(this.text)}get text(){return new TextDecoder().decode(this.bytes)}}const ae=["8.3","8.2","8.1","8.0","7.4","7.3","7.2","7.1","7.0"],Ye=ae[0],Ke=ae,Pe=["iconv","mbstring","xml-bundle","gd"],Ze={"kitchen-sink":Pe};var S,L;class we{constructor(e,t={}){c(this,S,void 0);c(this,L,void 0);this.requestHandler=e,p(this,S,{}),p(this,L,{handleRedirects:!1,maxRedirects:4,...t})}async request(e,t=0){const r=await this.requestHandler.request({...e,headers:{...e.headers,cookie:this.serializeCookies()}});if(r.headers["set-cookie"]&&this.setCookies(r.headers["set-cookie"]),i(this,L).handleRedirects&&r.headers.location&&t<i(this,L).maxRedirects){const n=new URL(r.headers.location[0],this.requestHandler.absoluteUrl);return this.request({url:n.toString(),method:"GET",headers:{}},t+1)}return r}pathToInternalUrl(e){return this.requestHandler.pathToInternalUrl(e)}internalUrlToPath(e){return this.requestHandler.internalUrlToPath(e)}get absoluteUrl(){return this.requestHandler.absoluteUrl}get documentRoot(){return this.requestHandler.documentRoot}setCookies(e){for(const t of e)try{if(!t.includes("="))continue;const r=t.indexOf("="),n=t.substring(0,r),o=t.substring(r+1).split(";")[0];i(this,S)[n]=o}catch(r){console.error(r)}}serializeCookies(){const e=[];for(const t in i(this,S))e.push(`${t}=${i(this,S)[t]}`);return e.join("; ")}}S=new WeakMap,L=new WeakMap;class be{constructor({concurrency:e}){this._running=0,this.concurrency=e,this.queue=[]}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency)await new Promise(e=>this.queue.push(e));else{this._running++;let e=!1;return()=>{e||(e=!0,this._running--,this.queue.length>0&&this.queue.shift()())}}}async run(e){const t=await this.acquire();try{return await e()}finally{t()}}}const _e="http://example.com";function ne(s){return s.toString().substring(s.origin.length)}function ie(s,e){return!e||!s.startsWith(e)?s:s.substring(e.length)}function Ee(s,e){return!e||s.startsWith(e)?s:e+s}var b,A,N,H,$,_,U,O,q,xe,j,Re,D,Se;class ve{constructor(e,t={}){c(this,q);c(this,j);c(this,D);c(this,b,void 0);c(this,A,void 0);c(this,N,void 0);c(this,H,void 0);c(this,$,void 0);c(this,_,void 0);c(this,U,void 0);c(this,O,void 0);p(this,O,new be({concurrency:1}));const{documentRoot:r="/www/",absoluteUrl:n=typeof location=="object"?location==null?void 0:location.href:""}=t;this.php=e,p(this,b,r);const o=new URL(n);p(this,N,o.hostname),p(this,H,o.port?Number(o.port):o.protocol==="https:"?443:80),p(this,A,(o.protocol||"").replace(":",""));const a=i(this,H)!==443&&i(this,H)!==80;p(this,$,[i(this,N),a?`:${i(this,H)}`:""].join("")),p(this,_,o.pathname.replace(/\/+$/,"")),p(this,U,[`${i(this,A)}://`,i(this,$),i(this,_)].join(""))}pathToInternalUrl(e){return`${this.absoluteUrl}${e}`}internalUrlToPath(e){const t=new URL(e);return t.pathname.startsWith(i(this,_))&&(t.pathname=t.pathname.slice(i(this,_).length)),ne(t)}get isRequestRunning(){return i(this,O).running>0}get absoluteUrl(){return i(this,U)}get documentRoot(){return i(this,b)}async request(e){const t=e.url.startsWith("http://")||e.url.startsWith("https://"),r=new URL(e.url,t?void 0:_e),n=ie(r.pathname,i(this,_)),o=`${i(this,b)}${n}`;return et(o)?await m(this,j,Re).call(this,e,r):m(this,q,xe).call(this,o)}}b=new WeakMap,A=new WeakMap,N=new WeakMap,H=new WeakMap,$=new WeakMap,_=new WeakMap,U=new WeakMap,O=new WeakMap,q=new WeakSet,xe=function(e){if(!this.php.fileExists(e))return new C(404,{"x-file-type":["static"]},new TextEncoder().encode("404 File not found"));const t=this.php.readFileAsBuffer(e);return new C(200,{"content-length":[`${t.byteLength}`],"content-type":[Xe(e)],"accept-ranges":["bytes"],"cache-control":["public, max-age=0"]},t)},j=new WeakSet,Re=async function(e,t){var n;const r=await i(this,O).acquire();try{this.php.addServerGlobalEntry("DOCUMENT_ROOT",i(this,b)),this.php.addServerGlobalEntry("HTTPS",i(this,U).startsWith("https://")?"on":"");let o="GET";const a={host:i(this,$),...Be(e.headers||{})},h=[];if(e.files&&Object.keys(e.files).length){o="POST";for(const u in e.files){const E=e.files[u];h.push({key:u,name:E.name,type:E.type,data:new Uint8Array(await E.arrayBuffer())})}(n=a["content-type"])!=null&&n.startsWith("multipart/form-data")&&(e.formData=Qe(e.body||""),a["content-type"]="application/x-www-form-urlencoded",delete e.body)}let d;e.formData!==void 0?(o="POST",a["content-type"]=a["content-type"]||"application/x-www-form-urlencoded",d=new URLSearchParams(e.formData).toString()):d=e.body;let f;try{f=m(this,D,Se).call(this,t.pathname)}catch{return new C(404,{},new TextEncoder().encode("404 File not found"))}return await this.php.run({relativeUri:Ee(ne(t),i(this,_)),protocol:i(this,A),method:e.method||o,body:d,fileInfos:h,scriptPath:f,headers:a})}finally{r()}},D=new WeakSet,Se=function(e){let t=ie(e,i(this,_));t.includes(".php")?t=t.split(".php")[0]+".php":(t.endsWith("/")||(t+="/"),t.endsWith("index.php")||(t+="index.php"));const r=`${i(this,b)}${t}`;if(this.php.fileExists(r))return r;if(!this.php.fileExists(`${i(this,b)}/index.php`))throw new Error(`File not found: ${r}`);return`${i(this,b)}/index.php`};function Qe(s){const e={},t=s.match(/--(.*)\r\n/);if(!t)return e;const r=t[1],n=s.split(`--${r}`);return n.shift(),n.pop(),n.forEach(o=>{const a=o.indexOf(`\r
31
+ `,de="\x1B[41m",Ke="\x1B[1m",fe="\x1B[0m",pe="\x1B[K";let me=!1;function Ze(r){if(!me){me=!0,console.log(`${de}
32
+ ${pe}
33
+ ${Ke} WASM ERROR${fe}${de}`);for(const e of r.split(`
34
+ `))console.log(`${pe} ${e} `);console.log(`${fe}`)}}function Qe(r){try{const e=r.split(`
35
+ `).slice(1).map(t=>{const s=t.trim().substring(3).split(" ");return{fn:s.length>=2?s[0]:"<unknown>",isWasm:t.includes("wasm://")}}).filter(({fn:t,isWasm:s})=>s&&!t.startsWith("dynCall_")&&!t.startsWith("invoke_")).map(({fn:t})=>t);return Array.from(new Set(e))}catch{return[]}}class be{constructor({concurrency:e}){this._running=0,this.concurrency=e,this.queue=[]}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency)await new Promise(e=>this.queue.push(e));else{this._running++;let e=!1;return()=>{e||(e=!0,this._running--,this.queue.length>0&&this.queue.shift()())}}}async run(e){const t=await this.acquire();try{return await e()}finally{t()}}}function Se(...r){let e=r.join("/");const t=e[0]==="/",s=e.substring(e.length-1)==="/";return e=le(e),!e&&!t&&(e="."),e&&s&&(e+="/"),e}function Xe(r){if(r==="/")return"/";r=le(r);const e=r.lastIndexOf("/");return e===-1?"":e===0?"/":r.substr(0,e)}function le(r){const e=r[0]==="/";return r=et(r.split("/").filter(t=>!!t),!e).join("/"),(e?"/":"")+r.replace(/\/$/,"")}function et(r,e){let t=0;for(let s=r.length-1;s>=0;s--){const n=r[s];n==="."?r.splice(s,1):n===".."?(r.splice(s,1),t++):t&&(r.splice(s,1),t--)}if(e)for(;t;t--)r.unshift("..");return r}function tt(...r){const e=new Uint8Array(r.reduce((s,n)=>s+n.length,0));let t=0;for(const s of r)e.set(s,t),t+=s.length;return e}function rt(r){if(r===void 0){let e=new Uint8Array;return new TransformStream({transform(t){e=tt(e,t)},flush(t){t.enqueue(e)}})}else{const e=new ArrayBuffer(r||0);let t=0;return new TransformStream({transform(s){new Uint8Array(e).set(s,t),t+=s.byteLength},flush(s){s.enqueue(new Uint8Array(e))}})}}function st(r,e){if(e===0)return new ReadableStream({start(n){n.close()}});const t=r.getReader({mode:"byob"});let s=0;return new ReadableStream({async pull(n){const{value:i,done:o}=await t.read(new Uint8Array(e-s));if(o){t.releaseLock(),n.close();return}s+=i.length,n.enqueue(i),s>=e&&(t.releaseLock(),n.close())},cancel(){t.cancel()}})}async function nt(r,e){return e!==void 0&&(r=st(r,e)),await r.pipeThrough(rt(e)).getReader().read().then(({value:t})=>t)}class it extends File{constructor(e,t,s){super([],t,{type:s}),this.readableStream=e}slice(){throw new Error("slice() is not possible on a StreamedFile")}stream(){return this.readableStream}async text(){return new TextDecoder().decode(await this.arrayBuffer())}async arrayBuffer(){return await nt(this.stream())}}ReadableStream.prototype[Symbol.asyncIterator]||(ReadableStream.prototype[Symbol.asyncIterator]=async function*(){const r=this.getReader();try{for(;;){const{done:e,value:t}=await r.read();if(e)return;yield t}}finally{r.releaseLock()}},ReadableStream.prototype.iterate=ReadableStream.prototype[Symbol.asyncIterator]);function ot(r,e){return new ReadableStream({async pull(t){const s=await r.readFileAsBuffer(e);t.enqueue(s),t.close()}})}async function*at(r,e,{relativePaths:t=!0,pathPrefix:s,exceptPaths:n=[]}={}){e=le(e);const i=[e];for(;i.length;){const o=i.pop();if(!o)return;const l=await r.listFiles(o);for(const d of l){const f=`${o}/${d}`;if(n.includes(f.substring(e.length+1)))continue;await r.isDir(f)?i.push(f):yield new it(ot(r,f),t?Se(s||"",f.substring(e.length+1)):f)}}}function lt(r,e){return new WritableStream({async write(t){const s=Se(e,t.name);t.type==="directory"?await r.mkdir(s):(await r.mkdir(Xe(s)),await r.writeFile(s,new Uint8Array(await t.arrayBuffer())))}})}class T{constructor(e,t,s,n="",i=0){this.httpStatusCode=e,this.headers=t,this.bytes=s,this.exitCode=i,this.errors=n}static fromRawData(e){return new T(e.httpStatusCode,e.headers,e.bytes,e.errors,e.exitCode)}toRawData(){return{headers:this.headers,bytes:this.bytes,errors:this.errors,exitCode:this.exitCode,httpStatusCode:this.httpStatusCode}}get json(){return JSON.parse(this.text)}get text(){return new TextDecoder().decode(this.bytes)}}const ce=["8.3","8.2","8.1","8.0","7.4","7.3","7.2","7.1","7.0"],ct=ce[0],ut=ce,Ee=["iconv","mbstring","xml-bundle","gd"],ht={"kitchen-sink":Ee};var x,A;class Re{constructor(e,t={}){u(this,x,void 0);u(this,A,void 0);this.requestHandler=e,p(this,x,{}),p(this,A,{handleRedirects:!1,maxRedirects:4,...t})}async request(e,t=0){const s=await this.requestHandler.request({...e,headers:{...e.headers,cookie:this.serializeCookies()}});if(s.headers["set-cookie"]&&this.setCookies(s.headers["set-cookie"]),a(this,A).handleRedirects&&s.headers.location&&t<a(this,A).maxRedirects){const n=new URL(s.headers.location[0],this.requestHandler.absoluteUrl);return this.request({url:n.toString(),method:"GET",headers:{}},t+1)}return s}pathToInternalUrl(e){return this.requestHandler.pathToInternalUrl(e)}internalUrlToPath(e){return this.requestHandler.internalUrlToPath(e)}get absoluteUrl(){return this.requestHandler.absoluteUrl}get documentRoot(){return this.requestHandler.documentRoot}setCookies(e){for(const t of e)try{if(!t.includes("="))continue;const s=t.indexOf("="),n=t.substring(0,s),i=t.substring(s+1).split(";")[0];a(this,x)[n]=i}catch(s){console.error(s)}}serializeCookies(){const e=[];for(const t in a(this,x))e.push(`${t}=${a(this,x)[t]}`);return e.join("; ")}}x=new WeakMap,A=new WeakMap;const ve="http://example.com";function ie(r){return r.toString().substring(r.origin.length)}function oe(r,e){return!e||!r.startsWith(e)?r:r.substring(e.length)}function _e(r,e){return!e||r.startsWith(e)?r:e+r}var P,U,O,F,B,b,L,$,M,Fe,j,He,W,ke;class xe{constructor(e,t={}){u(this,M);u(this,j);u(this,W);u(this,P,void 0);u(this,U,void 0);u(this,O,void 0);u(this,F,void 0);u(this,B,void 0);u(this,b,void 0);u(this,L,void 0);u(this,$,void 0);p(this,$,new be({concurrency:1}));const{documentRoot:s="/www/",absoluteUrl:n=typeof location=="object"?location==null?void 0:location.href:""}=t;this.php=e,p(this,P,s);const i=new URL(n);p(this,O,i.hostname),p(this,F,i.port?Number(i.port):i.protocol==="https:"?443:80),p(this,U,(i.protocol||"").replace(":",""));const o=a(this,F)!==443&&a(this,F)!==80;p(this,B,[a(this,O),o?`:${a(this,F)}`:""].join("")),p(this,b,i.pathname.replace(/\/+$/,"")),p(this,L,[`${a(this,U)}://`,a(this,B),a(this,b)].join(""))}pathToInternalUrl(e){return`${this.absoluteUrl}${e}`}internalUrlToPath(e){const t=new URL(e);return t.pathname.startsWith(a(this,b))&&(t.pathname=t.pathname.slice(a(this,b).length)),ie(t)}get isRequestRunning(){return a(this,$).running>0}get absoluteUrl(){return a(this,L)}get documentRoot(){return a(this,P)}async request(e){const t=e.url.startsWith("http://")||e.url.startsWith("https://"),s=new URL(e.url,t?void 0:ve),n=oe(s.pathname,a(this,b)),i=`${a(this,P)}${n}`;return pt(i)?await m(this,j,He).call(this,e,s):m(this,M,Fe).call(this,i)}}P=new WeakMap,U=new WeakMap,O=new WeakMap,F=new WeakMap,B=new WeakMap,b=new WeakMap,L=new WeakMap,$=new WeakMap,M=new WeakSet,Fe=function(e){if(!this.php.fileExists(e))return new T(404,{"x-file-type":["static"]},new TextEncoder().encode("404 File not found"));const t=this.php.readFileAsBuffer(e);return new T(200,{"content-length":[`${t.byteLength}`],"content-type":[ft(e)],"accept-ranges":["bytes"],"cache-control":["public, max-age=0"]},t)},j=new WeakSet,He=async function(e,t){var n;const s=await a(this,$).acquire();try{this.php.addServerGlobalEntry("DOCUMENT_ROOT",a(this,P)),this.php.addServerGlobalEntry("HTTPS",a(this,L).startsWith("https://")?"on":"");let i="GET";const o={host:a(this,B),...Me(e.headers||{})},l=[];if(e.files&&Object.keys(e.files).length){i="POST";for(const h in e.files){const E=e.files[h];l.push({key:h,name:E.name,type:E.type,data:new Uint8Array(await E.arrayBuffer())})}(n=o["content-type"])!=null&&n.startsWith("multipart/form-data")&&(e.formData=dt(e.body||""),o["content-type"]="application/x-www-form-urlencoded",delete e.body)}let d;e.formData!==void 0?(i="POST",o["content-type"]=o["content-type"]||"application/x-www-form-urlencoded",d=new URLSearchParams(e.formData).toString()):d=e.body;let f;try{f=m(this,W,ke).call(this,t.pathname)}catch{return new T(404,{},new TextEncoder().encode("404 File not found"))}return await this.php.run({relativeUri:_e(ie(t),a(this,b)),protocol:a(this,U),method:e.method||i,body:d,fileInfos:l,scriptPath:f,headers:o})}finally{s()}},W=new WeakSet,ke=function(e){let t=oe(e,a(this,b));t.includes(".php")?t=t.split(".php")[0]+".php":(t.endsWith("/")||(t+="/"),t.endsWith("index.php")||(t+="index.php"));const s=`${a(this,P)}${t}`;if(this.php.fileExists(s))return s;if(!this.php.fileExists(`${a(this,P)}/index.php`))throw new Error(`File not found: ${s}`);return`${a(this,P)}/index.php`};function dt(r){const e={},t=r.match(/--(.*)\r\n/);if(!t)return e;const s=t[1],n=r.split(`--${s}`);return n.shift(),n.pop(),n.forEach(i=>{const o=i.indexOf(`\r
36
36
  \r
37
- `),h=o.substring(0,a).trim(),d=o.substring(a+4).trim(),f=h.match(/name="([^"]+)"/);if(f){const u=f[1];e[u]=d}}),e}function Xe(s){switch(s.split(".").pop()){case"css":return"text/css";case"js":return"application/javascript";case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"svg":return"image/svg+xml";case"woff":return"font/woff";case"woff2":return"font/woff2";case"ttf":return"font/ttf";case"otf":return"font/otf";case"eot":return"font/eot";case"ico":return"image/x-icon";case"html":return"text/html";case"json":return"application/json";case"xml":return"application/xml";case"txt":case"md":return"text/plain";default:return"application-octet-stream"}}function et(s){return tt(s)||st(s)}function tt(s){return s.endsWith(".php")||s.includes(".php/")}function st(s){return!s.split("/").pop().includes(".")}const fe={0:"No error occurred. System call completed successfully.",1:"Argument list too long.",2:"Permission denied.",3:"Address in use.",4:"Address not available.",5:"Address family not supported.",6:"Resource unavailable, or operation would block.",7:"Connection already in progress.",8:"Bad file descriptor.",9:"Bad message.",10:"Device or resource busy.",11:"Operation canceled.",12:"No child processes.",13:"Connection aborted.",14:"Connection refused.",15:"Connection reset.",16:"Resource deadlock would occur.",17:"Destination address required.",18:"Mathematics argument out of domain of function.",19:"Reserved.",20:"File exists.",21:"Bad address.",22:"File too large.",23:"Host is unreachable.",24:"Identifier removed.",25:"Illegal byte sequence.",26:"Operation in progress.",27:"Interrupted function.",28:"Invalid argument.",29:"I/O error.",30:"Socket is connected.",31:"There is a directory under that path.",32:"Too many levels of symbolic links.",33:"File descriptor value too large.",34:"Too many links.",35:"Message too large.",36:"Reserved.",37:"Filename too long.",38:"Network is down.",39:"Connection aborted by network.",40:"Network unreachable.",41:"Too many files open in system.",42:"No buffer space available.",43:"No such device.",44:"There is no such file or directory OR the parent directory does not exist.",45:"Executable file format error.",46:"No locks available.",47:"Reserved.",48:"Not enough space.",49:"No message of the desired type.",50:"Protocol not available.",51:"No space left on device.",52:"Function not supported.",53:"The socket is not connected.",54:"Not a directory or a symbolic link to a directory.",55:"Directory not empty.",56:"State not recoverable.",57:"Not a socket.",58:"Not supported, or operation not supported on socket.",59:"Inappropriate I/O control operation.",60:"No such device or address.",61:"Value too large to be stored in data type.",62:"Previous owner died.",63:"Operation not permitted.",64:"Broken pipe.",65:"Protocol error.",66:"Protocol not supported.",67:"Protocol wrong type for socket.",68:"Result too large.",69:"Read-only file system.",70:"Invalid seek.",71:"No such process.",72:"Reserved.",73:"Connection timed out.",74:"Text file busy.",75:"Cross-device link.",76:"Extension: Capabilities insufficient."};function P(s=""){return function(t,r,n){const o=n.value;n.value=function(...a){try{return o.apply(this,a)}catch(h){const d=typeof h=="object"?h==null?void 0:h.errno:null;if(d in fe){const f=fe[d],u=typeof a[0]=="string"?a[0]:null,E=u!==null?s.replaceAll("{path}",u):s;throw new Error(`${E}: ${f}`,{cause:h})}throw h}}}}const rt=Symbol("RuntimeId"),M=new Map;async function nt(s,e={},t=[]){const[r,n,o]=me(),[a,h]=me(),d=s.init(ot,{onAbort(u){o(u),h(),console.error(u)},ENV:{},locateFile:u=>u,...e,noInitialRun:!0,onRuntimeInitialized(){e.onRuntimeInitialized&&e.onRuntimeInitialized(),n()},monitorRunDependencies(u){u===0&&(delete d.monitorRunDependencies,h())}});await Promise.all(t.map(({default:u})=>u(d))),t.length||h(),await a,await r;const f=M.size;return d.originalExit=d._exit,d._exit=function(u){return M.delete(f),d.originalExit(u)},d[rt]=f,M.set(f,d),f}function it(s){return M.get(s)}const ot=function(){var s;return typeof process<"u"&&((s=process.release)==null?void 0:s.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}(),me=()=>{const s=[],e=new Promise((t,r)=>{s.push(t,r)});return s.unshift(e),s};var at=Object.defineProperty,lt=Object.getOwnPropertyDescriptor,w=(s,e,t,r)=>{for(var n=r>1?void 0:r?lt(e,t):e,o=s.length-1,a;o>=0;o--)(a=s[o])&&(n=(r?a(e,t,n):a(n))||n);return r&&n&&at(e,t,n),n};const y="string",F="number",l=Symbol("__private__dont__use");var k,x,T,R,v,I,B,W,He,z,ke,G,Te,V,Ce,J,Fe,Y,Le,K,Ae,Z,$e,Q,Ue,X,Oe,ee,Ie,te,Ne;class g{constructor(e,t){c(this,W);c(this,z);c(this,G);c(this,V);c(this,J);c(this,Y);c(this,K);c(this,Z);c(this,Q);c(this,X);c(this,ee);c(this,te);c(this,k,void 0);c(this,x,void 0);c(this,T,void 0);c(this,R,void 0);c(this,v,void 0);c(this,I,void 0);c(this,B,void 0);p(this,k,[]),p(this,x,!1),p(this,T,null),p(this,R,{}),p(this,v,new Map),p(this,I,[]),p(this,B,new be({concurrency:1})),e!==void 0&&this.initializeRuntime(e),t&&(this.requestHandler=new we(new ve(this,t)))}addEventListener(e,t){i(this,v).has(e)||i(this,v).set(e,new Set),i(this,v).get(e).add(t)}removeEventListener(e,t){var r;(r=i(this,v).get(e))==null||r.delete(t)}dispatchEvent(e){const t=i(this,v).get(e.type);if(t)for(const r of t)r(e)}async onMessage(e){i(this,I).push(e)}async setSpawnHandler(e){this[l].spawnProcess=e}get absoluteUrl(){return this.requestHandler.requestHandler.absoluteUrl}get documentRoot(){return this.requestHandler.requestHandler.documentRoot}pathToInternalUrl(e){return this.requestHandler.requestHandler.pathToInternalUrl(e)}internalUrlToPath(e){return this.requestHandler.requestHandler.internalUrlToPath(e)}initializeRuntime(e){if(this[l])throw new Error("PHP runtime already initialized.");const t=it(e);if(!t)throw new Error("Invalid PHP runtime id.");this[l]=t,t.onMessage=async r=>{for(const n of i(this,I)){const o=await n(r);if(o)return o}return""},p(this,T,je(t))}setPhpIniPath(e){if(i(this,x))throw new Error("Cannot set PHP ini path after calling run().");this[l].ccall("wasm_set_phpini_path",null,["string"],[e])}setPhpIniEntry(e,t){if(i(this,x))throw new Error("Cannot set PHP ini entries after calling run().");i(this,k).push([e,t])}chdir(e){this[l].FS.chdir(e)}async request(e,t){if(!this.requestHandler)throw new Error("No request handler available.");return this.requestHandler.request(e,t)}async run(e){const t=await i(this,B).acquire();try{i(this,x)||(m(this,W,He).call(this),p(this,x,!0)),m(this,Z,$e).call(this,e.scriptPath||""),m(this,G,Te).call(this,e.relativeUri||""),m(this,J,Fe).call(this,e.method||"GET");const r=Be(e.headers||{}),n=r.host||"example.com:443";if(m(this,V,Ce).call(this,n,e.protocol||"http"),m(this,Y,Le).call(this,r),e.body&&m(this,K,Ae).call(this,e.body),e.fileInfos)for(const o of e.fileInfos)m(this,X,Oe).call(this,o);return e.code&&m(this,ee,Ie).call(this," ?>"+e.code),m(this,Q,Ue).call(this),await m(this,te,Ne).call(this)}finally{t(),this.dispatchEvent({type:"request.end"})}}addServerGlobalEntry(e,t){i(this,R)[e]=t}defineConstant(e,t){let r={};try{r=JSON.parse(this.fileExists("/tmp/consts.json")&&this.readFileAsText("/tmp/consts.json")||"{}")}catch{}this.writeFile("/tmp/consts.json",JSON.stringify({...r,[e]:t}))}mkdir(e){this[l].FS.mkdirTree(e)}mkdirTree(e){this.mkdir(e)}readFileAsText(e){return new TextDecoder().decode(this.readFileAsBuffer(e))}readFileAsBuffer(e){return this[l].FS.readFile(e)}writeFile(e,t){this[l].FS.writeFile(e,t)}unlink(e){this[l].FS.unlink(e)}mv(e,t){this[l].FS.rename(e,t)}rmdir(e,t={recursive:!0}){t!=null&&t.recursive&&this.listFiles(e).forEach(r=>{const n=`${e}/${r}`;this.isDir(n)?this.rmdir(n,t):this.unlink(n)}),this[l].FS.rmdir(e)}listFiles(e,t={prependPath:!1}){if(!this.fileExists(e))return[];try{const r=this[l].FS.readdir(e).filter(n=>n!=="."&&n!=="..");if(t.prependPath){const n=e.replace(/\/$/,"");return r.map(o=>`${n}/${o}`)}return r}catch(r){return console.error(r,{path:e}),[]}}isDir(e){return this.fileExists(e)?this[l].FS.isDir(this[l].FS.lookupPath(e).node.mode):!1}fileExists(e){try{return this[l].FS.lookupPath(e),!0}catch{return!1}}exit(e=0){return this[l]._exit(e)}}k=new WeakMap,x=new WeakMap,T=new WeakMap,R=new WeakMap,v=new WeakMap,I=new WeakMap,B=new WeakMap,W=new WeakSet,He=function(){if(this.setPhpIniEntry("auto_prepend_file","/tmp/consts.php"),this.fileExists("/tmp/consts.php")||this.writeFile("/tmp/consts.php",`<?php
37
+ `),l=i.substring(0,o).trim(),d=i.substring(o+4).trim(),f=l.match(/name="([^"]+)"/);if(f){const h=f[1];e[h]=d}}),e}function ft(r){switch(r.split(".").pop()){case"css":return"text/css";case"js":return"application/javascript";case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"svg":return"image/svg+xml";case"woff":return"font/woff";case"woff2":return"font/woff2";case"ttf":return"font/ttf";case"otf":return"font/otf";case"eot":return"font/eot";case"ico":return"image/x-icon";case"html":return"text/html";case"json":return"application/json";case"xml":return"application/xml";case"txt":case"md":return"text/plain";default:return"application-octet-stream"}}function pt(r){return mt(r)||yt(r)}function mt(r){return r.endsWith(".php")||r.includes(".php/")}function yt(r){return!r.split("/").pop().includes(".")}const D={0:"No error occurred. System call completed successfully.",1:"Argument list too long.",2:"Permission denied.",3:"Address in use.",4:"Address not available.",5:"Address family not supported.",6:"Resource unavailable, or operation would block.",7:"Connection already in progress.",8:"Bad file descriptor.",9:"Bad message.",10:"Device or resource busy.",11:"Operation canceled.",12:"No child processes.",13:"Connection aborted.",14:"Connection refused.",15:"Connection reset.",16:"Resource deadlock would occur.",17:"Destination address required.",18:"Mathematics argument out of domain of function.",19:"Reserved.",20:"File exists.",21:"Bad address.",22:"File too large.",23:"Host is unreachable.",24:"Identifier removed.",25:"Illegal byte sequence.",26:"Operation in progress.",27:"Interrupted function.",28:"Invalid argument.",29:"I/O error.",30:"Socket is connected.",31:"There is a directory under that path.",32:"Too many levels of symbolic links.",33:"File descriptor value too large.",34:"Too many links.",35:"Message too large.",36:"Reserved.",37:"Filename too long.",38:"Network is down.",39:"Connection aborted by network.",40:"Network unreachable.",41:"Too many files open in system.",42:"No buffer space available.",43:"No such device.",44:"There is no such file or directory OR the parent directory does not exist.",45:"Executable file format error.",46:"No locks available.",47:"Reserved.",48:"Not enough space.",49:"No message of the desired type.",50:"Protocol not available.",51:"No space left on device.",52:"Function not supported.",53:"The socket is not connected.",54:"Not a directory or a symbolic link to a directory.",55:"Directory not empty.",56:"State not recoverable.",57:"Not a socket.",58:"Not supported, or operation not supported on socket.",59:"Inappropriate I/O control operation.",60:"No such device or address.",61:"Value too large to be stored in data type.",62:"Previous owner died.",63:"Operation not permitted.",64:"Broken pipe.",65:"Protocol error.",66:"Protocol not supported.",67:"Protocol wrong type for socket.",68:"Result too large.",69:"Read-only file system.",70:"Invalid seek.",71:"No such process.",72:"Reserved.",73:"Connection timed out.",74:"Text file busy.",75:"Cross-device link.",76:"Extension: Capabilities insufficient."};function wt(r){const e=typeof r=="object"?r==null?void 0:r.errno:null;if(e in D)return D[e]}function g(r=""){return function(t,s,n){const i=n.value;n.value=function(...o){try{return i.apply(this,o)}catch(l){const d=typeof l=="object"?l==null?void 0:l.errno:null;if(d in D){const f=D[d],h=typeof o[0]=="string"?o[0]:null,E=h!==null?r.replaceAll("{path}",h):r;throw new Error(`${E}: ${f}`,{cause:l})}throw l}}}}const gt=Symbol("RuntimeId"),q=new Map;async function Pt(r,e={},t=[]){const[s,n,i]=ye(),[o,l]=ye(),d=r.init(St,{onAbort(h){i(h),l(),console.error(h)},ENV:{},locateFile:h=>h,...e,noInitialRun:!0,onRuntimeInitialized(){e.onRuntimeInitialized&&e.onRuntimeInitialized(),n()},monitorRunDependencies(h){h===0&&(delete d.monitorRunDependencies,l())}});await Promise.all(t.map(({default:h})=>h(d))),t.length||l(),await o,await s;const f=q.size;return d.originalExit=d._exit,d._exit=function(h){return q.delete(f),d.originalExit(h)},d[gt]=f,q.set(f,d),f}function bt(r){return q.get(r)}const St=function(){var r;return typeof process<"u"&&((r=process.release)==null?void 0:r.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}(),ye=()=>{const r=[],e=new Promise((t,s)=>{r.push(t,s)});return r.unshift(e),r};var Et=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,S=(r,e,t,s)=>{for(var n=s>1?void 0:s?Rt(e,t):e,i=r.length-1,o;i>=0;i--)(o=r[i])&&(n=(s?o(e,t,n):o(n))||n);return s&&n&&Et(e,t,n),n};const y="string",C="number",c=Symbol("__private__dont__use");var H,v,k,_,R,I,N,z,Te,G,Ce,V,Ae,J,Ue,Y,Be,K,Le,Z,$e,Q,Ie,X,Oe,ee,Ne,te,qe,re,De;class w{constructor(e,t){u(this,z);u(this,G);u(this,V);u(this,J);u(this,Y);u(this,K);u(this,Z);u(this,Q);u(this,X);u(this,ee);u(this,te);u(this,re);u(this,H,void 0);u(this,v,void 0);u(this,k,void 0);u(this,_,void 0);u(this,R,void 0);u(this,I,void 0);u(this,N,void 0);p(this,H,[]),p(this,v,!1),p(this,k,null),p(this,_,{}),p(this,R,new Map),p(this,I,[]),p(this,N,new be({concurrency:1})),e!==void 0&&this.initializeRuntime(e),t&&(this.requestHandler=new Re(new xe(this,t)))}addEventListener(e,t){a(this,R).has(e)||a(this,R).set(e,new Set),a(this,R).get(e).add(t)}removeEventListener(e,t){var s;(s=a(this,R).get(e))==null||s.delete(t)}dispatchEvent(e){const t=a(this,R).get(e.type);if(t)for(const s of t)s(e)}async onMessage(e){a(this,I).push(e)}async setSpawnHandler(e){this[c].spawnProcess=e}get absoluteUrl(){return this.requestHandler.requestHandler.absoluteUrl}get documentRoot(){return this.requestHandler.requestHandler.documentRoot}pathToInternalUrl(e){return this.requestHandler.requestHandler.pathToInternalUrl(e)}internalUrlToPath(e){return this.requestHandler.requestHandler.internalUrlToPath(e)}initializeRuntime(e){if(this[c])throw new Error("PHP runtime already initialized.");const t=bt(e);if(!t)throw new Error("Invalid PHP runtime id.");this[c]=t,t.onMessage=async s=>{for(const n of a(this,I)){const i=await n(s);if(i)return i}return""},p(this,k,Ge(t))}setPhpIniPath(e){if(a(this,v))throw new Error("Cannot set PHP ini path after calling run().");this[c].ccall("wasm_set_phpini_path",null,["string"],[e])}setPhpIniEntry(e,t){if(a(this,v))throw new Error("Cannot set PHP ini entries after calling run().");a(this,H).push([e,t])}chdir(e){this[c].FS.chdir(e)}async request(e,t){if(!this.requestHandler)throw new Error("No request handler available.");return this.requestHandler.request(e,t)}async run(e){const t=await a(this,N).acquire();try{a(this,v)||(m(this,z,Te).call(this),p(this,v,!0)),m(this,Q,Ie).call(this,e.scriptPath||""),m(this,V,Ae).call(this,e.relativeUri||""),m(this,Y,Be).call(this,e.method||"GET");const s=Me(e.headers||{}),n=s.host||"example.com:443";if(m(this,J,Ue).call(this,n,e.protocol||"http"),m(this,K,Le).call(this,s),e.body&&m(this,Z,$e).call(this,e.body),e.fileInfos)for(const i of e.fileInfos)m(this,ee,Ne).call(this,i);return e.code&&m(this,te,qe).call(this," ?>"+e.code),m(this,X,Oe).call(this),await m(this,re,De).call(this)}finally{t(),this.dispatchEvent({type:"request.end"})}}addServerGlobalEntry(e,t){a(this,_)[e]=t}defineConstant(e,t){let s={};try{s=JSON.parse(this.fileExists("/tmp/consts.json")&&this.readFileAsText("/tmp/consts.json")||"{}")}catch{}this.writeFile("/tmp/consts.json",JSON.stringify({...s,[e]:t}))}mkdir(e){this[c].FS.mkdirTree(e)}mkdirTree(e){this.mkdir(e)}readFileAsText(e){return new TextDecoder().decode(this.readFileAsBuffer(e))}readFileAsBuffer(e){return this[c].FS.readFile(e)}writeFile(e,t){this[c].FS.writeFile(e,t)}unlink(e){this[c].FS.unlink(e)}mv(e,t){try{this[c].FS.rename(e,t)}catch(s){const n=wt(s);throw n?new Error(`Could not move ${e} to ${t}: ${n}`,{cause:s}):s}}rmdir(e,t={recursive:!0}){t!=null&&t.recursive&&this.listFiles(e).forEach(s=>{const n=`${e}/${s}`;this.isDir(n)?this.rmdir(n,t):this.unlink(n)}),this[c].FS.rmdir(e)}listFiles(e,t={prependPath:!1}){if(!this.fileExists(e))return[];try{const s=this[c].FS.readdir(e).filter(n=>n!=="."&&n!=="..");if(t.prependPath){const n=e.replace(/\/$/,"");return s.map(i=>`${n}/${i}`)}return s}catch(s){return console.error(s,{path:e}),[]}}isDir(e){return this.fileExists(e)?this[c].FS.isDir(this[c].FS.lookupPath(e).node.mode):!1}fileExists(e){try{return this[c].FS.lookupPath(e),!0}catch{return!1}}exit(e=0){return this[c]._exit(e)}}H=new WeakMap,v=new WeakMap,k=new WeakMap,_=new WeakMap,R=new WeakMap,I=new WeakMap,N=new WeakMap,z=new WeakSet,Te=function(){if(this.setPhpIniEntry("auto_prepend_file","/tmp/consts.php"),this.fileExists("/tmp/consts.php")||this.writeFile("/tmp/consts.php",`<?php
38
38
  if(file_exists('/tmp/consts.json')) {
39
39
  $consts = json_decode(file_get_contents('/tmp/consts.json'), true);
40
40
  foreach ($consts as $const => $value) {
@@ -42,7 +42,7 @@ ${Ge} WASM ERROR${ue}${he}`);for(const e of s.split(`
42
42
  define($const, $value);
43
43
  }
44
44
  }
45
- }`),i(this,k).length>0){const e=i(this,k).map(([t,r])=>`${t}=${r}`).join(`
45
+ }`),a(this,H).length>0){const e=a(this,H).map(([t,s])=>`${t}=${s}`).join(`
46
46
  `)+`
47
47
 
48
- `;this[l].ccall("wasm_set_phpini_entries",null,[y],[e])}this[l].ccall("php_wasm_init",null,[],[])},z=new WeakSet,ke=function(){const e="/tmp/headers.json";if(!this.fileExists(e))throw new Error("SAPI Error: Could not find response headers file.");const t=JSON.parse(this.readFileAsText(e)),r={};for(const n of t.headers){if(!n.includes(": "))continue;const o=n.indexOf(": "),a=n.substring(0,o).toLowerCase(),h=n.substring(o+2);a in r||(r[a]=[]),r[a].push(h)}return{headers:r,httpStatusCode:t.status}},G=new WeakSet,Te=function(e){if(this[l].ccall("wasm_set_request_uri",null,[y],[e]),e.includes("?")){const t=e.substring(e.indexOf("?")+1);this[l].ccall("wasm_set_query_string",null,[y],[t])}},V=new WeakSet,Ce=function(e,t){this[l].ccall("wasm_set_request_host",null,[y],[e]);let r;try{r=parseInt(new URL(e).port,10)}catch{}(!r||isNaN(r)||r===80)&&(r=t==="https"?443:80),this[l].ccall("wasm_set_request_port",null,[F],[r]),(t==="https"||!t&&r===443)&&this.addServerGlobalEntry("HTTPS","on")},J=new WeakSet,Fe=function(e){this[l].ccall("wasm_set_request_method",null,[y],[e])},Y=new WeakSet,Le=function(e){e.cookie&&this[l].ccall("wasm_set_cookies",null,[y],[e.cookie]),e["content-type"]&&this[l].ccall("wasm_set_content_type",null,[y],[e["content-type"]]),e["content-length"]&&this[l].ccall("wasm_set_content_length",null,[F],[parseInt(e["content-length"],10)]);for(const t in e){let r="HTTP_";["content-type","content-length"].includes(t.toLowerCase())&&(r=""),this.addServerGlobalEntry(`${r}${t.toUpperCase().replace(/-/g,"_")}`,e[t])}},K=new WeakSet,Ae=function(e){this[l].ccall("wasm_set_request_body",null,[y],[e]),this[l].ccall("wasm_set_content_length",null,[F],[new TextEncoder().encode(e).length])},Z=new WeakSet,$e=function(e){this[l].ccall("wasm_set_path_translated",null,[y],[e])},Q=new WeakSet,Ue=function(){for(const e in i(this,R))this[l].ccall("wasm_add_SERVER_entry",null,[y,y],[e,i(this,R)[e]])},X=new WeakSet,Oe=function(e){const{key:t,name:r,type:n,data:o}=e,a=`/tmp/${Math.random().toFixed(20)}`;this.writeFile(a,o);const h=0;this[l].ccall("wasm_add_uploaded_file",null,[y,y,y,y,F,F],[t,r,n,a,h,o.byteLength])},ee=new WeakSet,Ie=function(e){this[l].ccall("wasm_set_php_code",null,[y],[e])},te=new WeakSet,Ne=async function(){var o;let e,t;try{e=await new Promise((a,h)=>{var f;t=u=>{const E=new Error("Rethrown");E.cause=u.error,E.betterMessage=u.message,h(E)},(f=i(this,T))==null||f.addEventListener("error",t);const d=this[l].ccall("wasm_sapi_handle_request",F,[],[],{async:!0});return d instanceof Promise?d.then(a,h):a(d)})}catch(a){for(const u in this)typeof this[u]=="function"&&(this[u]=()=>{throw new Error("PHP runtime has crashed – see the earlier error for details.")});this.functionsMaybeMissingFromAsyncify=De();const h=a,d="betterMessage"in h?h.betterMessage:h.message,f=new Error(d);throw f.cause=h,f}finally{(o=i(this,T))==null||o.removeEventListener("error",t),p(this,R,{})}const{headers:r,httpStatusCode:n}=m(this,z,ke).call(this);return new C(n,r,this.readFileAsBuffer("/tmp/stdout"),this.readFileAsText("/tmp/stderr"),e)};w([P('Could not create directory "{path}"')],g.prototype,"mkdir",1);w([P('Could not create directory "{path}"')],g.prototype,"mkdirTree",1);w([P('Could not read "{path}"')],g.prototype,"readFileAsText",1);w([P('Could not read "{path}"')],g.prototype,"readFileAsBuffer",1);w([P('Could not write to "{path}"')],g.prototype,"writeFile",1);w([P('Could not unlink "{path}"')],g.prototype,"unlink",1);w([P('Could not move "{path}"')],g.prototype,"mv",1);w([P('Could not remove directory "{path}"')],g.prototype,"rmdir",1);w([P('Could not list files in "{path}"')],g.prototype,"listFiles",1);w([P('Could not stat "{path}"')],g.prototype,"isDir",1);w([P('Could not stat "{path}"')],g.prototype,"fileExists",1);function Be(s){const e={};for(const t in s)e[t.toLowerCase()]=s[t];return e}function Me(s){return!(s instanceof g)}function ct(s){return!Me(s)}exports.BasePHP=g;exports.DEFAULT_BASE_URL=_e;exports.LatestSupportedPHPVersion=Ye;exports.PHPBrowser=we;exports.PHPRequestHandler=ve;exports.PHPResponse=C;exports.SupportedPHPExtensionBundles=Ze;exports.SupportedPHPExtensionsList=Pe;exports.SupportedPHPVersions=ae;exports.SupportedPHPVersionsList=Ke;exports.UnhandledRejectionsTarget=ge;exports.__private__dont__use=l;exports.ensurePathPrefix=Ee;exports.isExitCodeZero=ye;exports.isLocalPHP=Me;exports.isRemotePHP=ct;exports.loadPHPRuntime=nt;exports.removePathPrefix=ie;exports.rethrowFileSystemError=P;exports.toRelativeUrl=ne;
48
+ `;this[c].ccall("wasm_set_phpini_entries",null,[y],[e])}this[c].ccall("php_wasm_init",null,[],[])},G=new WeakSet,Ce=function(){const e="/tmp/headers.json";if(!this.fileExists(e))throw new Error("SAPI Error: Could not find response headers file.");const t=JSON.parse(this.readFileAsText(e)),s={};for(const n of t.headers){if(!n.includes(": "))continue;const i=n.indexOf(": "),o=n.substring(0,i).toLowerCase(),l=n.substring(i+2);o in s||(s[o]=[]),s[o].push(l)}return{headers:s,httpStatusCode:t.status}},V=new WeakSet,Ae=function(e){if(this[c].ccall("wasm_set_request_uri",null,[y],[e]),e.includes("?")){const t=e.substring(e.indexOf("?")+1);this[c].ccall("wasm_set_query_string",null,[y],[t])}},J=new WeakSet,Ue=function(e,t){this[c].ccall("wasm_set_request_host",null,[y],[e]);let s;try{s=parseInt(new URL(e).port,10)}catch{}(!s||isNaN(s)||s===80)&&(s=t==="https"?443:80),this[c].ccall("wasm_set_request_port",null,[C],[s]),(t==="https"||!t&&s===443)&&this.addServerGlobalEntry("HTTPS","on")},Y=new WeakSet,Be=function(e){this[c].ccall("wasm_set_request_method",null,[y],[e])},K=new WeakSet,Le=function(e){e.cookie&&this[c].ccall("wasm_set_cookies",null,[y],[e.cookie]),e["content-type"]&&this[c].ccall("wasm_set_content_type",null,[y],[e["content-type"]]),e["content-length"]&&this[c].ccall("wasm_set_content_length",null,[C],[parseInt(e["content-length"],10)]);for(const t in e){let s="HTTP_";["content-type","content-length"].includes(t.toLowerCase())&&(s=""),this.addServerGlobalEntry(`${s}${t.toUpperCase().replace(/-/g,"_")}`,e[t])}},Z=new WeakSet,$e=function(e){this[c].ccall("wasm_set_request_body",null,[y],[e]),this[c].ccall("wasm_set_content_length",null,[C],[new TextEncoder().encode(e).length])},Q=new WeakSet,Ie=function(e){this[c].ccall("wasm_set_path_translated",null,[y],[e])},X=new WeakSet,Oe=function(){for(const e in a(this,_))this[c].ccall("wasm_add_SERVER_entry",null,[y,y],[e,a(this,_)[e]])},ee=new WeakSet,Ne=function(e){const{key:t,name:s,type:n,data:i}=e,o=`/tmp/${Math.random().toFixed(20)}`;this.writeFile(o,i);const l=0;this[c].ccall("wasm_add_uploaded_file",null,[y,y,y,y,C,C],[t,s,n,o,l,i.byteLength])},te=new WeakSet,qe=function(e){this[c].ccall("wasm_set_php_code",null,[y],[e])},re=new WeakSet,De=async function(){var i;let e,t;try{e=await new Promise((o,l)=>{var f;t=h=>{const E=new Error("Rethrown");E.cause=h.error,E.betterMessage=h.message,l(E)},(f=a(this,k))==null||f.addEventListener("error",t);const d=this[c].ccall("wasm_sapi_handle_request",C,[],[],{async:!0});return d instanceof Promise?d.then(o,l):o(d)})}catch(o){for(const h in this)typeof this[h]=="function"&&(this[h]=()=>{throw new Error("PHP runtime has crashed – see the earlier error for details.")});this.functionsMaybeMissingFromAsyncify=Ve();const l=o,d="betterMessage"in l?l.betterMessage:l.message,f=new Error(d);throw f.cause=l,f}finally{(i=a(this,k))==null||i.removeEventListener("error",t),p(this,_,{})}const{headers:s,httpStatusCode:n}=m(this,G,Ce).call(this);return new T(n,s,this.readFileAsBuffer("/tmp/stdout"),this.readFileAsText("/tmp/stderr"),e)};S([g('Could not create directory "{path}"')],w.prototype,"mkdir",1);S([g('Could not create directory "{path}"')],w.prototype,"mkdirTree",1);S([g('Could not read "{path}"')],w.prototype,"readFileAsText",1);S([g('Could not read "{path}"')],w.prototype,"readFileAsBuffer",1);S([g('Could not write to "{path}"')],w.prototype,"writeFile",1);S([g('Could not unlink "{path}"')],w.prototype,"unlink",1);S([g('Could not remove directory "{path}"')],w.prototype,"rmdir",1);S([g('Could not list files in "{path}"')],w.prototype,"listFiles",1);S([g('Could not stat "{path}"')],w.prototype,"isDir",1);S([g('Could not stat "{path}"')],w.prototype,"fileExists",1);function Me(r){const e={};for(const t in r)e[t.toLowerCase()]=r[t];return e}function je(r){return!(r instanceof w)}function vt(r){return!je(r)}exports.BasePHP=w;exports.DEFAULT_BASE_URL=ve;exports.LatestSupportedPHPVersion=ct;exports.PHPBrowser=Re;exports.PHPRequestHandler=xe;exports.PHPResponse=T;exports.SupportedPHPExtensionBundles=ht;exports.SupportedPHPExtensionsList=Ee;exports.SupportedPHPVersions=ce;exports.SupportedPHPVersionsList=ut;exports.UnhandledRejectionsTarget=Pe;exports.__private__dont__use=c;exports.ensurePathPrefix=_e;exports.isExitCodeZero=ge;exports.isLocalPHP=je;exports.isRemotePHP=vt;exports.iterateFiles=at;exports.loadPHPRuntime=Pt;exports.removePathPrefix=oe;exports.rethrowFileSystemError=g;exports.toRelativeUrl=ie;exports.writeFilesStreamToPhp=lt;