@php-wasm/universal 0.6.6 → 0.6.7
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 +5 -5
- package/index.js +160 -150
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var Q=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var l=(e,t,r)=>(Q(e,t,"read from private field"),r?r.call(e):t.get(e)),u=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},h=(e,t,r,s)=>(Q(e,t,"write to private field"),s?s.call(e,r):t.set(e,r),r);var p=(e,t,r)=>(Q(e,t,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const currentJsRuntime$1=function(){var e;return typeof process<"u"&&((e=process.release)==null?void 0:e.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}();if(currentJsRuntime$1==="NODE"){let e=function(r){return new Promise(function(s,n){r.onload=r.onerror=function(i){r.onload=r.onerror=null,i.type==="load"?s(r.result):n(new Error("Failed to read the blob/file"))}})},t=function(){const r=new Uint8Array([1,2,3,4]),n=new File([r],"test").stream();try{return n.getReader({mode:"byob"}),!0}catch{return!1}};if(typeof File>"u"){class r extends Blob{constructor(n,i,o){super(n);let a;o!=null&&o.lastModified&&(a=new Date),(!a||isNaN(a.getFullYear()))&&(a=new Date),this.lastModifiedDate=a,this.lastModified=a.getMilliseconds(),this.name=i||""}}global.File=r}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const s=new FileReader;return s.readAsArrayBuffer(this),e(s)}),typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const s=new FileReader;return s.readAsText(this),e(s)}),(typeof Blob.prototype.stream>"u"||!t())&&(Blob.prototype.stream=function(){let r=0;const s=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(n){const i=n.byobRequest.view,a=await s.slice(r,r+i.byteLength).arrayBuffer(),c=new Uint8Array(a);new Uint8Array(i.buffer).set(c);const d=c.byteLength;n.byobRequest.respond(d),r+=d,r>=s.size&&n.close()}})})}if(currentJsRuntime$1==="NODE"&&typeof CustomEvent>"u"){class e extends Event{constructor(r,s={}){super(r,s),this.detail=s.detail}initCustomEvent(){}}globalThis.CustomEvent=e}const kError=Symbol("error"),kMessage=Symbol("message");class ErrorEvent2 extends Event{constructor(t,r={}){super(t),this[kError]=r.error===void 0?null:r.error,this[kMessage]=r.message===void 0?"":r.message}get error(){return this[kError]}get message(){return this[kMessage]}}Object.defineProperty(ErrorEvent2.prototype,"error",{enumerable:!0});Object.defineProperty(ErrorEvent2.prototype,"message",{enumerable:!0});const ErrorEvent=typeof globalThis.ErrorEvent=="function"?globalThis.ErrorEvent:ErrorEvent2;function isExitCodeZero(e){return e instanceof Error?"exitCode"in e&&(e==null?void 0:e.exitCode)===0||(e==null?void 0:e.name)==="ExitStatus"&&"status"in e&&e.status===0:!1}class UnhandledRejectionsTarget extends EventTarget{constructor(){super(...arguments),this.listenersCount=0}addEventListener(t,r){++this.listenersCount,super.addEventListener(t,r)}removeEventListener(t,r){--this.listenersCount,super.removeEventListener(t,r)}hasListeners(){return this.listenersCount>0}}function improveWASMErrorReporting(e){e.asm={...e.asm};const t=new UnhandledRejectionsTarget;for(const r in e.asm)if(typeof e.asm[r]=="function"){const s=e.asm[r];e.asm[r]=function(...n){var i;try{return s(...n)}catch(o){if(!(o instanceof Error))throw o;const a=clarifyErrorMessage(o,(i=e.lastAsyncifyStackSource)==null?void 0:i.stack);if(e.lastAsyncifyStackSource&&(o.cause=e.lastAsyncifyStackSource),t.hasListeners()){t.dispatchEvent(new ErrorEvent("error",{error:o,message:a}));return}throw isExitCodeZero(o)||showCriticalErrorBox(a),o}}}return t}let functionsMaybeMissingFromAsyncify=[];function getFunctionsMaybeMissingFromAsyncify(){return functionsMaybeMissingFromAsyncify}function clarifyErrorMessage(e,t){if(e.message==="unreachable"){let r=UNREACHABLE_ERROR;t||(r+=`
|
|
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 }).
|
|
@@ -32,13 +32,13 @@ CLI option:
|
|
|
32
32
|
${eol}
|
|
33
33
|
${bold} WASM ERROR${reset}${redBg}`);for(const t of e.split(`
|
|
34
34
|
`))console.log(`${eol} ${t} `);console.log(`${reset}`)}}function extractPHPFunctionsFromStack(e){try{const t=e.split(`
|
|
35
|
-
`).slice(1).map(r=>{const s=r.trim().substring(3).split(" ");return{fn:s.length>=2?s[0]:"<unknown>",isWasm:r.includes("wasm://")}}).filter(({fn:r,isWasm:s})=>s&&!r.startsWith("dynCall_")&&!r.startsWith("invoke_")).map(({fn:r})=>r);return Array.from(new Set(t))}catch{return[]}}class Semaphore{constructor({concurrency:t}){this._running=0,this.concurrency=t,this.queue=[]}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency)await new Promise(t=>this.queue.push(t));else{this._running++;let t=!1;return()=>{t||(t=!0,this._running--,this.queue.length>0&&this.queue.shift()())}}}async run(t){const r=await this.acquire();try{return await t()}finally{r()}}}function joinPaths(...e){let t=e.join("/");const r=t[0]==="/",s=t.substring(t.length-1)==="/";return t=normalizePath(t),!t&&!r&&(t="."),t&&s&&(t+="/"),t}function dirname(e){if(e==="/")return"/";e=normalizePath(e);const t=e.lastIndexOf("/");return t===-1?"":t===0?"/":e.substr(0,t)}function normalizePath(e){const t=e[0]==="/";return e=normalizePathsArray(e.split("/").filter(r=>!!r),!t).join("/"),(t?"/":"")+e.replace(/\/$/,"")}function normalizePathsArray(e,t){let r=0;for(let s=e.length-1;s>=0;s--){const n=e[s];n==="."?e.splice(s,1):n===".."?(e.splice(s,1),r++):r&&(e.splice(s,1),r--)}if(t)for(;r;r--)e.unshift("..");return e}function splitShellCommand(e){let s=0,n="";const i=[];let o="";for(let
|
|
35
|
+
`).slice(1).map(r=>{const s=r.trim().substring(3).split(" ");return{fn:s.length>=2?s[0]:"<unknown>",isWasm:r.includes("wasm://")}}).filter(({fn:r,isWasm:s})=>s&&!r.startsWith("dynCall_")&&!r.startsWith("invoke_")).map(({fn:r})=>r);return Array.from(new Set(t))}catch{return[]}}class Semaphore{constructor({concurrency:t}){this._running=0,this.concurrency=t,this.queue=[]}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency)await new Promise(t=>this.queue.push(t));else{this._running++;let t=!1;return()=>{t||(t=!0,this._running--,this.queue.length>0&&this.queue.shift()())}}}async run(t){const r=await this.acquire();try{return await t()}finally{r()}}}function joinPaths(...e){let t=e.join("/");const r=t[0]==="/",s=t.substring(t.length-1)==="/";return t=normalizePath(t),!t&&!r&&(t="."),t&&s&&(t+="/"),t}function dirname(e){if(e==="/")return"/";e=normalizePath(e);const t=e.lastIndexOf("/");return t===-1?"":t===0?"/":e.substr(0,t)}function normalizePath(e){const t=e[0]==="/";return e=normalizePathsArray(e.split("/").filter(r=>!!r),!t).join("/"),(t?"/":"")+e.replace(/\/$/,"")}function normalizePathsArray(e,t){let r=0;for(let s=e.length-1;s>=0;s--){const n=e[s];n==="."?e.splice(s,1):n===".."?(e.splice(s,1),r++):r&&(e.splice(s,1),r--)}if(t)for(;r;r--)e.unshift("..");return e}function splitShellCommand(e){let s=0,n="";const i=[];let o="";for(let a=0;a<e.length;a++){const c=e[a];c==="\\"?((e[a+1]==='"'||e[a+1]==="'")&&a++,o+=e[a]):s===0?c==='"'||c==="'"?(s=1,n=c):c.match(/\s/)?(o.trim().length&&i.push(o.trim()),o=c):i.length&&!o?o=i.pop()+c:o+=c:s===1&&(c===n?(s=0,n=""):o+=c)}return o&&i.push(o.trim()),i}function createSpawnHandler(e){return function(t,r=[],s={}){const n=new ChildProcess,i=new ProcessApi(n);return setTimeout(async()=>{let o=[];if(r.length)o=[t,...r];else if(typeof t=="string")o=splitShellCommand(t);else if(Array.isArray(t))o=t;else throw new Error("Invalid command ",t);await e(o,i,s),n.emit("spawn",!0)}),n}}class EventEmitter{constructor(){this.listeners={}}emit(t,r){this.listeners[t]&&this.listeners[t].forEach(function(s){s(r)})}on(t,r){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(r)}}class ProcessApi extends EventEmitter{constructor(t){super(),this.childProcess=t,this.exited=!1,this.stdinData=[],t.on("stdin",r=>{this.stdinData?this.stdinData.push(r.slice()):this.emit("stdin",r)})}stdout(t){typeof t=="string"&&(t=new TextEncoder().encode(t)),this.childProcess.stdout.emit("data",t)}stdoutEnd(){this.childProcess.stdout.emit("end",{})}stderr(t){typeof t=="string"&&(t=new TextEncoder().encode(t)),this.childProcess.stderr.emit("data",t)}stderrEnd(){this.childProcess.stderr.emit("end",{})}exit(t){this.exited||(this.exited=!0,this.childProcess.emit("exit",t))}flushStdin(){if(this.stdinData)for(let t=0;t<this.stdinData.length;t++)this.emit("stdin",this.stdinData[t]);this.stdinData=null}}let lastPid=9743;class ChildProcess extends EventEmitter{constructor(t=lastPid++){super(),this.pid=t,this.stdout=new EventEmitter,this.stderr=new EventEmitter;const r=this;this.stdin={write:s=>{r.emit("stdin",s)}}}}function concatUint8Array(...e){const t=new Uint8Array(e.reduce((s,n)=>s+n.length,0));let r=0;for(const s of e)t.set(s,r),r+=s.length;return t}function concatBytes(e){if(e===void 0){let t=new Uint8Array;return new TransformStream({transform(r){t=concatUint8Array(t,r)},flush(r){r.enqueue(t)}})}else{const t=new ArrayBuffer(e||0);let r=0;return new TransformStream({transform(s){new Uint8Array(t).set(s,r),r+=s.byteLength},flush(s){s.enqueue(new Uint8Array(t))}})}}function limitBytes(e,t){if(t===0)return new ReadableStream({start(n){n.close()}});const r=e.getReader({mode:"byob"});let s=0;return new ReadableStream({async pull(n){const{value:i,done:o}=await r.read(new Uint8Array(t-s));if(o){r.releaseLock(),n.close();return}s+=i.length,n.enqueue(i),s>=t&&(r.releaseLock(),n.close())},cancel(){r.cancel()}})}async function collectBytes(e,t){return t!==void 0&&(e=limitBytes(e,t)),await e.pipeThrough(concatBytes(t)).getReader().read().then(({value:r})=>r)}class StreamedFile extends File{constructor(t,r,s){super([],r,{type:s}),this.readableStream=t}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 collectBytes(this.stream())}}ReadableStream.prototype[Symbol.asyncIterator]||(ReadableStream.prototype[Symbol.asyncIterator]=async function*(){const e=this.getReader();try{for(;;){const{done:t,value:r}=await e.read();if(t)return;yield r}}finally{e.releaseLock()}},ReadableStream.prototype.iterate=ReadableStream.prototype[Symbol.asyncIterator]);function streamReadFileFromPHP(e,t){return new ReadableStream({async pull(r){const s=await e.readFileAsBuffer(t);r.enqueue(s),r.close()}})}async function*iteratePhpFiles(e,t,{relativePaths:r=!0,pathPrefix:s,exceptPaths:n=[]}={}){t=normalizePath(t);const i=[t];for(;i.length;){const o=i.pop();if(!o)return;const a=await e.listFiles(o);for(const c of a){const d=`${o}/${c}`;if(n.includes(d.substring(t.length+1)))continue;await e.isDir(d)?i.push(d):yield new StreamedFile(streamReadFileFromPHP(e,d),r?joinPaths(s||"",d.substring(t.length+1)):d)}}}function writeFilesStreamToPhp(e,t){return new WritableStream({async write(r){const s=joinPaths(t,r.name);r.type==="directory"?await e.mkdir(s):(await e.mkdir(dirname(s)),await e.writeFile(s,new Uint8Array(await r.arrayBuffer())))}})}class PHPResponse{constructor(t,r,s,n="",i=0){this.httpStatusCode=t,this.headers=r,this.bytes=s,this.exitCode=i,this.errors=n}static fromRawData(t){return new PHPResponse(t.httpStatusCode,t.headers,t.bytes,t.errors,t.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 SupportedPHPVersions=["8.3","8.2","8.1","8.0","7.4","7.3","7.2","7.1","7.0"],LatestSupportedPHPVersion=SupportedPHPVersions[0],SupportedPHPVersionsList=SupportedPHPVersions,SupportedPHPExtensionsList=["iconv","mbstring","xml-bundle","gd"],SupportedPHPExtensionBundles={"kitchen-sink":SupportedPHPExtensionsList};var E,b;class PHPBrowser{constructor(t,r={}){u(this,E,void 0);u(this,b,void 0);this.requestHandler=t,h(this,E,{}),h(this,b,{handleRedirects:!1,maxRedirects:4,...r})}async request(t,r=0){const s=await this.requestHandler.request({...t,headers:{...t.headers,cookie:this.serializeCookies()}});if(s.headers["set-cookie"]&&this.setCookies(s.headers["set-cookie"]),l(this,b).handleRedirects&&s.headers.location&&r<l(this,b).maxRedirects){const n=new URL(s.headers.location[0],this.requestHandler.absoluteUrl);return this.request({url:n.toString(),method:"GET",headers:{}},r+1)}return s}pathToInternalUrl(t){return this.requestHandler.pathToInternalUrl(t)}internalUrlToPath(t){return this.requestHandler.internalUrlToPath(t)}get absoluteUrl(){return this.requestHandler.absoluteUrl}get documentRoot(){return this.requestHandler.documentRoot}setCookies(t){for(const r of t)try{if(!r.includes("="))continue;const s=r.indexOf("="),n=r.substring(0,s),i=r.substring(s+1).split(";")[0];l(this,E)[n]=i}catch(s){console.error(s)}}serializeCookies(){const t=[];for(const r in l(this,E))t.push(`${r}=${l(this,E)[r]}`);return t.join("; ")}}E=new WeakMap,b=new WeakMap;const DEFAULT_BASE_URL="http://example.com";function toRelativeUrl(e){return e.toString().substring(e.origin.length)}function removePathPrefix(e,t){return!t||!e.startsWith(t)?e:e.substring(t.length)}function ensurePathPrefix(e,t){return!t||e.startsWith(t)?e:t+e}async function encodeAsMultipart(e){const t=`----${Math.random().toString(36).slice(2)}`,r=`multipart/form-data; boundary=${t}`,s=new TextEncoder,n=[];for(const[c,d]of Object.entries(e))n.push(`--${t}\r
|
|
36
36
|
`),n.push(`Content-Disposition: form-data; name="${c}"`),d instanceof File&&n.push(`; filename="${d.name}"`),n.push(`\r
|
|
37
37
|
`),d instanceof File&&(n.push("Content-Type: application/octet-stream"),n.push(`\r
|
|
38
38
|
`)),n.push(`\r
|
|
39
39
|
`),d instanceof File?n.push(await fileToUint8Array(d)):n.push(d),n.push(`\r
|
|
40
40
|
`);n.push(`--${t}--\r
|
|
41
|
-
`);const i=n.reduce((c,d)=>c+d.length,0),o=new Uint8Array(i);let l=0;for(const c of n)o.set(typeof c=="string"?s.encode(c):c,l),l+=c.length;return{bytes:o,contentType:r}}function fileToUint8Array(e){return new Promise(t=>{const r=new FileReader;r.onload=()=>{t(new Uint8Array(r.result))},r.readAsArrayBuffer(e)})}var m,x,U,v,H,_,F,R,B,Y,I,Z,L,K;class PHPRequestHandler{constructor(t,r={}){u(this,B);u(this,I);u(this,L);u(this,m,void 0);u(this,x,void 0);u(this,U,void 0);u(this,v,void 0);u(this,H,void 0);u(this,_,void 0);u(this,F,void 0);u(this,R,void 0);h(this,R,new Semaphore({concurrency:1}));const{documentRoot:s="/www/",absoluteUrl:n=typeof location=="object"?location==null?void 0:location.href:""}=r;this.php=t,h(this,m,s);const i=new URL(n);h(this,U,i.hostname),h(this,v,i.port?Number(i.port):i.protocol==="https:"?443:80),h(this,x,(i.protocol||"").replace(":",""));const o=a(this,v)!==443&&a(this,v)!==80;h(this,H,[a(this,U),o?`:${a(this,v)}`:""].join("")),h(this,_,i.pathname.replace(/\/+$/,"")),h(this,F,[`${a(this,x)}://`,a(this,H),a(this,_)].join(""))}pathToInternalUrl(t){return`${this.absoluteUrl}${t}`}internalUrlToPath(t){const r=new URL(t);return r.pathname.startsWith(a(this,_))&&(r.pathname=r.pathname.slice(a(this,_).length)),toRelativeUrl(r)}get isRequestRunning(){return a(this,R).running>0}get absoluteUrl(){return a(this,F)}get documentRoot(){return a(this,m)}async request(t){const r=t.url.startsWith("http://")||t.url.startsWith("https://"),s=new URL(t.url,r?void 0:DEFAULT_BASE_URL),n=removePathPrefix(s.pathname,a(this,_)),i=`${a(this,m)}${n}`;return seemsLikeAPHPRequestHandlerPath(i)?await p(this,I,Z).call(this,t,s):p(this,B,Y).call(this,i)}}m=new WeakMap,x=new WeakMap,U=new WeakMap,v=new WeakMap,H=new WeakMap,_=new WeakMap,F=new WeakMap,R=new WeakMap,B=new WeakSet,Y=function(t){if(!this.php.fileExists(t))return new PHPResponse(404,{"x-file-type":["static"]},new TextEncoder().encode("404 File not found"));const r=this.php.readFileAsBuffer(t);return new PHPResponse(200,{"content-length":[`${r.byteLength}`],"content-type":[inferMimeType(t)],"accept-ranges":["bytes"],"cache-control":["public, max-age=0"]},r)},I=new WeakSet,Z=async function(t,r){var n,i;if(a(this,R).running>0&&((n=t.headers)==null?void 0:n["x-request-issuer"])==="php")return console.warn("Possible deadlock: Called request() before the previous request() have finished. PHP likely issued an HTTP call to itself. Normally this would lead to infinite waiting as Request 1 holds the lock that the Request 2 is waiting to acquire. That's not useful, so PHPRequestHandler will return error 502 instead."),new PHPResponse(502,{},new TextEncoder().encode("502 Bad Gateway"));const s=await a(this,R).acquire();try{this.php.addServerGlobalEntry("REMOTE_ADDR","127.0.0.1"),this.php.addServerGlobalEntry("DOCUMENT_ROOT",a(this,m)),this.php.addServerGlobalEntry("HTTPS",a(this,F).startsWith("https://")?"on":"");let o="GET";const l={host:a(this,H),...normalizeHeaders(t.headers||{})};let c=t.body;if(typeof c=="object"&&!(c instanceof Uint8Array)){o="POST";const{bytes:f,contentType:k}=await encodeAsMultipart(c);c=f,l["content-type"]=k}let d;try{let f=r.pathname;if((i=t.headers)!=null&&i["x-rewrite-url"])try{f=new URL(t.headers["x-rewrite-url"]).pathname}catch{}d=p(this,L,K).call(this,f)}catch{return new PHPResponse(404,{},new TextEncoder().encode("404 File not found"))}return await this.php.run({relativeUri:ensurePathPrefix(toRelativeUrl(r),a(this,_)),protocol:a(this,x),method:t.method||o,body:c,scriptPath:d,headers:l})}finally{s()}},L=new WeakSet,K=function(t){let r=removePathPrefix(t,a(this,_));r.includes(".php")?r=r.split(".php")[0]+".php":this.php.isDir(`${a(this,m)}${r}`)?(r.endsWith("/")||(r=`${r}/`),r=`${r}index.php`):r="/index.php";const s=`${a(this,m)}${r}`;if(this.php.fileExists(s))return s;throw new Error(`File not found: ${s}`)};function inferMimeType(e){switch(e.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 seemsLikeAPHPRequestHandlerPath(e){return seemsLikeAPHPFile(e)||seemsLikeADirectoryRoot(e)}function seemsLikeAPHPFile(e){return e.endsWith(".php")||e.includes(".php/")}function seemsLikeADirectoryRoot(e){return!e.split("/").pop().includes(".")}const FileErrorCodes={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 getEmscriptenFsError(e){const t=typeof e=="object"?e==null?void 0:e.errno:null;if(t in FileErrorCodes)return FileErrorCodes[t]}function rethrowFileSystemError(e=""){return function(r,s,n){const i=n.value;n.value=function(...o){try{return i.apply(this,o)}catch(l){const c=typeof l=="object"?l==null?void 0:l.errno:null;if(c in FileErrorCodes){const d=FileErrorCodes[c],f=typeof o[0]=="string"?o[0]:null,k=f!==null?e.replaceAll("{path}",f):e;throw new Error(`${k}: ${d}`,{cause:l})}throw l}}}}const RuntimeId=Symbol("RuntimeId"),loadedRuntimes=new Map;let lastRuntimeId=0;async function loadPHPRuntime(e,t={}){const[r,s,n]=makePromise(),i=e.init(currentJsRuntime,{onAbort(l){n(l),console.error(l)},ENV:{},locateFile:l=>l,...t,noInitialRun:!0,onRuntimeInitialized(){t.onRuntimeInitialized&&t.onRuntimeInitialized(),s()}});await r;const o=++lastRuntimeId;return i.id=o,i.originalExit=i._exit,i._exit=function(l){return loadedRuntimes.delete(o),i.originalExit(l)},i[RuntimeId]=o,loadedRuntimes.set(o,i),o}function getLoadedRuntime(e){return loadedRuntimes.get(e)}const currentJsRuntime=function(){var e;return typeof process<"u"&&((e=process.release)==null?void 0:e.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}(),makePromise=()=>{const e=[],t=new Promise((r,s)=>{e.push(r,s)});return e.unshift(t),e};var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=(e,t,r,s)=>{for(var n=s>1?void 0:s?__getOwnPropDesc(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(n=(s?o(t,r,n):o(n))||n);return s&&n&&__defProp(t,r,n),n};const STRING="string",NUMBER="number",__private__dont__use=Symbol("__private__dont__use");var S,T,A,y,w,g,P,C,N,X,M,ee,q,te,O,re,D,se,$,ne,j,ie,z,oe,W,ae,G,le,V,ce,Q,ue;class BasePHP{constructor(e,t){u(this,N);u(this,M);u(this,q);u(this,O);u(this,D);u(this,$);u(this,j);u(this,z);u(this,W);u(this,G);u(this,V);u(this,Q);u(this,S,void 0);u(this,T,void 0);u(this,A,void 0);u(this,y,void 0);u(this,w,void 0);u(this,g,void 0);u(this,P,void 0);u(this,C,void 0);h(this,S,[]),h(this,y,!1),h(this,w,null),h(this,g,{}),h(this,P,new Map),h(this,C,[]),this.semaphore=new Semaphore({concurrency:1}),e!==void 0&&this.initializeRuntime(e),t&&(this.requestHandler=new PHPBrowser(new PHPRequestHandler(this,t)))}addEventListener(e,t){a(this,P).has(e)||a(this,P).set(e,new Set),a(this,P).get(e).add(t)}removeEventListener(e,t){var r;(r=a(this,P).get(e))==null||r.delete(t)}dispatchEvent(e){const t=a(this,P).get(e.type);if(t)for(const r of t)r(e)}async onMessage(e){a(this,C).push(e)}async setSpawnHandler(handler){typeof handler=="string"&&(handler=createSpawnHandler(eval(handler))),this[__private__dont__use].spawnProcess=handler}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[__private__dont__use])throw new Error("PHP runtime already initialized.");const t=getLoadedRuntime(e);if(!t)throw new Error("Invalid PHP runtime id.");this[__private__dont__use]=t,t.onMessage=async r=>{for(const s of a(this,C)){const n=await s(r);if(n)return n}return""},h(this,w,improveWASMErrorReporting(t)),this.dispatchEvent({type:"runtime.initialized"})}async setSapiName(e){if(this[__private__dont__use].ccall("wasm_set_sapi_name",NUMBER,[STRING],[e])!==0)throw new Error("Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?");h(this,A,e)}setPhpIniPath(e){if(a(this,y))throw new Error("Cannot set PHP ini path after calling run().");h(this,T,e),this[__private__dont__use].ccall("wasm_set_phpini_path",null,["string"],[e])}setPhpIniEntry(e,t){if(a(this,y))throw new Error("Cannot set PHP ini entries after calling run().");a(this,S).push([e,t])}chdir(e){this[__private__dont__use].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 this.semaphore.acquire();let r;try{if(a(this,y)||(p(this,N,X).call(this),h(this,y,!0)),e.scriptPath&&!this.fileExists(e.scriptPath))throw new Error(`The script path "${e.scriptPath}" does not exist.`);p(this,z,oe).call(this,e.scriptPath||""),p(this,q,te).call(this,e.relativeUri||""),p(this,D,se).call(this,e.method||"GET");const s=normalizeHeaders(e.headers||{}),n=s.host||"example.com:443";p(this,O,re).call(this,n,e.protocol||"http"),p(this,$,ne).call(this,s),e.body&&(r=p(this,j,ie).call(this,e.body)),typeof e.code=="string"&&p(this,V,ce).call(this," ?>"+e.code),p(this,W,ae).call(this);const i=e.env||{};for(const l in i)p(this,G,le).call(this,l,i[l]);const o=await p(this,Q,ue).call(this);if(e.throwOnError&&o.exitCode!==0){const l={stdout:o.text,stderr:o.errors};console.warn("PHP.run() output was:",l);const c=new Error(`PHP.run() failed with exit code ${o.exitCode} and the following output: `+o.errors);throw c.output=l,console.error(c),c}return o}finally{try{r&&this[__private__dont__use].free(r)}finally{t(),this.dispatchEvent({type:"request.end"})}}}addServerGlobalEntry(e,t){a(this,g)[e]=t}defineConstant(e,t){let r={};try{r=JSON.parse(this.fileExists("/internal/consts.json")&&this.readFileAsText("/internal/consts.json")||"{}")}catch{}this.writeFile("/internal/consts.json",JSON.stringify({...r,[e]:t}))}mkdir(e){this[__private__dont__use].FS.mkdirTree(e)}mkdirTree(e){this.mkdir(e)}readFileAsText(e){return new TextDecoder().decode(this.readFileAsBuffer(e))}readFileAsBuffer(e){return this[__private__dont__use].FS.readFile(e)}writeFile(e,t){this[__private__dont__use].FS.writeFile(e,t)}unlink(e){this[__private__dont__use].FS.unlink(e)}mv(e,t){try{this[__private__dont__use].FS.rename(e,t)}catch(r){const s=getEmscriptenFsError(r);throw s?new Error(`Could not move ${e} to ${t}: ${s}`,{cause:r}):r}}rmdir(e,t={recursive:!0}){t!=null&&t.recursive&&this.listFiles(e).forEach(r=>{const s=`${e}/${r}`;this.isDir(s)?this.rmdir(s,t):this.unlink(s)}),this[__private__dont__use].FS.rmdir(e)}listFiles(e,t={prependPath:!1}){if(!this.fileExists(e))return[];try{const r=this[__private__dont__use].FS.readdir(e).filter(s=>s!=="."&&s!=="..");if(t.prependPath){const s=e.replace(/\/$/,"");return r.map(n=>`${s}/${n}`)}return r}catch(r){return console.error(r,{path:e}),[]}}isDir(e){return this.fileExists(e)?this[__private__dont__use].FS.isDir(this[__private__dont__use].FS.lookupPath(e).node.mode):!1}fileExists(e){try{return this[__private__dont__use].FS.lookupPath(e),!0}catch{return!1}}hotSwapPHPRuntime(e){const t=this[__private__dont__use].FS;try{this.exit()}catch{}if(this.initializeRuntime(e),a(this,T)&&this.setPhpIniPath(a(this,T)),a(this,A)&&this.setSapiName(a(this,A)),this.requestHandler){const r=this.documentRoot;copyFS(t,this[__private__dont__use].FS,r)}}exit(e=0){this.dispatchEvent({type:"runtime.beforedestroy"});try{this[__private__dont__use]._exit(e)}catch{}h(this,y,!1),h(this,w,null),delete this[__private__dont__use].onMessage,delete this[__private__dont__use]}}S=new WeakMap,T=new WeakMap,A=new WeakMap,y=new WeakMap,w=new WeakMap,g=new WeakMap,P=new WeakMap,C=new WeakMap,N=new WeakSet,X=function(){if(this.setPhpIniEntry("auto_prepend_file","/internal/consts.php"),this.fileExists("/internal/consts.php")||this.writeFile("/internal/consts.php",`<?php
|
|
41
|
+
`);const i=n.reduce((c,d)=>c+d.length,0),o=new Uint8Array(i);let a=0;for(const c of n)o.set(typeof c=="string"?s.encode(c):c,a),a+=c.length;return{bytes:o,contentType:r}}function fileToUint8Array(e){return new Promise(t=>{const r=new FileReader;r.onload=()=>{t(new Uint8Array(r.result))},r.readAsArrayBuffer(e)})}var m,x,k,v,H,_,F,R,B,Y,I,Z,L,K;class PHPRequestHandler{constructor(t,r={}){u(this,B);u(this,I);u(this,L);u(this,m,void 0);u(this,x,void 0);u(this,k,void 0);u(this,v,void 0);u(this,H,void 0);u(this,_,void 0);u(this,F,void 0);u(this,R,void 0);h(this,R,new Semaphore({concurrency:1}));const{documentRoot:s="/www/",absoluteUrl:n=typeof location=="object"?location==null?void 0:location.href:""}=r;this.php=t,h(this,m,s);const i=new URL(n);h(this,k,i.hostname),h(this,v,i.port?Number(i.port):i.protocol==="https:"?443:80),h(this,x,(i.protocol||"").replace(":",""));const o=l(this,v)!==443&&l(this,v)!==80;h(this,H,[l(this,k),o?`:${l(this,v)}`:""].join("")),h(this,_,i.pathname.replace(/\/+$/,"")),h(this,F,[`${l(this,x)}://`,l(this,H),l(this,_)].join(""))}pathToInternalUrl(t){return`${this.absoluteUrl}${t}`}internalUrlToPath(t){const r=new URL(t);return r.pathname.startsWith(l(this,_))&&(r.pathname=r.pathname.slice(l(this,_).length)),toRelativeUrl(r)}get isRequestRunning(){return l(this,R).running>0}get absoluteUrl(){return l(this,F)}get documentRoot(){return l(this,m)}async request(t){const r=t.url.startsWith("http://")||t.url.startsWith("https://"),s=new URL(t.url,r?void 0:DEFAULT_BASE_URL),n=removePathPrefix(s.pathname,l(this,_)),i=`${l(this,m)}${n}`;return seemsLikeAPHPRequestHandlerPath(i)?await p(this,I,Z).call(this,t,s):p(this,B,Y).call(this,i)}}m=new WeakMap,x=new WeakMap,k=new WeakMap,v=new WeakMap,H=new WeakMap,_=new WeakMap,F=new WeakMap,R=new WeakMap,B=new WeakSet,Y=function(t){if(!this.php.fileExists(t))return new PHPResponse(404,{"x-file-type":["static"]},new TextEncoder().encode("404 File not found"));const r=this.php.readFileAsBuffer(t);return new PHPResponse(200,{"content-length":[`${r.byteLength}`],"content-type":[inferMimeType(t)],"accept-ranges":["bytes"],"cache-control":["public, max-age=0"]},r)},I=new WeakSet,Z=async function(t,r){var n,i;if(l(this,R).running>0&&((n=t.headers)==null?void 0:n["x-request-issuer"])==="php")return console.warn("Possible deadlock: Called request() before the previous request() have finished. PHP likely issued an HTTP call to itself. Normally this would lead to infinite waiting as Request 1 holds the lock that the Request 2 is waiting to acquire. That's not useful, so PHPRequestHandler will return error 502 instead."),new PHPResponse(502,{},new TextEncoder().encode("502 Bad Gateway"));const s=await l(this,R).acquire();try{this.php.addServerGlobalEntry("REMOTE_ADDR","127.0.0.1"),this.php.addServerGlobalEntry("DOCUMENT_ROOT",l(this,m)),this.php.addServerGlobalEntry("HTTPS",l(this,F).startsWith("https://")?"on":"");let o="GET";const a={host:l(this,H),...normalizeHeaders(t.headers||{})};let c=t.body;if(typeof c=="object"&&!(c instanceof Uint8Array)){o="POST";const{bytes:f,contentType:U}=await encodeAsMultipart(c);c=f,a["content-type"]=U}let d;try{let f=r.pathname;if((i=t.headers)!=null&&i["x-rewrite-url"])try{f=new URL(t.headers["x-rewrite-url"]).pathname}catch{}d=p(this,L,K).call(this,f)}catch{return new PHPResponse(404,{},new TextEncoder().encode("404 File not found"))}return await this.php.run({relativeUri:ensurePathPrefix(toRelativeUrl(r),l(this,_)),protocol:l(this,x),method:t.method||o,body:c,scriptPath:d,headers:a})}finally{s()}},L=new WeakSet,K=function(t){let r=removePathPrefix(t,l(this,_));r.includes(".php")?r=r.split(".php")[0]+".php":this.php.isDir(`${l(this,m)}${r}`)?(r.endsWith("/")||(r=`${r}/`),r=`${r}index.php`):r="/index.php";const s=`${l(this,m)}${r}`;if(this.php.fileExists(s))return s;throw new Error(`File not found: ${s}`)};function inferMimeType(e){switch(e.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 seemsLikeAPHPRequestHandlerPath(e){return seemsLikeAPHPFile(e)||seemsLikeADirectoryRoot(e)}function seemsLikeAPHPFile(e){return e.endsWith(".php")||e.includes(".php/")}function seemsLikeADirectoryRoot(e){return!e.split("/").pop().includes(".")}const FileErrorCodes={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 getEmscriptenFsError(e){const t=typeof e=="object"?e==null?void 0:e.errno:null;if(t in FileErrorCodes)return FileErrorCodes[t]}function rethrowFileSystemError(e=""){return function(r,s,n){const i=n.value;n.value=function(...o){try{return i.apply(this,o)}catch(a){const c=typeof a=="object"?a==null?void 0:a.errno:null;if(c in FileErrorCodes){const d=FileErrorCodes[c],f=typeof o[0]=="string"?o[0]:null,U=f!==null?e.replaceAll("{path}",f):e;throw new Error(`${U}: ${d}`,{cause:a})}throw a}}}}const RuntimeId=Symbol("RuntimeId"),loadedRuntimes=new Map;let lastRuntimeId=0;async function loadPHPRuntime(e,t={}){const[r,s,n]=makePromise(),i=e.init(currentJsRuntime,{onAbort(a){n(a),console.error(a)},ENV:{},locateFile:a=>a,...t,noInitialRun:!0,onRuntimeInitialized(){t.onRuntimeInitialized&&t.onRuntimeInitialized(),s()}});await r;const o=++lastRuntimeId;return i.id=o,i.originalExit=i._exit,i._exit=function(a){return loadedRuntimes.delete(o),i.originalExit(a)},i[RuntimeId]=o,loadedRuntimes.set(o,i),o}function getLoadedRuntime(e){return loadedRuntimes.get(e)}const currentJsRuntime=function(){var e;return typeof process<"u"&&((e=process.release)==null?void 0:e.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}(),makePromise=()=>{const e=[],t=new Promise((r,s)=>{e.push(r,s)});return e.unshift(t),e};var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=(e,t,r,s)=>{for(var n=s>1?void 0:s?__getOwnPropDesc(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(n=(s?o(t,r,n):o(n))||n);return s&&n&&__defProp(t,r,n),n};const STRING="string",NUMBER="number",__private__dont__use=Symbol("__private__dont__use");var S,T,A,y,w,g,P,C,N,X,O,ee,M,te,q,re,D,se,$,ne,j,ie,W,oe,z,ae,G,le,V,ce,J,ue;class BasePHP{constructor(e,t){u(this,N);u(this,O);u(this,M);u(this,q);u(this,D);u(this,$);u(this,j);u(this,W);u(this,z);u(this,G);u(this,V);u(this,J);u(this,S,void 0);u(this,T,void 0);u(this,A,void 0);u(this,y,void 0);u(this,w,void 0);u(this,g,void 0);u(this,P,void 0);u(this,C,void 0);h(this,S,[]),h(this,y,!1),h(this,w,null),h(this,g,{}),h(this,P,new Map),h(this,C,[]),this.semaphore=new Semaphore({concurrency:1}),e!==void 0&&this.initializeRuntime(e),t&&(this.requestHandler=new PHPBrowser(new PHPRequestHandler(this,t)))}addEventListener(e,t){l(this,P).has(e)||l(this,P).set(e,new Set),l(this,P).get(e).add(t)}removeEventListener(e,t){var r;(r=l(this,P).get(e))==null||r.delete(t)}dispatchEvent(e){const t=l(this,P).get(e.type);if(t)for(const r of t)r(e)}async onMessage(e){l(this,C).push(e)}async setSpawnHandler(handler){typeof handler=="string"&&(handler=createSpawnHandler(eval(handler))),this[__private__dont__use].spawnProcess=handler}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[__private__dont__use])throw new Error("PHP runtime already initialized.");const t=getLoadedRuntime(e);if(!t)throw new Error("Invalid PHP runtime id.");this[__private__dont__use]=t,t.onMessage=async r=>{for(const s of l(this,C)){const n=await s(r);if(n)return n}return""},h(this,w,improveWASMErrorReporting(t)),this.dispatchEvent({type:"runtime.initialized"})}async setSapiName(e){if(this[__private__dont__use].ccall("wasm_set_sapi_name",NUMBER,[STRING],[e])!==0)throw new Error("Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?");h(this,A,e)}setPhpIniPath(e){if(l(this,y))throw new Error("Cannot set PHP ini path after calling run().");h(this,T,e),this[__private__dont__use].ccall("wasm_set_phpini_path",null,["string"],[e])}setPhpIniEntry(e,t){if(l(this,y))throw new Error("Cannot set PHP ini entries after calling run().");l(this,S).push([e,t])}chdir(e){this[__private__dont__use].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 this.semaphore.acquire();let r;try{if(l(this,y)||(p(this,N,X).call(this),h(this,y,!0)),e.scriptPath&&!this.fileExists(e.scriptPath))throw new Error(`The script path "${e.scriptPath}" does not exist.`);p(this,W,oe).call(this,e.scriptPath||""),p(this,M,te).call(this,e.relativeUri||""),p(this,D,se).call(this,e.method||"GET");const s=normalizeHeaders(e.headers||{}),n=s.host||"example.com:443";p(this,q,re).call(this,n,e.protocol||"http"),p(this,$,ne).call(this,s),e.body&&(r=p(this,j,ie).call(this,e.body)),typeof e.code=="string"&&p(this,V,ce).call(this," ?>"+e.code),p(this,z,ae).call(this);const i=e.env||{};for(const a in i)p(this,G,le).call(this,a,i[a]);const o=await p(this,J,ue).call(this);if(e.throwOnError&&o.exitCode!==0){const a={stdout:o.text,stderr:o.errors};console.warn("PHP.run() output was:",a);const c=new Error(`PHP.run() failed with exit code ${o.exitCode} and the following output: `+o.errors);throw c.output=a,console.error(c),c}return o}finally{try{r&&this[__private__dont__use].free(r)}finally{t(),this.dispatchEvent({type:"request.end"})}}}addServerGlobalEntry(e,t){l(this,g)[e]=t}defineConstant(e,t){let r={};try{r=JSON.parse(this.fileExists("/internal/consts.json")&&this.readFileAsText("/internal/consts.json")||"{}")}catch{}this.writeFile("/internal/consts.json",JSON.stringify({...r,[e]:t}))}mkdir(e){this[__private__dont__use].FS.mkdirTree(e)}mkdirTree(e){this.mkdir(e)}readFileAsText(e){return new TextDecoder().decode(this.readFileAsBuffer(e))}readFileAsBuffer(e){return this[__private__dont__use].FS.readFile(e)}writeFile(e,t){this[__private__dont__use].FS.writeFile(e,t)}unlink(e){this[__private__dont__use].FS.unlink(e)}mv(e,t){try{this[__private__dont__use].FS.rename(e,t)}catch(r){const s=getEmscriptenFsError(r);throw s?new Error(`Could not move ${e} to ${t}: ${s}`,{cause:r}):r}}rmdir(e,t={recursive:!0}){t!=null&&t.recursive&&this.listFiles(e).forEach(r=>{const s=`${e}/${r}`;this.isDir(s)?this.rmdir(s,t):this.unlink(s)}),this[__private__dont__use].FS.rmdir(e)}listFiles(e,t={prependPath:!1}){if(!this.fileExists(e))return[];try{const r=this[__private__dont__use].FS.readdir(e).filter(s=>s!=="."&&s!=="..");if(t.prependPath){const s=e.replace(/\/$/,"");return r.map(n=>`${s}/${n}`)}return r}catch(r){return console.error(r,{path:e}),[]}}isDir(e){return this.fileExists(e)?this[__private__dont__use].FS.isDir(this[__private__dont__use].FS.lookupPath(e).node.mode):!1}fileExists(e){try{return this[__private__dont__use].FS.lookupPath(e),!0}catch{return!1}}hotSwapPHPRuntime(e){const t=this[__private__dont__use].FS;try{this.exit()}catch{}if(this.initializeRuntime(e),l(this,T)&&this.setPhpIniPath(l(this,T)),l(this,A)&&this.setSapiName(l(this,A)),this.requestHandler){const r=this.documentRoot;copyFS(t,this[__private__dont__use].FS,r)}}exit(e=0){this.dispatchEvent({type:"runtime.beforedestroy"});try{this[__private__dont__use]._exit(e)}catch{}h(this,y,!1),h(this,w,null),delete this[__private__dont__use].onMessage,delete this[__private__dont__use]}}S=new WeakMap,T=new WeakMap,A=new WeakMap,y=new WeakMap,w=new WeakMap,g=new WeakMap,P=new WeakMap,C=new WeakMap,N=new WeakSet,X=function(){if(this.setPhpIniEntry("auto_prepend_file","/internal/consts.php"),this.fileExists("/internal/consts.php")||this.writeFile("/internal/consts.php",`<?php
|
|
42
42
|
if(file_exists('/internal/consts.json')) {
|
|
43
43
|
$consts = json_decode(file_get_contents('/internal/consts.json'), true);
|
|
44
44
|
foreach ($consts as $const => $value) {
|
|
@@ -46,7 +46,7 @@ ${bold} WASM ERROR${reset}${redBg}`);for(const t of e.split(`
|
|
|
46
46
|
define($const, $value);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
}`),
|
|
49
|
+
}`),l(this,S).length>0){const e=l(this,S).map(([t,r])=>`${t}=${r}`).join(`
|
|
50
50
|
`)+`
|
|
51
51
|
|
|
52
|
-
`;this[__private__dont__use].ccall("wasm_set_phpini_entries",null,[STRING],[e])}this[__private__dont__use].ccall("php_wasm_init",null,[],[])},
|
|
52
|
+
`;this[__private__dont__use].ccall("wasm_set_phpini_entries",null,[STRING],[e])}this[__private__dont__use].ccall("php_wasm_init",null,[],[])},O=new WeakSet,ee=function(){const e="/internal/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 s of t.headers){if(!s.includes(": "))continue;const n=s.indexOf(": "),i=s.substring(0,n).toLowerCase(),o=s.substring(n+2);i in r||(r[i]=[]),r[i].push(o)}return{headers:r,httpStatusCode:t.status}},M=new WeakSet,te=function(e){if(this[__private__dont__use].ccall("wasm_set_request_uri",null,[STRING],[e]),e.includes("?")){const t=e.substring(e.indexOf("?")+1);this[__private__dont__use].ccall("wasm_set_query_string",null,[STRING],[t])}},q=new WeakSet,re=function(e,t){this[__private__dont__use].ccall("wasm_set_request_host",null,[STRING],[e]);let r;try{r=parseInt(new URL(e).port,10)}catch{}(!r||isNaN(r)||r===80)&&(r=t==="https"?443:80),this[__private__dont__use].ccall("wasm_set_request_port",null,[NUMBER],[r]),(t==="https"||!t&&r===443)&&this.addServerGlobalEntry("HTTPS","on")},D=new WeakSet,se=function(e){this[__private__dont__use].ccall("wasm_set_request_method",null,[STRING],[e])},$=new WeakSet,ne=function(e){e.cookie&&this[__private__dont__use].ccall("wasm_set_cookies",null,[STRING],[e.cookie]),e["content-type"]&&this[__private__dont__use].ccall("wasm_set_content_type",null,[STRING],[e["content-type"]]),e["content-length"]&&this[__private__dont__use].ccall("wasm_set_content_length",null,[NUMBER],[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])}},j=new WeakSet,ie=function(e){let t,r;typeof e=="string"?(console.warn("Passing a string as the request body is deprecated. Please use a Uint8Array instead. See https://github.com/WordPress/wordpress-playground/issues/997 for more details"),r=this[__private__dont__use].lengthBytesUTF8(e),t=r+1):(r=e.byteLength,t=e.byteLength);const s=this[__private__dont__use].malloc(t);if(!s)throw new Error("Could not allocate memory for the request body.");return typeof e=="string"?this[__private__dont__use].stringToUTF8(e,s,t+1):this[__private__dont__use].HEAPU8.set(e,s),this[__private__dont__use].ccall("wasm_set_request_body",null,[NUMBER],[s]),this[__private__dont__use].ccall("wasm_set_content_length",null,[NUMBER],[r]),s},W=new WeakSet,oe=function(e){this[__private__dont__use].ccall("wasm_set_path_translated",null,[STRING],[e])},z=new WeakSet,ae=function(){for(const e in l(this,g))this[__private__dont__use].ccall("wasm_add_SERVER_entry",null,[STRING,STRING],[e,l(this,g)[e]])},G=new WeakSet,le=function(e,t){this[__private__dont__use].ccall("wasm_add_ENV_entry",null,[STRING,STRING],[e,t])},V=new WeakSet,ce=function(e){this[__private__dont__use].ccall("wasm_set_php_code",null,[STRING],[e])},J=new WeakSet,ue=async function(){var n;let e,t;try{e=await new Promise((i,o)=>{var c;t=d=>{console.error(d),console.error(d.error);const f=new Error("Rethrown");f.cause=d.error,f.betterMessage=d.message,o(f)},(c=l(this,w))==null||c.addEventListener("error",t);const a=this[__private__dont__use].ccall("wasm_sapi_handle_request",NUMBER,[],[],{async:!0});return a instanceof Promise?a.then(i,o):i(a)})}catch(i){for(const d in this)typeof this[d]=="function"&&(this[d]=()=>{throw new Error("PHP runtime has crashed – see the earlier error for details.")});this.functionsMaybeMissingFromAsyncify=getFunctionsMaybeMissingFromAsyncify();const o=i,a="betterMessage"in o?o.betterMessage:o.message,c=new Error(a);throw c.cause=o,console.error(c),c}finally{(n=l(this,w))==null||n.removeEventListener("error",t),h(this,g,{})}const{headers:r,httpStatusCode:s}=p(this,O,ee).call(this);return new PHPResponse(s,r,this.readFileAsBuffer("/internal/stdout"),this.readFileAsText("/internal/stderr"),e)};__decorateClass([rethrowFileSystemError('Could not create directory "{path}"')],BasePHP.prototype,"mkdir",1);__decorateClass([rethrowFileSystemError('Could not create directory "{path}"')],BasePHP.prototype,"mkdirTree",1);__decorateClass([rethrowFileSystemError('Could not read "{path}"')],BasePHP.prototype,"readFileAsText",1);__decorateClass([rethrowFileSystemError('Could not read "{path}"')],BasePHP.prototype,"readFileAsBuffer",1);__decorateClass([rethrowFileSystemError('Could not write to "{path}"')],BasePHP.prototype,"writeFile",1);__decorateClass([rethrowFileSystemError('Could not unlink "{path}"')],BasePHP.prototype,"unlink",1);__decorateClass([rethrowFileSystemError('Could not remove directory "{path}"')],BasePHP.prototype,"rmdir",1);__decorateClass([rethrowFileSystemError('Could not list files in "{path}"')],BasePHP.prototype,"listFiles",1);__decorateClass([rethrowFileSystemError('Could not stat "{path}"')],BasePHP.prototype,"isDir",1);__decorateClass([rethrowFileSystemError('Could not stat "{path}"')],BasePHP.prototype,"fileExists",1);function normalizeHeaders(e){const t={};for(const r in e)t[r.toLowerCase()]=e[r];return t}function copyFS(e,t,r){let s;try{s=e.lookupPath(r)}catch{return}if(!("contents"in s.node))return;if(!e.isDir(s.node.mode)){t.writeFile(r,e.readFile(r));return}t.mkdirTree(r);const n=e.readdir(r).filter(i=>i!=="."&&i!=="..");for(const i of n)copyFS(e,t,joinPaths(r,i))}function isLocalPHP(e){return!(e instanceof BasePHP)}function isRemotePHP(e){return!isLocalPHP(e)}function rotatePHPRuntime({php:e,recreateRuntime:t,maxRequests:r}){let s=0;async function n(){if(++s<r)return;s=0;const i=await e.semaphore.acquire();try{e.hotSwapPHPRuntime(await t())}finally{i()}}return e.addEventListener("request.end",n),function(){e.removeEventListener("request.end",n)}}async function writeFiles(e,t,r,{rmRoot:s=!1}={}){s&&await e.isDir(t)&&await e.rmdir(t,{recursive:!0});for(const[n,i]of Object.entries(r)){const o=joinPaths(t,n);await e.fileExists(dirname(o))||await e.mkdir(dirname(o)),await e.writeFile(o,i)}}exports.BasePHP=BasePHP;exports.DEFAULT_BASE_URL=DEFAULT_BASE_URL;exports.LatestSupportedPHPVersion=LatestSupportedPHPVersion;exports.PHPBrowser=PHPBrowser;exports.PHPRequestHandler=PHPRequestHandler;exports.PHPResponse=PHPResponse;exports.SupportedPHPExtensionBundles=SupportedPHPExtensionBundles;exports.SupportedPHPExtensionsList=SupportedPHPExtensionsList;exports.SupportedPHPVersions=SupportedPHPVersions;exports.SupportedPHPVersionsList=SupportedPHPVersionsList;exports.UnhandledRejectionsTarget=UnhandledRejectionsTarget;exports.__private__dont__use=__private__dont__use;exports.ensurePathPrefix=ensurePathPrefix;exports.isExitCodeZero=isExitCodeZero;exports.isLocalPHP=isLocalPHP;exports.isRemotePHP=isRemotePHP;exports.iterateFiles=iteratePhpFiles;exports.loadPHPRuntime=loadPHPRuntime;exports.removePathPrefix=removePathPrefix;exports.rethrowFileSystemError=rethrowFileSystemError;exports.rotatePHPRuntime=rotatePHPRuntime;exports.toRelativeUrl=toRelativeUrl;exports.writeFiles=writeFiles;exports.writeFilesStreamToPhp=writeFilesStreamToPhp;
|
package/index.js
CHANGED
|
@@ -1,63 +1,73 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Q = (e, t, r) => {
|
|
2
2
|
if (!t.has(e))
|
|
3
3
|
throw TypeError("Cannot " + r);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
5
|
+
var l = (e, t, r) => (Q(e, t, "read from private field"), r ? r.call(e) : t.get(e)), u = (e, t, r) => {
|
|
6
6
|
if (t.has(e))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
8
|
t instanceof WeakSet ? t.add(e) : t.set(e, r);
|
|
9
|
-
}, h = (e, t, r, s) => (
|
|
10
|
-
var f = (e, t, r) => (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
}, h = (e, t, r, s) => (Q(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
|
|
10
|
+
var f = (e, t, r) => (Q(e, t, "access private method"), r);
|
|
11
|
+
const currentJsRuntime$1 = function() {
|
|
12
|
+
var e;
|
|
13
|
+
return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
typeof WorkerGlobalScope < "u" && // @ts-ignore
|
|
16
|
+
self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
|
|
17
|
+
);
|
|
18
|
+
}();
|
|
19
|
+
if (currentJsRuntime$1 === "NODE") {
|
|
20
|
+
let e = function(r) {
|
|
21
|
+
return new Promise(function(s, n) {
|
|
22
|
+
r.onload = r.onerror = function(i) {
|
|
23
|
+
r.onload = r.onerror = null, i.type === "load" ? s(r.result) : n(new Error("Failed to read the blob/file"));
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}, t = function() {
|
|
27
|
+
const r = new Uint8Array([1, 2, 3, 4]), n = new File([r], "test").stream();
|
|
28
|
+
try {
|
|
29
|
+
return n.getReader({ mode: "byob" }), !0;
|
|
30
|
+
} catch {
|
|
31
|
+
return !1;
|
|
17
32
|
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
29
|
-
const t = new FileReader();
|
|
30
|
-
return t.readAsArrayBuffer(this), asPromise(t);
|
|
31
|
-
});
|
|
32
|
-
typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
33
|
-
const t = new FileReader();
|
|
34
|
-
return t.readAsText(this), asPromise(t);
|
|
35
|
-
});
|
|
36
|
-
function isByobSupported() {
|
|
37
|
-
const e = new Uint8Array([1, 2, 3, 4]), r = new File([e], "test").stream();
|
|
38
|
-
try {
|
|
39
|
-
return r.getReader({ mode: "byob" }), !0;
|
|
40
|
-
} catch {
|
|
41
|
-
return !1;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
(typeof Blob.prototype.stream > "u" || !isByobSupported()) && (Blob.prototype.stream = function() {
|
|
45
|
-
let e = 0;
|
|
46
|
-
const t = this;
|
|
47
|
-
return new ReadableStream({
|
|
48
|
-
type: "bytes",
|
|
49
|
-
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
50
|
-
// this if needed.
|
|
51
|
-
autoAllocateChunkSize: 512 * 1024,
|
|
52
|
-
async pull(r) {
|
|
53
|
-
const s = r.byobRequest.view, i = await t.slice(e, e + s.byteLength).arrayBuffer(), o = new Uint8Array(i);
|
|
54
|
-
new Uint8Array(s.buffer).set(o);
|
|
55
|
-
const l = o.byteLength;
|
|
56
|
-
r.byobRequest.respond(l), e += l, e >= t.size && r.close();
|
|
33
|
+
};
|
|
34
|
+
if (typeof File > "u") {
|
|
35
|
+
class r extends Blob {
|
|
36
|
+
constructor(n, i, o) {
|
|
37
|
+
super(n);
|
|
38
|
+
let a;
|
|
39
|
+
o != null && o.lastModified && (a = /* @__PURE__ */ new Date()), (!a || isNaN(a.getFullYear())) && (a = /* @__PURE__ */ new Date()), this.lastModifiedDate = a, this.lastModified = a.getMilliseconds(), this.name = i || "";
|
|
40
|
+
}
|
|
57
41
|
}
|
|
42
|
+
global.File = r;
|
|
43
|
+
}
|
|
44
|
+
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
45
|
+
const s = new FileReader();
|
|
46
|
+
return s.readAsArrayBuffer(this), e(s);
|
|
47
|
+
}), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
48
|
+
const s = new FileReader();
|
|
49
|
+
return s.readAsText(this), e(s);
|
|
50
|
+
}), (typeof Blob.prototype.stream > "u" || !t()) && (Blob.prototype.stream = function() {
|
|
51
|
+
let r = 0;
|
|
52
|
+
const s = this;
|
|
53
|
+
return new ReadableStream({
|
|
54
|
+
type: "bytes",
|
|
55
|
+
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
56
|
+
// this if needed.
|
|
57
|
+
autoAllocateChunkSize: 512 * 1024,
|
|
58
|
+
async pull(n) {
|
|
59
|
+
const i = n.byobRequest.view, a = await s.slice(
|
|
60
|
+
r,
|
|
61
|
+
r + i.byteLength
|
|
62
|
+
).arrayBuffer(), c = new Uint8Array(a);
|
|
63
|
+
new Uint8Array(i.buffer).set(c);
|
|
64
|
+
const d = c.byteLength;
|
|
65
|
+
n.byobRequest.respond(d), r += d, r >= s.size && n.close();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
58
68
|
});
|
|
59
|
-
}
|
|
60
|
-
if (typeof CustomEvent > "u") {
|
|
69
|
+
}
|
|
70
|
+
if (currentJsRuntime$1 === "NODE" && typeof CustomEvent > "u") {
|
|
61
71
|
class e extends Event {
|
|
62
72
|
constructor(r, s = {}) {
|
|
63
73
|
super(r, s), this.detail = s.detail;
|
|
@@ -121,7 +131,7 @@ function improveWASMErrorReporting(e) {
|
|
|
121
131
|
} catch (o) {
|
|
122
132
|
if (!(o instanceof Error))
|
|
123
133
|
throw o;
|
|
124
|
-
const
|
|
134
|
+
const a = clarifyErrorMessage(
|
|
125
135
|
o,
|
|
126
136
|
(i = e.lastAsyncifyStackSource) == null ? void 0 : i.stack
|
|
127
137
|
);
|
|
@@ -129,12 +139,12 @@ function improveWASMErrorReporting(e) {
|
|
|
129
139
|
t.dispatchEvent(
|
|
130
140
|
new ErrorEvent("error", {
|
|
131
141
|
error: o,
|
|
132
|
-
message:
|
|
142
|
+
message: a
|
|
133
143
|
})
|
|
134
144
|
);
|
|
135
145
|
return;
|
|
136
146
|
}
|
|
137
|
-
throw isExitCodeZero(o) || showCriticalErrorBox(
|
|
147
|
+
throw isExitCodeZero(o) || showCriticalErrorBox(a), o;
|
|
138
148
|
}
|
|
139
149
|
};
|
|
140
150
|
}
|
|
@@ -278,9 +288,9 @@ function splitShellCommand(e) {
|
|
|
278
288
|
let s = 0, n = "";
|
|
279
289
|
const i = [];
|
|
280
290
|
let o = "";
|
|
281
|
-
for (let
|
|
282
|
-
const c = e[
|
|
283
|
-
c === "\\" ? ((e[
|
|
291
|
+
for (let a = 0; a < e.length; a++) {
|
|
292
|
+
const c = e[a];
|
|
293
|
+
c === "\\" ? ((e[a + 1] === '"' || e[a + 1] === "'") && a++, o += e[a]) : s === 0 ? c === '"' || c === "'" ? (s = 1, n = c) : c.match(/\s/) ? (o.trim().length && i.push(o.trim()), o = c) : i.length && !o ? o = i.pop() + c : o += c : s === 1 && (c === n ? (s = 0, n = "") : o += c);
|
|
284
294
|
}
|
|
285
295
|
return o && i.push(o.trim()), i;
|
|
286
296
|
}
|
|
@@ -492,8 +502,8 @@ async function* iteratePhpFiles(e, t, {
|
|
|
492
502
|
const o = i.pop();
|
|
493
503
|
if (!o)
|
|
494
504
|
return;
|
|
495
|
-
const
|
|
496
|
-
for (const c of
|
|
505
|
+
const a = await e.listFiles(o);
|
|
506
|
+
for (const c of a) {
|
|
497
507
|
const d = `${o}/${c}`;
|
|
498
508
|
if (n.includes(d.substring(t.length + 1)))
|
|
499
509
|
continue;
|
|
@@ -608,7 +618,7 @@ class PHPBrowser {
|
|
|
608
618
|
cookie: this.serializeCookies()
|
|
609
619
|
}
|
|
610
620
|
});
|
|
611
|
-
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]),
|
|
621
|
+
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), l(this, b).handleRedirects && s.headers.location && r < l(this, b).maxRedirects) {
|
|
612
622
|
const n = new URL(
|
|
613
623
|
s.headers.location[0],
|
|
614
624
|
this.requestHandler.absoluteUrl
|
|
@@ -646,15 +656,15 @@ class PHPBrowser {
|
|
|
646
656
|
if (!r.includes("="))
|
|
647
657
|
continue;
|
|
648
658
|
const s = r.indexOf("="), n = r.substring(0, s), i = r.substring(s + 1).split(";")[0];
|
|
649
|
-
|
|
659
|
+
l(this, E)[n] = i;
|
|
650
660
|
} catch (s) {
|
|
651
661
|
console.error(s);
|
|
652
662
|
}
|
|
653
663
|
}
|
|
654
664
|
serializeCookies() {
|
|
655
665
|
const t = [];
|
|
656
|
-
for (const r in
|
|
657
|
-
t.push(`${r}=${
|
|
666
|
+
for (const r in l(this, E))
|
|
667
|
+
t.push(`${r}=${l(this, E)[r]}`);
|
|
658
668
|
return t.join("; ");
|
|
659
669
|
}
|
|
660
670
|
}
|
|
@@ -681,12 +691,12 @@ async function encodeAsMultipart(e) {
|
|
|
681
691
|
n.push(`--${t}--\r
|
|
682
692
|
`);
|
|
683
693
|
const i = n.reduce((c, d) => c + d.length, 0), o = new Uint8Array(i);
|
|
684
|
-
let
|
|
694
|
+
let a = 0;
|
|
685
695
|
for (const c of n)
|
|
686
696
|
o.set(
|
|
687
697
|
typeof c == "string" ? s.encode(c) : c,
|
|
688
|
-
|
|
689
|
-
),
|
|
698
|
+
a
|
|
699
|
+
), a += c.length;
|
|
690
700
|
return { bytes: o, contentType: r };
|
|
691
701
|
}
|
|
692
702
|
function fileToUint8Array(e) {
|
|
@@ -697,7 +707,7 @@ function fileToUint8Array(e) {
|
|
|
697
707
|
}, r.readAsArrayBuffer(e);
|
|
698
708
|
});
|
|
699
709
|
}
|
|
700
|
-
var m, H, k, v, x, _, F, R, B, Y, I,
|
|
710
|
+
var m, H, k, v, x, _, F, R, B, Y, I, K, N, Z;
|
|
701
711
|
class PHPRequestHandler {
|
|
702
712
|
/**
|
|
703
713
|
* @param php - The PHP instance.
|
|
@@ -728,7 +738,7 @@ class PHPRequestHandler {
|
|
|
728
738
|
* @throws {Error} If the requested path doesn't exist.
|
|
729
739
|
* @returns The resolved filesystem path.
|
|
730
740
|
*/
|
|
731
|
-
u(this,
|
|
741
|
+
u(this, N);
|
|
732
742
|
u(this, m, void 0);
|
|
733
743
|
u(this, H, void 0);
|
|
734
744
|
u(this, k, void 0);
|
|
@@ -745,14 +755,14 @@ class PHPRequestHandler {
|
|
|
745
755
|
this.php = t, h(this, m, s);
|
|
746
756
|
const i = new URL(n);
|
|
747
757
|
h(this, k, i.hostname), h(this, v, i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80), h(this, H, (i.protocol || "").replace(":", ""));
|
|
748
|
-
const o =
|
|
758
|
+
const o = l(this, v) !== 443 && l(this, v) !== 80;
|
|
749
759
|
h(this, x, [
|
|
750
|
-
|
|
751
|
-
o ? `:${
|
|
760
|
+
l(this, k),
|
|
761
|
+
o ? `:${l(this, v)}` : ""
|
|
752
762
|
].join("")), h(this, _, i.pathname.replace(/\/+$/, "")), h(this, F, [
|
|
753
|
-
`${
|
|
754
|
-
|
|
755
|
-
|
|
763
|
+
`${l(this, H)}://`,
|
|
764
|
+
l(this, x),
|
|
765
|
+
l(this, _)
|
|
756
766
|
].join(""));
|
|
757
767
|
}
|
|
758
768
|
/** @inheritDoc */
|
|
@@ -762,18 +772,18 @@ class PHPRequestHandler {
|
|
|
762
772
|
/** @inheritDoc */
|
|
763
773
|
internalUrlToPath(t) {
|
|
764
774
|
const r = new URL(t);
|
|
765
|
-
return r.pathname.startsWith(
|
|
775
|
+
return r.pathname.startsWith(l(this, _)) && (r.pathname = r.pathname.slice(l(this, _).length)), toRelativeUrl(r);
|
|
766
776
|
}
|
|
767
777
|
get isRequestRunning() {
|
|
768
|
-
return
|
|
778
|
+
return l(this, R).running > 0;
|
|
769
779
|
}
|
|
770
780
|
/** @inheritDoc */
|
|
771
781
|
get absoluteUrl() {
|
|
772
|
-
return
|
|
782
|
+
return l(this, F);
|
|
773
783
|
}
|
|
774
784
|
/** @inheritDoc */
|
|
775
785
|
get documentRoot() {
|
|
776
|
-
return
|
|
786
|
+
return l(this, m);
|
|
777
787
|
}
|
|
778
788
|
/** @inheritDoc */
|
|
779
789
|
async request(t) {
|
|
@@ -782,9 +792,9 @@ class PHPRequestHandler {
|
|
|
782
792
|
r ? void 0 : DEFAULT_BASE_URL
|
|
783
793
|
), n = removePathPrefix(
|
|
784
794
|
s.pathname,
|
|
785
|
-
|
|
786
|
-
), i = `${
|
|
787
|
-
return seemsLikeAPHPRequestHandlerPath(i) ? await f(this, I,
|
|
795
|
+
l(this, _)
|
|
796
|
+
), i = `${l(this, m)}${n}`;
|
|
797
|
+
return seemsLikeAPHPRequestHandlerPath(i) ? await f(this, I, K).call(this, t, s) : f(this, B, Y).call(this, i);
|
|
788
798
|
}
|
|
789
799
|
}
|
|
790
800
|
m = new WeakMap(), H = new WeakMap(), k = new WeakMap(), v = new WeakMap(), x = new WeakMap(), _ = new WeakMap(), F = new WeakMap(), R = new WeakMap(), B = new WeakSet(), Y = function(t) {
|
|
@@ -812,9 +822,9 @@ m = new WeakMap(), H = new WeakMap(), k = new WeakMap(), v = new WeakMap(), x =
|
|
|
812
822
|
},
|
|
813
823
|
r
|
|
814
824
|
);
|
|
815
|
-
}, I = new WeakSet(),
|
|
825
|
+
}, I = new WeakSet(), K = async function(t, r) {
|
|
816
826
|
var n, i;
|
|
817
|
-
if (
|
|
827
|
+
if (l(this, R).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
|
|
818
828
|
return console.warn(
|
|
819
829
|
"Possible deadlock: Called request() before the previous request() have finished. PHP likely issued an HTTP call to itself. Normally this would lead to infinite waiting as Request 1 holds the lock that the Request 2 is waiting to acquire. That's not useful, so PHPRequestHandler will return error 502 instead."
|
|
820
830
|
), new PHPResponse(
|
|
@@ -822,22 +832,22 @@ m = new WeakMap(), H = new WeakMap(), k = new WeakMap(), v = new WeakMap(), x =
|
|
|
822
832
|
{},
|
|
823
833
|
new TextEncoder().encode("502 Bad Gateway")
|
|
824
834
|
);
|
|
825
|
-
const s = await
|
|
835
|
+
const s = await l(this, R).acquire();
|
|
826
836
|
try {
|
|
827
|
-
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT",
|
|
837
|
+
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", l(this, m)), this.php.addServerGlobalEntry(
|
|
828
838
|
"HTTPS",
|
|
829
|
-
|
|
839
|
+
l(this, F).startsWith("https://") ? "on" : ""
|
|
830
840
|
);
|
|
831
841
|
let o = "GET";
|
|
832
|
-
const
|
|
833
|
-
host:
|
|
842
|
+
const a = {
|
|
843
|
+
host: l(this, x),
|
|
834
844
|
...normalizeHeaders(t.headers || {})
|
|
835
845
|
};
|
|
836
846
|
let c = t.body;
|
|
837
847
|
if (typeof c == "object" && !(c instanceof Uint8Array)) {
|
|
838
848
|
o = "POST";
|
|
839
849
|
const { bytes: p, contentType: U } = await encodeAsMultipart(c);
|
|
840
|
-
c = p,
|
|
850
|
+
c = p, a["content-type"] = U;
|
|
841
851
|
}
|
|
842
852
|
let d;
|
|
843
853
|
try {
|
|
@@ -849,7 +859,7 @@ m = new WeakMap(), H = new WeakMap(), k = new WeakMap(), v = new WeakMap(), x =
|
|
|
849
859
|
).pathname;
|
|
850
860
|
} catch {
|
|
851
861
|
}
|
|
852
|
-
d = f(this,
|
|
862
|
+
d = f(this, N, Z).call(this, p);
|
|
853
863
|
} catch {
|
|
854
864
|
return new PHPResponse(
|
|
855
865
|
404,
|
|
@@ -860,21 +870,21 @@ m = new WeakMap(), H = new WeakMap(), k = new WeakMap(), v = new WeakMap(), x =
|
|
|
860
870
|
return await this.php.run({
|
|
861
871
|
relativeUri: ensurePathPrefix(
|
|
862
872
|
toRelativeUrl(r),
|
|
863
|
-
|
|
873
|
+
l(this, _)
|
|
864
874
|
),
|
|
865
|
-
protocol:
|
|
875
|
+
protocol: l(this, H),
|
|
866
876
|
method: t.method || o,
|
|
867
877
|
body: c,
|
|
868
878
|
scriptPath: d,
|
|
869
|
-
headers:
|
|
879
|
+
headers: a
|
|
870
880
|
});
|
|
871
881
|
} finally {
|
|
872
882
|
s();
|
|
873
883
|
}
|
|
874
|
-
},
|
|
875
|
-
let r = removePathPrefix(t,
|
|
876
|
-
r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${
|
|
877
|
-
const s = `${
|
|
884
|
+
}, N = new WeakSet(), Z = function(t) {
|
|
885
|
+
let r = removePathPrefix(t, l(this, _));
|
|
886
|
+
r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${l(this, m)}${r}`) ? (r.endsWith("/") || (r = `${r}/`), r = `${r}index.php`) : r = "/index.php";
|
|
887
|
+
const s = `${l(this, m)}${r}`;
|
|
878
888
|
if (this.php.fileExists(s))
|
|
879
889
|
return s;
|
|
880
890
|
throw new Error(`File not found: ${s}`);
|
|
@@ -1018,15 +1028,15 @@ function rethrowFileSystemError(e = "") {
|
|
|
1018
1028
|
n.value = function(...o) {
|
|
1019
1029
|
try {
|
|
1020
1030
|
return i.apply(this, o);
|
|
1021
|
-
} catch (
|
|
1022
|
-
const c = typeof
|
|
1031
|
+
} catch (a) {
|
|
1032
|
+
const c = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
1023
1033
|
if (c in FileErrorCodes) {
|
|
1024
1034
|
const d = FileErrorCodes[c], p = typeof o[0] == "string" ? o[0] : null, U = p !== null ? e.replaceAll("{path}", p) : e;
|
|
1025
1035
|
throw new Error(`${U}: ${d}`, {
|
|
1026
|
-
cause:
|
|
1036
|
+
cause: a
|
|
1027
1037
|
});
|
|
1028
1038
|
}
|
|
1029
|
-
throw
|
|
1039
|
+
throw a;
|
|
1030
1040
|
}
|
|
1031
1041
|
};
|
|
1032
1042
|
};
|
|
@@ -1035,14 +1045,14 @@ const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map(
|
|
|
1035
1045
|
let lastRuntimeId = 0;
|
|
1036
1046
|
async function loadPHPRuntime(e, t = {}) {
|
|
1037
1047
|
const [r, s, n] = makePromise(), i = e.init(currentJsRuntime, {
|
|
1038
|
-
onAbort(
|
|
1039
|
-
n(
|
|
1048
|
+
onAbort(a) {
|
|
1049
|
+
n(a), console.error(a);
|
|
1040
1050
|
},
|
|
1041
1051
|
ENV: {},
|
|
1042
1052
|
// Emscripten sometimes prepends a '/' to the path, which
|
|
1043
1053
|
// breaks vite dev mode. An identity `locateFile` function
|
|
1044
1054
|
// fixes it.
|
|
1045
|
-
locateFile: (
|
|
1055
|
+
locateFile: (a) => a,
|
|
1046
1056
|
...t,
|
|
1047
1057
|
noInitialRun: !0,
|
|
1048
1058
|
onRuntimeInitialized() {
|
|
@@ -1051,8 +1061,8 @@ async function loadPHPRuntime(e, t = {}) {
|
|
|
1051
1061
|
});
|
|
1052
1062
|
await r;
|
|
1053
1063
|
const o = ++lastRuntimeId;
|
|
1054
|
-
return i.id = o, i.originalExit = i._exit, i._exit = function(
|
|
1055
|
-
return loadedRuntimes.delete(o), i.originalExit(
|
|
1064
|
+
return i.id = o, i.originalExit = i._exit, i._exit = function(a) {
|
|
1065
|
+
return loadedRuntimes.delete(o), i.originalExit(a);
|
|
1056
1066
|
}, i[RuntimeId] = o, loadedRuntimes.set(o, i), o;
|
|
1057
1067
|
}
|
|
1058
1068
|
function getLoadedRuntime(e) {
|
|
@@ -1073,7 +1083,7 @@ var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyD
|
|
|
1073
1083
|
return s && n && __defProp(t, r, n), n;
|
|
1074
1084
|
};
|
|
1075
1085
|
const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
|
|
1076
|
-
var S, T, A, y, w, g, P, C,
|
|
1086
|
+
var S, T, A, y, w, g, P, C, L, X, O, ee, M, te, q, re, D, se, $, ne, j, ie, W, oe, z, ae, G, le, V, ce, J, ue;
|
|
1077
1087
|
class BasePHP {
|
|
1078
1088
|
/**
|
|
1079
1089
|
* Initializes a PHP runtime.
|
|
@@ -1083,18 +1093,18 @@ class BasePHP {
|
|
|
1083
1093
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
1084
1094
|
*/
|
|
1085
1095
|
constructor(e, t) {
|
|
1086
|
-
u(this,
|
|
1096
|
+
u(this, L);
|
|
1097
|
+
u(this, O);
|
|
1087
1098
|
u(this, M);
|
|
1088
1099
|
u(this, q);
|
|
1089
|
-
u(this, O);
|
|
1090
|
-
u(this, $);
|
|
1091
1100
|
u(this, D);
|
|
1101
|
+
u(this, $);
|
|
1092
1102
|
u(this, j);
|
|
1093
|
-
u(this, z);
|
|
1094
1103
|
u(this, W);
|
|
1104
|
+
u(this, z);
|
|
1095
1105
|
u(this, G);
|
|
1096
1106
|
u(this, V);
|
|
1097
|
-
u(this,
|
|
1107
|
+
u(this, J);
|
|
1098
1108
|
u(this, S, void 0);
|
|
1099
1109
|
u(this, T, void 0);
|
|
1100
1110
|
u(this, A, void 0);
|
|
@@ -1108,21 +1118,21 @@ class BasePHP {
|
|
|
1108
1118
|
));
|
|
1109
1119
|
}
|
|
1110
1120
|
addEventListener(e, t) {
|
|
1111
|
-
|
|
1121
|
+
l(this, P).has(e) || l(this, P).set(e, /* @__PURE__ */ new Set()), l(this, P).get(e).add(t);
|
|
1112
1122
|
}
|
|
1113
1123
|
removeEventListener(e, t) {
|
|
1114
1124
|
var r;
|
|
1115
|
-
(r =
|
|
1125
|
+
(r = l(this, P).get(e)) == null || r.delete(t);
|
|
1116
1126
|
}
|
|
1117
1127
|
dispatchEvent(e) {
|
|
1118
|
-
const t =
|
|
1128
|
+
const t = l(this, P).get(e.type);
|
|
1119
1129
|
if (t)
|
|
1120
1130
|
for (const r of t)
|
|
1121
1131
|
r(e);
|
|
1122
1132
|
}
|
|
1123
1133
|
/** @inheritDoc */
|
|
1124
1134
|
async onMessage(e) {
|
|
1125
|
-
|
|
1135
|
+
l(this, C).push(e);
|
|
1126
1136
|
}
|
|
1127
1137
|
/** @inheritDoc */
|
|
1128
1138
|
async setSpawnHandler(handler) {
|
|
@@ -1153,7 +1163,7 @@ class BasePHP {
|
|
|
1153
1163
|
if (!t)
|
|
1154
1164
|
throw new Error("Invalid PHP runtime id.");
|
|
1155
1165
|
this[__private__dont__use] = t, t.onMessage = async (r) => {
|
|
1156
|
-
for (const s of
|
|
1166
|
+
for (const s of l(this, C)) {
|
|
1157
1167
|
const n = await s(r);
|
|
1158
1168
|
if (n)
|
|
1159
1169
|
return n;
|
|
@@ -1178,7 +1188,7 @@ class BasePHP {
|
|
|
1178
1188
|
}
|
|
1179
1189
|
/** @inheritDoc */
|
|
1180
1190
|
setPhpIniPath(e) {
|
|
1181
|
-
if (
|
|
1191
|
+
if (l(this, y))
|
|
1182
1192
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
1183
1193
|
h(this, T, e), this[__private__dont__use].ccall(
|
|
1184
1194
|
"wasm_set_phpini_path",
|
|
@@ -1189,9 +1199,9 @@ class BasePHP {
|
|
|
1189
1199
|
}
|
|
1190
1200
|
/** @inheritDoc */
|
|
1191
1201
|
setPhpIniEntry(e, t) {
|
|
1192
|
-
if (
|
|
1202
|
+
if (l(this, y))
|
|
1193
1203
|
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
1194
|
-
|
|
1204
|
+
l(this, S).push([e, t]);
|
|
1195
1205
|
}
|
|
1196
1206
|
/** @inheritDoc */
|
|
1197
1207
|
chdir(e) {
|
|
@@ -1208,27 +1218,27 @@ class BasePHP {
|
|
|
1208
1218
|
const t = await this.semaphore.acquire();
|
|
1209
1219
|
let r;
|
|
1210
1220
|
try {
|
|
1211
|
-
if (
|
|
1221
|
+
if (l(this, y) || (f(this, L, X).call(this), h(this, y, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
1212
1222
|
throw new Error(
|
|
1213
1223
|
`The script path "${e.scriptPath}" does not exist.`
|
|
1214
1224
|
);
|
|
1215
|
-
f(this,
|
|
1225
|
+
f(this, W, oe).call(this, e.scriptPath || ""), f(this, M, te).call(this, e.relativeUri || ""), f(this, D, se).call(this, e.method || "GET");
|
|
1216
1226
|
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
|
|
1217
|
-
f(this,
|
|
1227
|
+
f(this, q, re).call(this, n, e.protocol || "http"), f(this, $, ne).call(this, s), e.body && (r = f(this, j, ie).call(this, e.body)), typeof e.code == "string" && f(this, V, ce).call(this, " ?>" + e.code), f(this, z, ae).call(this);
|
|
1218
1228
|
const i = e.env || {};
|
|
1219
|
-
for (const
|
|
1220
|
-
f(this, G, le).call(this,
|
|
1221
|
-
const o = await f(this,
|
|
1229
|
+
for (const a in i)
|
|
1230
|
+
f(this, G, le).call(this, a, i[a]);
|
|
1231
|
+
const o = await f(this, J, ue).call(this);
|
|
1222
1232
|
if (e.throwOnError && o.exitCode !== 0) {
|
|
1223
|
-
const
|
|
1233
|
+
const a = {
|
|
1224
1234
|
stdout: o.text,
|
|
1225
1235
|
stderr: o.errors
|
|
1226
1236
|
};
|
|
1227
|
-
console.warn("PHP.run() output was:",
|
|
1237
|
+
console.warn("PHP.run() output was:", a);
|
|
1228
1238
|
const c = new Error(
|
|
1229
1239
|
`PHP.run() failed with exit code ${o.exitCode} and the following output: ` + o.errors
|
|
1230
1240
|
);
|
|
1231
|
-
throw c.output =
|
|
1241
|
+
throw c.output = a, console.error(c), c;
|
|
1232
1242
|
}
|
|
1233
1243
|
return o;
|
|
1234
1244
|
} finally {
|
|
@@ -1242,7 +1252,7 @@ class BasePHP {
|
|
|
1242
1252
|
}
|
|
1243
1253
|
}
|
|
1244
1254
|
addServerGlobalEntry(e, t) {
|
|
1245
|
-
|
|
1255
|
+
l(this, g)[e] = t;
|
|
1246
1256
|
}
|
|
1247
1257
|
defineConstant(e, t) {
|
|
1248
1258
|
let r = {};
|
|
@@ -1338,7 +1348,7 @@ class BasePHP {
|
|
|
1338
1348
|
this.exit();
|
|
1339
1349
|
} catch {
|
|
1340
1350
|
}
|
|
1341
|
-
if (this.initializeRuntime(e),
|
|
1351
|
+
if (this.initializeRuntime(e), l(this, T) && this.setPhpIniPath(l(this, T)), l(this, A) && this.setSapiName(l(this, A)), this.requestHandler) {
|
|
1342
1352
|
const r = this.documentRoot;
|
|
1343
1353
|
copyFS(t, this[__private__dont__use].FS, r);
|
|
1344
1354
|
}
|
|
@@ -1354,7 +1364,7 @@ class BasePHP {
|
|
|
1354
1364
|
h(this, y, !1), h(this, w, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1355
1365
|
}
|
|
1356
1366
|
}
|
|
1357
|
-
S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), P = new WeakMap(), C = new WeakMap(),
|
|
1367
|
+
S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), P = new WeakMap(), C = new WeakMap(), L = new WeakSet(), X = function() {
|
|
1358
1368
|
if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
|
|
1359
1369
|
"/internal/consts.php",
|
|
1360
1370
|
`<?php
|
|
@@ -1366,8 +1376,8 @@ S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w =
|
|
|
1366
1376
|
}
|
|
1367
1377
|
}
|
|
1368
1378
|
}`
|
|
1369
|
-
),
|
|
1370
|
-
const e =
|
|
1379
|
+
), l(this, S).length > 0) {
|
|
1380
|
+
const e = l(this, S).map(([t, r]) => `${t}=${r}`).join(`
|
|
1371
1381
|
`) + `
|
|
1372
1382
|
|
|
1373
1383
|
`;
|
|
@@ -1379,7 +1389,7 @@ S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w =
|
|
|
1379
1389
|
);
|
|
1380
1390
|
}
|
|
1381
1391
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1382
|
-
},
|
|
1392
|
+
}, O = new WeakSet(), ee = function() {
|
|
1383
1393
|
const e = "/internal/headers.json";
|
|
1384
1394
|
if (!this.fileExists(e))
|
|
1385
1395
|
throw new Error(
|
|
@@ -1396,7 +1406,7 @@ S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w =
|
|
|
1396
1406
|
headers: r,
|
|
1397
1407
|
httpStatusCode: t.status
|
|
1398
1408
|
};
|
|
1399
|
-
},
|
|
1409
|
+
}, M = new WeakSet(), te = function(e) {
|
|
1400
1410
|
if (this[__private__dont__use].ccall(
|
|
1401
1411
|
"wasm_set_request_uri",
|
|
1402
1412
|
null,
|
|
@@ -1411,7 +1421,7 @@ S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w =
|
|
|
1411
1421
|
[t]
|
|
1412
1422
|
);
|
|
1413
1423
|
}
|
|
1414
|
-
},
|
|
1424
|
+
}, q = new WeakSet(), re = function(e, t) {
|
|
1415
1425
|
this[__private__dont__use].ccall(
|
|
1416
1426
|
"wasm_set_request_host",
|
|
1417
1427
|
null,
|
|
@@ -1429,14 +1439,14 @@ S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w =
|
|
|
1429
1439
|
[NUMBER],
|
|
1430
1440
|
[r]
|
|
1431
1441
|
), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
1432
|
-
},
|
|
1442
|
+
}, D = new WeakSet(), se = function(e) {
|
|
1433
1443
|
this[__private__dont__use].ccall(
|
|
1434
1444
|
"wasm_set_request_method",
|
|
1435
1445
|
null,
|
|
1436
1446
|
[STRING],
|
|
1437
1447
|
[e]
|
|
1438
1448
|
);
|
|
1439
|
-
},
|
|
1449
|
+
}, $ = new WeakSet(), ne = function(e) {
|
|
1440
1450
|
e.cookie && this[__private__dont__use].ccall(
|
|
1441
1451
|
"wasm_set_cookies",
|
|
1442
1452
|
null,
|
|
@@ -1483,20 +1493,20 @@ S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w =
|
|
|
1483
1493
|
[NUMBER],
|
|
1484
1494
|
[r]
|
|
1485
1495
|
), s;
|
|
1486
|
-
},
|
|
1496
|
+
}, W = new WeakSet(), oe = function(e) {
|
|
1487
1497
|
this[__private__dont__use].ccall(
|
|
1488
1498
|
"wasm_set_path_translated",
|
|
1489
1499
|
null,
|
|
1490
1500
|
[STRING],
|
|
1491
1501
|
[e]
|
|
1492
1502
|
);
|
|
1493
|
-
},
|
|
1494
|
-
for (const e in
|
|
1503
|
+
}, z = new WeakSet(), ae = function() {
|
|
1504
|
+
for (const e in l(this, g))
|
|
1495
1505
|
this[__private__dont__use].ccall(
|
|
1496
1506
|
"wasm_add_SERVER_entry",
|
|
1497
1507
|
null,
|
|
1498
1508
|
[STRING, STRING],
|
|
1499
|
-
[e,
|
|
1509
|
+
[e, l(this, g)[e]]
|
|
1500
1510
|
);
|
|
1501
1511
|
}, G = new WeakSet(), le = function(e, t) {
|
|
1502
1512
|
this[__private__dont__use].ccall(
|
|
@@ -1512,7 +1522,7 @@ S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w =
|
|
|
1512
1522
|
[STRING],
|
|
1513
1523
|
[e]
|
|
1514
1524
|
);
|
|
1515
|
-
},
|
|
1525
|
+
}, J = new WeakSet(), ue = async function() {
|
|
1516
1526
|
var n;
|
|
1517
1527
|
let e, t;
|
|
1518
1528
|
try {
|
|
@@ -1522,18 +1532,18 @@ S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w =
|
|
|
1522
1532
|
console.error(d), console.error(d.error);
|
|
1523
1533
|
const p = new Error("Rethrown");
|
|
1524
1534
|
p.cause = d.error, p.betterMessage = d.message, o(p);
|
|
1525
|
-
}, (c =
|
|
1535
|
+
}, (c = l(this, w)) == null || c.addEventListener(
|
|
1526
1536
|
"error",
|
|
1527
1537
|
t
|
|
1528
1538
|
);
|
|
1529
|
-
const
|
|
1539
|
+
const a = this[__private__dont__use].ccall(
|
|
1530
1540
|
"wasm_sapi_handle_request",
|
|
1531
1541
|
NUMBER,
|
|
1532
1542
|
[],
|
|
1533
1543
|
[],
|
|
1534
1544
|
{ async: !0 }
|
|
1535
1545
|
);
|
|
1536
|
-
return
|
|
1546
|
+
return a instanceof Promise ? a.then(i, o) : i(a);
|
|
1537
1547
|
});
|
|
1538
1548
|
} catch (i) {
|
|
1539
1549
|
for (const d in this)
|
|
@@ -1543,12 +1553,12 @@ S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w =
|
|
|
1543
1553
|
);
|
|
1544
1554
|
});
|
|
1545
1555
|
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1546
|
-
const o = i,
|
|
1556
|
+
const o = i, a = "betterMessage" in o ? o.betterMessage : o.message, c = new Error(a);
|
|
1547
1557
|
throw c.cause = o, console.error(c), c;
|
|
1548
1558
|
} finally {
|
|
1549
|
-
(n =
|
|
1559
|
+
(n = l(this, w)) == null || n.removeEventListener("error", t), h(this, g, {});
|
|
1550
1560
|
}
|
|
1551
|
-
const { headers: r, httpStatusCode: s } = f(this,
|
|
1561
|
+
const { headers: r, httpStatusCode: s } = f(this, O, ee).call(this);
|
|
1552
1562
|
return new PHPResponse(
|
|
1553
1563
|
s,
|
|
1554
1564
|
r,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/universal",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "PHP.wasm – emscripten bindings for PHP",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"main": "./index.cjs",
|
|
37
37
|
"module": "./index.js",
|
|
38
38
|
"license": "GPL-2.0-or-later",
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "c4c52563eee8997b94cd4a0875e10fb5d8ccda42",
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=18.18.2",
|
|
42
42
|
"npm": ">=8.11.0"
|