├── .eslintrc.cjs ├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── playwright.yml │ ├── review_dog.yml │ ├── static.yml │ └── test.yml ├── .gitignore ├── .node-version ├── .prettierignore ├── .prettierrc.json ├── LICENSE ├── Makefile ├── Readme.md ├── assets ├── ads.txt ├── favicon.svg ├── octocat.png ├── ogp.png ├── php-5.6.wasm ├── php-7.0.wasm ├── php-7.1.wasm ├── php-7.2.wasm ├── php-7.3.wasm ├── php-7.4.wasm ├── php-8.0.wasm ├── php-8.1.wasm ├── php-8.2.wasm ├── php-8.3.wasm ├── php-8.4.wasm ├── privacy.html └── sitemap.xml ├── build.mjs ├── doc └── demo.gif ├── e2e └── e2e.spec.ts ├── index.html ├── package-lock.json ├── package.json ├── playwright.config.ts ├── src ├── __test__ │ ├── __snapshots__ │ │ └── php.test.ts.snap │ ├── php.spec.ts │ └── php.test.ts ├── app.tsx ├── editor.tsx ├── footer.tsx ├── format.tsx ├── header.tsx ├── index.tsx ├── manual.tsx ├── php-wasm │ ├── __tests__ │ │ ├── php.ts │ │ └── utils.ts │ ├── index.ts │ ├── php-browser.ts │ ├── php-server.ts │ ├── php.ts │ └── utils.ts ├── php.ts ├── select.tsx ├── switch.tsx ├── theme.tsx ├── wasm-assets │ ├── php-5.6.js │ ├── php-7.0.js │ ├── php-7.1.js │ ├── php-7.2.js │ ├── php-7.3.js │ ├── php-7.4.js │ ├── php-8.0.js │ ├── php-8.1.js │ ├── php-8.2.js │ ├── php-8.3.js │ └── php-8.4.js └── wasm │ ├── Dockerfile │ └── build-assets │ ├── bison27.patch │ ├── ncurses.patch │ ├── php5.6-openssl1.1.patch │ ├── php5.6.patch │ ├── php7.0.patch │ ├── php7.1.patch │ ├── php7.2.patch │ ├── php7.3.patch │ ├── php7.4.patch │ ├── php8.0.patch │ ├── php8.1.patch │ ├── php8.2.patch │ ├── php8.3.patch │ ├── php8.4.patch │ ├── php_wasm.c │ ├── phpwasm-emscripten-library.js │ ├── replace.sh │ └── zlib │ ├── CMakeLists.txt │ ├── Makefile.in │ ├── README │ ├── adler32.c │ ├── benchmark.c │ ├── compress.c │ ├── configure │ ├── crc32.c │ ├── crc32.h │ ├── deflate.c │ ├── deflate.h │ ├── example.c │ ├── gzclose.c │ ├── gzguts.h │ ├── gzlib.c │ ├── gzread.c │ ├── gzwrite.c │ ├── infback.c │ ├── inffast.c │ ├── inffast.h │ ├── inffixed.h │ ├── inflate.c │ ├── inflate.h │ ├── inftrees.c │ ├── inftrees.h │ ├── minigzip.c │ ├── readme.txt │ ├── ref.txt │ ├── trees.c │ ├── trees.h │ ├── uncompr.c │ ├── zconf.h │ ├── zconf.h.cmakein │ ├── zconf.h.in │ ├── zlib.3 │ ├── zlib.h │ ├── zlib.map │ ├── zlib.pc │ ├── zlib.pc.in │ ├── zutil.c │ └── zutil.h ├── tsconfig.json ├── vite.config.js └── vitest.config.js /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | es2021: true, 5 | }, 6 | settings: { 7 | jsdoc: { 8 | tagNamePreference: { 9 | return: 'returns', 10 | internal: 'internal', 11 | }, 12 | }, 13 | react: { 14 | version: 'detect', 15 | } 16 | }, 17 | extends: [ 18 | 'eslint:recommended', 19 | 'plugin:react/recommended', 20 | 'plugin:@typescript-eslint/recommended', 21 | ], 22 | parser: '@typescript-eslint/parser', 23 | parserOptions: { 24 | ecmaVersion: 'latest', 25 | sourceType: 'module', 26 | }, 27 | root: true, 28 | ignorePatterns: [ 29 | "src/php-wasm/__tests__/*.ts", 30 | "src/wasm/build-assets/*.js", 31 | "src/wasm-assets/*.js" 32 | ], 33 | plugins: ['react', '@typescript-eslint'], 34 | rules: { 35 | 'no-inner-declarations': 0, 36 | 'no-use-before-define': 'off', 37 | 'react/prop-types': 0, 38 | 'no-console': 0, 39 | 'no-empty': 0, 40 | 'no-async-promise-executor': 0, 41 | 'no-constant-condition': 0, 42 | 'no-nested-ternary': 0, 43 | 'jsx-a11y/click-events-have-key-events': 0, 44 | 'jsx-a11y/no-static-element-interactions': 0, 45 | '@typescript-eslint/ban-ts-comment': 0, 46 | '@typescript-eslint/no-non-null-assertion': 0, 47 | }, 48 | }; -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: glassmonkey 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: weekly -------------------------------------------------------------------------------- /.github/workflows/playwright.yml: -------------------------------------------------------------------------------- 1 | name: Playwright Tests 2 | on: 3 | push: 4 | branches: 5 | master 6 | pull_request: 7 | branches: 8 | master 9 | jobs: 10 | test: 11 | timeout-minutes: 60 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: actions/setup-node@v4 16 | with: 17 | node-version: lts/* 18 | - name: Install dependencies 19 | run: npm ci 20 | - name: Install Playwright Browsers 21 | run: npx playwright install --with-deps 22 | - name: Run Playwright tests 23 | run: npx playwright test 24 | - uses: actions/upload-artifact@v4 25 | if: always() 26 | with: 27 | name: playwright-report 28 | path: playwright-report/ 29 | retention-days: 30 30 | -------------------------------------------------------------------------------- /.github/workflows/review_dog.yml: -------------------------------------------------------------------------------- 1 | name: reviewdog 2 | on: [pull_request] 3 | jobs: 4 | eslint: 5 | name: runner / eslint 6 | runs-on: ubuntu-latest 7 | permissions: 8 | contents: read 9 | pull-requests: write 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: reviewdog/action-eslint@v1 13 | with: 14 | github_token: ${{ github.token }} 15 | reporter: github-pr-review # Change reporter. 16 | eslint_flags: 'src/' -------------------------------------------------------------------------------- /.github/workflows/static.yml: -------------------------------------------------------------------------------- 1 | # Simple workflow for deploying static content to GitHub Pages 2 | name: Deploy static content to Pages 3 | 4 | on: 5 | # Runs on pushes targeting the default branch 6 | push: 7 | branches: ["master"] 8 | 9 | # Allows you to run this workflow manually from the Actions tab 10 | workflow_dispatch: 11 | 12 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 13 | permissions: 14 | contents: read 15 | pages: write 16 | id-token: write 17 | 18 | # Allow one concurrent deployment 19 | concurrency: 20 | group: "pages" 21 | cancel-in-progress: true 22 | 23 | jobs: 24 | # Single deploy job since we're just deploying 25 | deploy: 26 | environment: 27 | name: github-pages 28 | url: ${{ steps.deployment.outputs.page_url }} 29 | runs-on: ubuntu-latest 30 | steps: 31 | - name: Checkout 32 | uses: actions/checkout@v4 33 | - name: Setup Pages 34 | uses: actions/configure-pages@v3 35 | - name: Cache node modules 36 | id: cache-npm 37 | uses: actions/cache@v3 38 | env: 39 | cache-name: cache-node-modules 40 | with: 41 | # npm cache files are stored in `~/.npm` on Linux/macOS 42 | path: ~/.npm 43 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} 44 | restore-keys: | 45 | ${{ runner.os }}-build-${{ env.cache-name }}- 46 | ${{ runner.os }}-build- 47 | ${{ runner.os }}- 48 | - name: Install dependencies 49 | run: npm install 50 | - name: build 51 | run: npm run build 52 | - name: Upload artifact 53 | uses: actions/upload-pages-artifact@v1 54 | with: 55 | # Upload entire repository 56 | path: 'public' 57 | - name: Deploy to GitHub Pages 58 | id: deployment 59 | uses: actions/deploy-pages@v1 60 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Unit Tests 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4 13 | - name: Use Node.js 14 | uses: actions/setup-node@v4 15 | with: 16 | node-version: 22.4.0 17 | cache: 'npm' 18 | - run: npm ci 19 | - run: make lint 20 | - run: make test-ci 21 | env: 22 | LANG: ja_JP.UTF-8 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | cmake-build-debug 3 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 4 | 5 | # dependencies 6 | /node_modules 7 | /.pnp 8 | .pnp.js 9 | 10 | # testing 11 | /coverage 12 | 13 | # production 14 | /build 15 | 16 | /public 17 | 18 | # misc 19 | .DS_Store 20 | .env.local 21 | .env.development.local 22 | .env.test.local 23 | .env.production.local 24 | 25 | npm-debug.log* 26 | yarn-debug.log* 27 | yarn-error.log* 28 | 29 | assets/index.js 30 | 31 | build-types 32 | *.tsbuildinfo 33 | /test-results/ 34 | /playwright-report/ 35 | /blob-report/ 36 | /playwright/.cache/ 37 | -------------------------------------------------------------------------------- /.node-version: -------------------------------------------------------------------------------- 1 | 22.4.0 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | public/* 2 | src/wasm/* -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 4, 4 | "useTabs": true, 5 | "semi": true, 6 | "singleQuote": true 7 | } 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # parametaers 2 | PHP_VERSION := 8.2 3 | WITH_VRZNO := yes 4 | WITH_LIBXML := no 5 | WITH_LIBPNG := no 6 | WITH_MBSTRING := yes 7 | WITH_CLI_SAPI := no 8 | WITH_OPENSSL := no 9 | WITH_NODEFS := no 10 | WITH_CURL := no 11 | WITH_SQLITE := no 12 | WITH_MYSQL := no 13 | WITH_WS_NETWORKING_PROXY := no 14 | # web or node 15 | PLATFORM := web 16 | 17 | PHP_IMAGE := php-wasm:$(PHP_VERSION) 18 | 19 | DIST_DIR := $(PWD)/dist 20 | 21 | 22 | .PHONY: build-image build-wasm build build-all build-5.6 build-7.0 build-7.1 build-7.2 build-7.3 build-7.4 build-8.0 build-8.1 build-8.2 23 | WITH_CACHE := 24 | ifeq ($(WITH_CACHE),no) 25 | WITH_CACHE := --no-cache 26 | endif 27 | 28 | build-image: 29 | cd src/wasm && \ 30 | docker build $(WITH_CACHE) . --tag=$(PHP_IMAGE) \ 31 | --build-arg PHP_VERSION=$(PHP_VERSION) \ 32 | --build-arg WITH_VRZNO=$(WITH_VRZNO) \ 33 | --build-arg WITH_LIBXML=$(WITH_LIBXML) \ 34 | --build-arg WITH_LIBPNG=$(WITH_LIBPNG) \ 35 | --build-arg WITH_MBSTRING=$(WITH_MBSTRING) \ 36 | --build-arg WITH_CLI_SAPI=$(WITH_CLI_SAPI) \ 37 | --build-arg WITH_OPENSSL=$(WITH_OPENSSL) \ 38 | --build-arg WITH_NODEFS=$(WITH_NODEFS) \ 39 | --build-arg WITH_CURL=$(WITH_CURL) \ 40 | --build-arg WITH_SQLITE=$(WITH_SQLITE) \ 41 | --build-arg WITH_MYSQL=$(WITH_MYSQL) \ 42 | --build-arg WITH_WS_NETWORKING_PROXY=$(WITH_WS_NETWORKING_PROXY) \ 43 | --build-arg EMSCRIPTEN_ENVIRONMENT=$(PLATFORM) && \ 44 | cd - 45 | 46 | CMD_DIST := 'cp /root/output/php* /output' 47 | ifeq ($(WITH_CLI_SAPI),yes) 48 | CMD_DIST = "$(CMD_DIST) && cp /root/lib/share/terminfo/x/xterm /output/terminfo/x" 49 | endif 50 | 51 | build-wasm: build-image 52 | docker run --rm -v $(DIST_DIR):/output $(PHP_IMAGE) \ 53 | sh -c $(CMD_DIST); 54 | mv $(DIST_DIR)/php-$(PHP_VERSION).js src/wasm-assets/; 55 | mv $(DIST_DIR)/php-$(PHP_VERSION).wasm assets/; 56 | 57 | JOBS := $(call add $(shell grep cpu.cores /proc/cpuinfo | sort -u | sed 's/[^0-9]//g'), 1) 58 | ifeq ($(shell uname), Darwin) 59 | JOBS = $(shell sysctl -a machdep.cpu | grep core_count | sed 's/[^0-9]//g') 60 | endif 61 | 62 | build: 63 | $(MAKE) build-all -j$(JOBS) 64 | 65 | # too heavy 66 | build-all: build-5.6 build-7.0 build-7.1 build-7.2 build-7.3 build-7.4 build-8.0 build-8.1 build-8.2 build-8.3 build-8.4 67 | 68 | build-5.6: 69 | $(MAKE) build-wasm PHP_VERSION=5.6 70 | 71 | build-7.0: 72 | $(MAKE) build-wasm PHP_VERSION=7.0 73 | 74 | build-7.1: 75 | $(MAKE) build-wasm PHP_VERSION=7.1 76 | 77 | build-7.2: 78 | $(MAKE) build-wasm PHP_VERSION=7.2 79 | 80 | build-7.3: 81 | $(MAKE) build-wasm PHP_VERSION=7.3 82 | 83 | build-7.4: 84 | $(MAKE) build-wasm PHP_VERSION=7.4 85 | 86 | build-8.0: 87 | $(MAKE) build-wasm PHP_VERSION=8.0 88 | 89 | build-8.1: 90 | $(MAKE) build-wasm PHP_VERSION=8.1 91 | 92 | build-8.2: 93 | $(MAKE) build-wasm PHP_VERSION=8.2 94 | 95 | build-8.3: 96 | $(MAKE) build-wasm PHP_VERSION=8.3 97 | 98 | build-8.4: 99 | $(MAKE) build-wasm PHP_VERSION=8.4 100 | 101 | public/index.js: 102 | npm run build 103 | 104 | debug: build-image 105 | docker run -it --rm -v $(DIST_DIR):/output $(PHP_IMAGE) bash 106 | 107 | .PHONY: lint 108 | lint: 109 | npm run lint:js 110 | npm run build:types 111 | 112 | .PHONY: test 113 | test: 114 | npm run test 115 | 116 | .PHONY: test-cl 117 | test-ci: 118 | npm run test:ci 119 | 120 | .PHONY: style-fix 121 | style-fix: 122 | npm run lint:js:fix 123 | npm run format 124 | 125 | .PHONY: clean-image 126 | clean-image: 127 | docker image rm `docker images php-wasm -q` -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | ![playwright](https://github.com/glassmonkey/php-playground/actions/workflows/playwright.yml/badge.svg?branch=master) 2 | ![test](https://github.com/glassmonkey/php-playground/actions/workflows/test.yml/badge.svg?branch=master) 3 | 4 | # php-playground 5 | 6 | PHP Playground let you to execute basic PHP code in real time. 7 | 8 | https://php-play.dev 9 | 10 | ![demo](doc/demo.gif) 11 | 12 | # usage build 13 | build web assembly 14 | ``` 15 | make build 16 | ``` 17 | 18 | build JavaScript with watching 19 | ``` 20 | npm run dev 21 | ``` 22 | 23 | build JavaScript 24 | ``` 25 | npm run build 26 | ``` 27 | 28 | build JavaScript and preview 29 | ``` 30 | npm run preview 31 | ``` 32 | 33 | # related 34 | 35 | ## chrome extension 36 | install: [store page](https://chromewebstore.google.com/detail/run-on-php-playground/ddhmobhdfmhfckpkedkompdjdmpapeng) 37 | repository: [meihei3/run-on-php-playground](https://github.com/meihei3/run-on-php-playground) 38 | 39 | ## PHP to WebAssembly build pipeline 40 | 41 | The bulild pipeline was created by Forking [WordPress/wordpress-playground](https://github.com/WordPress/wordpress-playground). 42 | Please refer to the [original document](https://wordpresswasm.readthedocs.io/en/latest/using-php-in-javascript/) for details. 43 | 44 | # Licence 45 | 46 | Apache License 2.0 47 | -------------------------------------------------------------------------------- /assets/favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /assets/octocat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/octocat.png -------------------------------------------------------------------------------- /assets/ogp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/ogp.png -------------------------------------------------------------------------------- /assets/php-5.6.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-5.6.wasm -------------------------------------------------------------------------------- /assets/php-7.0.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-7.0.wasm -------------------------------------------------------------------------------- /assets/php-7.1.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-7.1.wasm -------------------------------------------------------------------------------- /assets/php-7.2.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-7.2.wasm -------------------------------------------------------------------------------- /assets/php-7.3.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-7.3.wasm -------------------------------------------------------------------------------- /assets/php-7.4.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-7.4.wasm -------------------------------------------------------------------------------- /assets/php-8.0.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-8.0.wasm -------------------------------------------------------------------------------- /assets/php-8.1.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-8.1.wasm -------------------------------------------------------------------------------- /assets/php-8.2.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-8.2.wasm -------------------------------------------------------------------------------- /assets/php-8.3.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-8.3.wasm -------------------------------------------------------------------------------- /assets/php-8.4.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-8.4.wasm -------------------------------------------------------------------------------- /assets/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | https://php-play.dev/ 5 | 6 | -------------------------------------------------------------------------------- /build.mjs: -------------------------------------------------------------------------------- 1 | import * as esbuild from 'esbuild' 2 | 3 | let options = { 4 | entryPoints: ['src/index.tsx'], 5 | bundle: true, 6 | outdir: 'public', 7 | tsconfig: "./tsconfig.json" 8 | } 9 | 10 | const context = await esbuild.context(options) 11 | const result = await context.rebuild() 12 | console.log(result) 13 | 14 | if (process.env.WATCH !== "true") { 15 | context.dispose(); 16 | 17 | } else{ 18 | console.log("begin: watch") 19 | await context.watch() 20 | } 21 | -------------------------------------------------------------------------------- /doc/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/doc/demo.gif -------------------------------------------------------------------------------- /e2e/e2e.spec.ts: -------------------------------------------------------------------------------- 1 | import {expect, test} from '@playwright/test'; 2 | import {versions} from "../src/php-wasm/php"; 3 | 4 | const PAGE = 'http://127.0.0.1:18888'; 5 | test.describe('default page', () => { 6 | test.beforeEach(async ({page}) => { 7 | await page.goto(PAGE); 8 | }) 9 | test('has title', async ({ page }) => { 10 | await expect(page).toHaveTitle('PHP Playground'); 11 | }); 12 | test('default version is 8.4', async ({ page }) => { 13 | await expect(page.getByText('8.4')).toBeVisible() 14 | }) 15 | test('default code is `phpinfo()`', async ({ page }) => { 16 | await expect(page.getByRole('code')).toContainText('phpinfo();') 17 | }) 18 | 19 | test('default URL', async ({ page }) => { 20 | const defaultPage = `${PAGE}/?c=DwfgDgFmBQD0sAICmAPAhgWzAGyQgxgPYAmS0kYAlgHYBmhAFAJQDcQA&v=8.4&f=html` 21 | await page.waitForURL(defaultPage) 22 | expect(page.url()).toContain(defaultPage) 23 | }) 24 | 25 | test('switch preview', async ({ page }) => { 26 | // html preview 27 | await page.getByTestId('checkbox-format').check() 28 | await expect(await page.getByTestId('preview-html').getAttribute('srcdoc')).toContain('PHP Version 8.4') 29 | await expect(await page.getByTestId('preview-console')).not.toBeVisible() 30 | 31 | // console pvreview 32 | await page.getByTestId('checkbox-format').uncheck() 33 | await expect(await page.getByTestId('preview-console')).toContainText('PHP Version 8.4') 34 | await expect(await page.getByTestId('preview-html')).not.toBeVisible() 35 | }) 36 | }) 37 | 38 | test.describe('select version', () => { 39 | // ref: https://github.com/microsoft/playwright/issues/7036 40 | versions.forEach((v) => { 41 | test.describe(`select version v=${v}`, () => { 42 | test.beforeEach(async ({page}) => { 43 | await page.goto(PAGE); 44 | }) 45 | test(`running php info`, async ({page}) => { 46 | const input = page.locator('#select-input-php') 47 | await input.fill(v) 48 | await page.keyboard.down("Tab"); 49 | 50 | // html preview 51 | await page.getByTestId('checkbox-format').check() 52 | await expect(await page.getByTestId('preview-html').getAttribute('srcdoc')).toContain(`PHP Version ${v}`) 53 | expect(page.url()).toContain(`v=${v}`) 54 | }) 55 | test(`compute php code(1+1)`, async ({page}) => { 56 | await page.goto(`${PAGE}/?c=DwfgUEA`); 57 | // select version 58 | const input = page.locator('#select-input-php') 59 | await input.fill(v) 60 | await page.keyboard.down("Tab"); 61 | 62 | const editor = page.getByRole('code') 63 | // focus editor 64 | await editor.click() 65 | // display code in editor 66 | await expect(page.getByRole('presentation')).toHaveText(' { 77 | if (v < '7.0') { 78 | console.log("strict_types is not supported") 79 | return 80 | } 81 | await page.goto(`${PAGE}/?c=DwfgUEA`); 82 | // select version 83 | const input = page.locator('#select-input-php') 84 | await input.fill(v) 85 | await page.keyboard.down("Tab"); 86 | 87 | const editor = page.getByRole('code') 88 | // focus editor 89 | await editor.click() 90 | // display code in editor 91 | await expect(page.getByRole('presentation')).toHaveText(' { 101 | await page.goto(`${PAGE}/?c=DwQgtBYHxA`); 102 | // select version 103 | const input = page.locator('#select-input-php') 104 | await input.fill(v) 105 | await page.keyboard.down("Tab"); 106 | 107 | const editor = page.getByRole('code') 108 | // focus editor 109 | await editor.click() 110 | // display code in editor 111 | await expect(page.getByRole('presentation')).toHaveText('') 112 | // try 1+1 113 | await page.keyboard.type('Hello, World') 114 | // display code in editor 115 | await expect(page.getByRole('presentation')).toHaveText('Hello, World') 116 | // run and result is 2 117 | await page.getByTestId('checkbox-format').uncheck() 118 | await expect(await page.getByTestId('preview-console')).toHaveText('Hello, World') 119 | }) 120 | test(`include compute text`, async ({page}) => { 121 | await page.goto(`${PAGE}/?c=DwQgtBYHxA`); // 122 | // select version 123 | const input = page.locator('#select-input-php') 124 | await input.fill(v) 125 | await page.keyboard.down("Tab"); 126 | 127 | const editor = page.getByRole('code') 128 | // focus editor 129 | await editor.click() 130 | // display code in editor 131 | await expect(page.getByRole('presentation')).toHaveText('') 132 | // try 1+1 133 | await page.keyboard.type('') 134 | // display code in editor 135 | await expect(page.getByRole('presentation')).toHaveText('') 136 | // run and result is 2 137 | await page.getByTestId('checkbox-format').uncheck() 138 | await expect(await page.getByTestId('preview-console')).toHaveText('xyz') 139 | }) 140 | }) 141 | }) 142 | }) 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | PHP Playground 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 31 | 32 | 33 |
34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "php-playground", 3 | "version": "0.1.0", 4 | "engines": { 5 | "node": "22.4.0" 6 | }, 7 | "type": "module", 8 | "private": true, 9 | "dependencies": { 10 | "@chakra-ui/icons": "2.1.0", 11 | "@chakra-ui/react": "2.8.0", 12 | "@codemirror/language": "6.11.0", 13 | "@codesandbox/sandpack-react": "2.19.9", 14 | "@emotion/react": "11.13.3", 15 | "@emotion/styled": "11.13.0", 16 | "@monaco-editor/react": "4.6.0", 17 | "@testing-library/jest-dom": "6.5.0", 18 | "@testing-library/user-event": "14.5.2", 19 | "@types/jest": "29.5.14", 20 | "@types/lz-string": "1.5.0", 21 | "@types/node": "20.12.8", 22 | "@types/react": "18.3.3", 23 | "@types/react-dom": "18.3.1", 24 | "debounce": "2.0.0", 25 | "framer-motion": "11.5.4", 26 | "lz-string": "1.5.0", 27 | "npm-run-all": "4.1.5", 28 | "prettier": "3.5.3", 29 | "react": "18.3.1", 30 | "react-dom": "18.3.1", 31 | "react-icons": "5.0.1", 32 | "react-router-dom": "6.26.2", 33 | "react-select": "5.9.0", 34 | "typescript": "5.6.2", 35 | "web-vitals": "4.2.4" 36 | }, 37 | "scripts": { 38 | "dev": "vite", 39 | "build": "vite build", 40 | "preview": "vite build && vite preview --port 8888", 41 | "build:types": "npm run clean:types; npm-run-all --parallel build:types:*", 42 | "build:types:general": "tsc -p ./tsconfig.json", 43 | "clean": "npm-run-all --parallel clean:*", 44 | "clean:all": "rm -rf build/* ./build-*/*", 45 | "clean:types": "rm -rf build-types/* *.tsbuildinfo", 46 | "format": "prettier --write src", 47 | "lint:js": "eslint \"./src/**/*.{js,mjs,ts}\"", 48 | "lint:js:fix": "npm run lint:js -- --fix", 49 | "test": "vitest", 50 | "test:ci": "vitest run", 51 | "test:e2e": "playwright test", 52 | "test:e2e:report": "playwright show-report" 53 | }, 54 | "eslintConfig": { 55 | "extends": [ 56 | "react-app", 57 | "react-app/jest" 58 | ] 59 | }, 60 | "browserslist": { 61 | "production": [ 62 | ">0.2%", 63 | "not dead", 64 | "not op_mini all" 65 | ], 66 | "development": [ 67 | "last 1 chrome version", 68 | "last 1 firefox version", 69 | "last 1 safari version" 70 | ] 71 | }, 72 | "devDependencies": { 73 | "@playwright/test": "1.51.1", 74 | "@testing-library/react": "16.0.1", 75 | "@types/debounce": "1.2.4", 76 | "@typescript-eslint/eslint-plugin": "7.16.0", 77 | "@vitejs/plugin-react": "4.3.4", 78 | "esbuild": "0.25.1", 79 | "eslint": "8.57.0", 80 | "eslint-plugin-react": "7.35.0", 81 | "jsdom": "^25.0.1", 82 | "node-fetch": "3.3.2", 83 | "vi-fetch": "0.8.0", 84 | "vite": "6.3.3", 85 | "vitest": "3.0.9" 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /playwright.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig, devices } from '@playwright/test'; 2 | 3 | const projects = [ 4 | { 5 | name: 'chromium', 6 | use: { ...devices['Desktop Chrome'] }, 7 | }, 8 | ] 9 | if (process.env.CI) { 10 | projects.push({ 11 | name: 'firefox', 12 | use: { ...devices['Desktop Firefox'] }, 13 | }) 14 | projects.push({ 15 | name: 'webkit', 16 | use: { ...devices['Desktop Safari'] }, 17 | }) 18 | } 19 | 20 | 21 | /** 22 | * Read environment variables from file. 23 | * https://github.com/motdotla/dotenv 24 | */ 25 | // import dotenv from 'dotenv'; 26 | // dotenv.config({ path: path.resolve(__dirname, '.env') }); 27 | 28 | /** 29 | * See https://playwright.dev/docs/test-configuration. 30 | */ 31 | export default defineConfig({ 32 | testDir: './e2e', 33 | /* Run tests in files in parallel */ 34 | fullyParallel: true, 35 | /* Fail the build on CI if you accidentally left test.only in the source code. */ 36 | forbidOnly: !!process.env.CI, 37 | /* Retry on CI only */ 38 | retries: 2, 39 | /* Opt out of parallel tests on CI. */ 40 | workers: 4, 41 | /* Reporter to use. See https://playwright.dev/docs/test-reporters */ 42 | reporter: 'html', 43 | /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ 44 | use: { 45 | /* Base URL to use in actions like `await page.goto('/')`. */ 46 | // baseURL: 'http://127.0.0.1:3000', 47 | 48 | /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ 49 | trace: 'on-first-retry', 50 | }, 51 | timeout: 5 * 60 * 1000, 52 | expect: { 53 | timeout: 1000 * 10, 54 | }, 55 | 56 | /* Configure projects for major browsers */ 57 | projects: projects, 58 | 59 | /* Test against mobile viewports. */ 60 | // { 61 | // name: 'Mobile Chrome', 62 | // use: { ...devices['Pixel 5'] }, 63 | // }, 64 | // { 65 | // name: 'Mobile Safari', 66 | // use: { ...devices['iPhone 12'] }, 67 | // }, 68 | 69 | /* Test against branded browsers. */ 70 | // { 71 | // name: 'Microsoft Edge', 72 | // use: { ...devices['Desktop Edge'], channel: 'msedge' }, 73 | // }, 74 | // { 75 | // name: 'Google Chrome', 76 | // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, 77 | // }, 78 | 79 | /* Run your local dev server before starting the tests */ 80 | webServer: { 81 | command: 'npm run dev', 82 | url: 'http://127.0.0.1:18888', 83 | reuseExistingServer: !process.env.CI, 84 | timeout: 1000 * 60, 85 | stdout: 'pipe', 86 | stderr: 'pipe', 87 | }, 88 | }); 89 | -------------------------------------------------------------------------------- /src/__test__/php.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect, it } from 'vitest'; 2 | import { usePHP } from '../php'; 3 | // @ts-ignore 4 | import { mockFetch } from 'vi-fetch'; 5 | // @ts-ignore 6 | import 'vi-fetch/setup'; 7 | import * as fs from 'fs'; 8 | import { renderHook } from '@testing-library/react'; 9 | 10 | mockFetch.setOptions({ 11 | baseUrl: '', 12 | }); 13 | it.skip('should increment counter', async () => { 14 | const v = '8.3'; 15 | const code = ' usePHP(v, code)); 23 | const [loading, value] = result.current; 24 | expect(loading).toBe(true); 25 | expect(value).toBe(''); 26 | }); 27 | -------------------------------------------------------------------------------- /src/__test__/php.test.ts: -------------------------------------------------------------------------------- 1 | import { expect, it, describe } from 'vitest'; 2 | import {convertCodeToPhpPlayground, initPHP, runPHP} from '../php'; 3 | // @ts-ignore 4 | import { mockFetch } from 'vi-fetch'; 5 | // @ts-ignore 6 | import 'vi-fetch/setup'; 7 | import * as fs from 'fs'; 8 | import { versions } from '../php-wasm/php'; 9 | 10 | mockFetch.setOptions({ 11 | baseUrl: '', 12 | }); 13 | 14 | describe('load wasm files', async function () { 15 | versions.forEach(function (v) { 16 | it(`version: ${v} should echo 1.`, async function () { 17 | const data = fs.readFileSync(`assets/php-${v}.wasm`); 18 | const pattern = `php-${v}.wasm?.+`; 19 | mockFetch('GET', new RegExp(pattern)).willResolve(data.buffer); 20 | // Runtime error occurs, but you can ignore it because it is a problem with the way wasm is loaded. 21 | const sut = await initPHP(v); 22 | expect(sut.version).toBe(v); 23 | const actual = await runPHP(sut, 'echo(1);'); 24 | expect(actual).toBe('1'); 25 | }); 26 | }); 27 | }); 28 | 29 | describe('show phpinfo()', async function () { 30 | versions.forEach(function (v) { 31 | it(`version: ${v} run phpinfo().`, async function () { 32 | const data = fs.readFileSync(`assets/php-${v}.wasm`); 33 | const pattern = `php-${v}.wasm?.+`; 34 | mockFetch('GET', new RegExp(pattern)).willResolve(data.buffer); 35 | // Runtime error occurs, but you can ignore it because it is a problem with the way wasm is loaded. 36 | const sut = await initPHP(v); 37 | expect(sut.version).toBe(v); 38 | let actual = await runPHP(sut, 'phpinfo();'); 39 | // Shrink the request time 40 | actual = actual.replace( 41 | /(.+?REQUEST_TIME_FLOAT.+?)([\d.]+)(<\/td><\/tr>)/g, 42 | '$1--$3' 43 | ); 44 | actual = actual.replace( 45 | /(.+?REQUEST_TIME.+?)([\d.]+)(<\/td><\/tr>)/g, 46 | '$1--$3' 47 | ); 48 | expect(actual).toMatchSnapshot(); 49 | }); 50 | }); 51 | }); 52 | 53 | describe('convert code to php code for wasm', async function () { 54 | 55 | const testCases = [ 56 | {"input": "Hello, World"}, 61 | {"input": "", "expected": "?>"}, 62 | {"input": "", "expected": "?>"}, 64 | ] 65 | 66 | it.each(testCases)('input: %s to %s', async function (testCase) { 67 | const actual = convertCodeToPhpPlayground(testCase.input); 68 | expect(actual).toBe(testCase.expected); 69 | }) 70 | }) 71 | -------------------------------------------------------------------------------- /src/app.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { useEffect } from 'react'; 3 | import { 4 | Flex, 5 | Box, 6 | Spacer, 7 | Text, 8 | Link, 9 | Center, 10 | Button, 11 | Switch, 12 | useColorMode, 13 | } from '@chakra-ui/react'; 14 | import { useSearchParams } from 'react-router-dom'; 15 | import * as lzstring from 'lz-string'; 16 | 17 | import { Version, asVersion } from './php-wasm/php'; 18 | import SelectPHP from './select'; 19 | import { Editor } from './editor'; 20 | import { BellIcon } from '@chakra-ui/icons'; 21 | import { Format, SelectFormat } from './format'; 22 | 23 | type UrlState = { 24 | v: Version; 25 | c: string; 26 | f: Format; 27 | }; 28 | 29 | export default function App() { 30 | const [searchParams, setSearchParams] = useSearchParams(); 31 | const initCode = 32 | lzstring.decompressFromEncodedURIComponent( 33 | searchParams.get('c') ?? '' 34 | ) ?? ' 98 | 99 | 100 | 104 | 105 | 114 | 121 | < Request and Report 122 | 123 | 124 | 125 | 126 | 127 | 128 |
129 | 137 |
138 | 146 | 150 | 151 | UI Theme: 152 | 160 | 161 | 165 |
166 |
167 | 175 | 176 | ); 177 | } 178 | -------------------------------------------------------------------------------- /src/editor.tsx: -------------------------------------------------------------------------------- 1 | import type { Version } from './php-wasm/php'; 2 | import { 3 | SandpackLayout, 4 | SandpackProvider, 5 | useActiveCode, 6 | useSandpack, 7 | } from '@codesandbox/sandpack-react'; 8 | import { usePHP } from './php'; 9 | import { Box, Center, Flex, Spinner, useColorMode } from '@chakra-ui/react'; 10 | import type { ReactElement } from 'react'; 11 | import * as React from 'react'; 12 | import MonacoEditor, { type OnChange } from '@monaco-editor/react'; 13 | import { Format } from './format'; 14 | import debounce from 'debounce'; 15 | 16 | function LoadSpinner() { 17 | return ( 18 |
19 | 20 |
21 | ); 22 | } 23 | 24 | function PhpEditor() { 25 | const { code, updateCode } = useActiveCode(); 26 | const { sandpack } = useSandpack(); 27 | const { colorMode } = useColorMode(); 28 | 29 | const onChangeCode: OnChange = debounce((value) => { 30 | updateCode(value || ''); 31 | }, 300); 32 | 33 | return ( 34 | } 43 | options={{ 44 | minimap: { 45 | enabled: false, 46 | }, 47 | }} 48 | /> 49 | ); 50 | } 51 | 52 | function PhpPreview(params: { version: Version; format: Format }) { 53 | const { sandpack } = useSandpack(); 54 | const { files, activeFile } = sandpack; 55 | const code = files[activeFile].code; 56 | const [loading, result] = usePHP(params.version, code); 57 | 58 | if (loading) { 59 | return ; 60 | } 61 | if (params.format === 'console') { 62 | return ( 63 |
 72 | 				{result}
 73 | 			
74 | ); 75 | } 76 | 77 | return ( 78 |