{"id":17513288,"url":"https://github.com/asmblah/uniter","last_synced_at":"2025-04-12T22:28:55.947Z","repository":{"id":9867664,"uuid":"11866527","full_name":"asmblah/uniter","owner":"asmblah","description":"🎉 PHP in the browser and Node.js =\u003e Docs: https://phptojs.com/","archived":false,"fork":false,"pushed_at":"2023-09-19T06:14:51.000Z","size":6621,"stargazers_count":449,"open_issues_count":24,"forks_count":42,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-04T02:07:46.348Z","etag":null,"topics":["javascript","php","transpiler"],"latest_commit_sha":null,"homepage":"https://asmblah.github.io/uniter/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/asmblah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-08-03T17:07:13.000Z","updated_at":"2025-02-27T18:55:36.000Z","dependencies_parsed_at":"2024-06-18T18:40:27.631Z","dependency_job_id":"4cb8fe38-3ce8-4d2a-bd9e-57e9ac769378","html_url":"https://github.com/asmblah/uniter","commit_stats":{"total_commits":750,"total_committers":3,"mean_commits":250.0,"dds":"0.0040000000000000036","last_synced_commit":"304fa1108393f4238fa4fb09c5cfad30a7690493"},"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asmblah%2Funiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asmblah%2Funiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asmblah%2Funiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asmblah%2Funiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asmblah","download_url":"https://codeload.github.com/asmblah/uniter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248639320,"owners_count":21137824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","php","transpiler"],"created_at":"2024-10-20T06:08:26.595Z","updated_at":"2025-04-12T22:28:55.920Z","avatar_url":"https://github.com/asmblah.png","language":"JavaScript","readme":"![Uniter PHP](https://asmblah.github.io/uniter/img/logo.jpg)\n======\n\n[![Build Status](https://github.com/asmblah/uniter/workflows/CI/badge.svg)](https://github.com/asmblah/uniter/actions?query=workflow%3ACI) [![Join the chat at https://gitter.im/asmblah/uniter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/asmblah/uniter?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nRun PHP client-side in the browser or in Node.js.\n\n[\n![Manipulating the DOM using PHP with Uniter](https://asmblah.github.io/uniter/img/uniter_dom_demo.gif)\n](https://asmblah.github.io/uniter/demo/interactive.html)\n\n[Try it now](https://asmblah.github.io/uniter/demo/interactive.html)\n\nDemos\n-----\n- [jQuery + PHP + Browserify (with PHPUnit)](https://uniter.github.io/uniter-jquery)\n- [Interactive demo (above)](https://asmblah.github.io/uniter/demo/interactive.html)\n- [Simple REPL](https://codepen.io/jcubic/pen/VGYBVj?editors=0010)\n\nPackages\n--------\nUniter is split into several NPM packages, each with a separate repository:\n\n| Package | Version | Dependencies |\n|--------|-------|------------|\n| [`uniter`](https://github.com/asmblah/uniter) | [![npm](https://img.shields.io/npm/v/uniter.svg?maxAge=2592000)](https://www.npmjs.com/package/uniter) | [![Dependency Status](https://david-dm.org/asmblah/uniter.svg)](https://david-dm.org/asmblah/uniter) |\n| [`phptoast`](https://github.com/uniter/phptoast) | [![npm](https://img.shields.io/npm/v/phptoast.svg?maxAge=2592000)](https://www.npmjs.com/package/phptoast) | [![Dependency Status](https://david-dm.org/uniter/phptoast.svg)](https://david-dm.org/uniter/phptoast) |\n| [`phptojs`](https://github.com/uniter/phptojs) | [![npm](https://img.shields.io/npm/v/phptojs.svg?maxAge=2592000)](https://www.npmjs.com/package/phptojs) | [![Dependency Status](https://david-dm.org/uniter/phptojs.svg)](https://david-dm.org/uniter/phptojs) |\n| [`phpcore`](https://github.com/uniter/phpcore) | [![npm](https://img.shields.io/npm/v/phpcore.svg?maxAge=2592000)](https://www.npmjs.com/package/phpcore) | [![Dependency Status](https://david-dm.org/uniter/phpcore.svg)](https://david-dm.org/uniter/phpcore) |\n| [`phpruntime`](https://github.com/uniter/phpruntime) | [![npm](https://img.shields.io/npm/v/phpruntime.svg?maxAge=2592000)](https://www.npmjs.com/package/phpruntime) | [![Dependency Status](https://david-dm.org/uniter/phpruntime.svg)](https://david-dm.org/uniter/phpruntime) |\n| [`phpcommon`](https://github.com/uniter/phpcommon) | [![npm](https://img.shields.io/npm/v/phpcommon.svg?maxAge=2592000)](https://www.npmjs.com/package/phpcommon) | [![Dependency Status](https://david-dm.org/uniter/phpcommon.svg)](https://david-dm.org/uniter/phpcommon) |\n| [`phpify`](https://github.com/uniter/phpify) | [![npm](https://img.shields.io/npm/v/phpify.svg?maxAge=2592000)](https://www.npmjs.com/package/phpify) | [![Dependency Status](https://david-dm.org/uniter/phpify.svg)](https://david-dm.org/uniter/phpify) |\n| [`dotphp`](https://github.com/uniter/dotphp) | [![npm](https://img.shields.io/npm/v/dotphp.svg?maxAge=2592000)](https://www.npmjs.com/package/dotphp) | [![Dependency Status](https://david-dm.org/uniter/dotphp.svg)](https://david-dm.org/uniter/dotphp) |\n\n[`uniter`](https://github.com/asmblah/uniter) is the main Uniter library (this repository).\nIt pulls in all the required components (below) to take a string of PHP code, evaluate it and return the result\nwith a simple API.\n\n[`phptoast`](https://github.com/uniter/phptoast) is the parser for Uniter. It takes PHP code as a string\nand returns an AST comprised of plain JavaScript objects.\n\n[`phptojs`](https://github.com/uniter/phptojs) is the transpiler. It takes an AST (such as the one returned by `phptoast`)\nand translates it into JavaScript\nthat can then be executed.\n\n[`phpcore`](https://github.com/uniter/phpcore) is the minimal runtime library required for code transpiled by `phptojs` to execute.\nIt contains some builtin PHP classes and functions, but only those that are required\n(eg. the `Closure` class or `spl_autoload_register(...)` function).\n\n[`phpruntime`](https://github.com/uniter/phpruntime) is the extended \"full\" runtime library.\nAfter pulling in `phpcore`, it installs the remaining builtin classes and functions, such as `array_merge(...)`.\nOnly a small subset of PHP's standard library has been implemented so far - please open a GitHub issue\nin the `phpruntime` repository if you would like to request something that is missing.\n\n[`phpcommon`](https://github.com/uniter/phpcommon) contains various tools that are shared between the different\npackages, such as the `PHPFatalError` class used by both the parser (`phptoast`) and runtime (`phpcore`).\n\n[`phpify`](https://github.com/uniter/phpify) is a Browserify transform that can be used to require PHP modules\n(and entire libraries) from JavaScript.\nFor an example of compiling a PHP library down to JavaScript,\nsee the [Uniter Symfony EventDispatcher demo](https://github.com/uniter/event-dispatcher-demo).\n\n[`dotphp`](https://github.com/uniter/dotphp) allows for easily including PHP files from Node.js.\nA `require(...)` extension may be installed by using the `/register` script or PHP files may simply be required\nwith the exported `.require(...)` method. Stderr and stdout are mapped to the process' stderr and stdout respectively,\nand the filesystem/ `include/require/_once(...)` access is mapped to the real filesystem.\n\nGetting started\n---------------\n```shell\n$ npm install uniter\n$ node\n```\n```javascript\n\u003e var php = require('uniter').createEngine('PHP');\n\u003e php.getStdout().on('data', function (text) { console.log(text); });\n\u003e php.execute('\u003c?php print \"Hello from PHP!\";');\nHello from PHP!\n```\n\nFeatures\n--------\n- Environment-agnostic architecture: should run in any modern browser (IE \u003c 9 support coming soon) and Node.js\n\n- PHP statements, constructs and operators:\n    - `if`, `else` and `else if` statements\n    - `while` loop support\n    - `for` loop support\n    - `foreach` loop support\n    - `function` statements with type hinting (as syntactic sugar only: no enforcement is performed yet)\n    - Closure `function` expressions\n    - `switch` statements\n    - Forward and backward `goto` statements (but no overlap support yet)\n    - `class` object support (`new` operator, `extends` support etc.)\n    - Instance property/method access (`-\u003e` operator)\n    - Static class property/method access (`::` operator), `self::` construct\n    - `use` statement for `class`, `namespace` and `function` importing and aliasing\n    - Magic `__autoload(...)` function\n    - Magic `__DIR__`, `__FILE__` and `__LINE__` constants\n    - Ternary operator\n    - Loose equality `==` and inequality `!=` comparison operators\n    - Strict equality `===` and inequality `!==` comparison operators\n\n    And others... see [the `Engine` integration tests](https://github.com/asmblah/uniter/tree/master/tests/bdd/integration/languages/PHP/engine) for more info.\n\nUsing on the command line\n-------------------------\nYou can use Uniter from the command line after installing it via NPM, eg.:\n\n```sh\n# Install Uniter globally\n$ npm install -g uniter\n\n# Execute PHP code\n$ uniter -r 'echo 7 + 2;'\n9\n\n# Parse PHP but just dump the AST as JSON, don't attempt to execute\n$ uniter -r 'echo 7 + 2;' --dump-ast\n{\n    \"statements\": [\n        {\n            \"expression\": {\n                \"left\": {\n                    \"number\": \"7\",\n                    \"name\": \"N_INTEGER\"\n                },\n                \"right\": [\n                    {\n                        \"operator\": \"+\",\n                        \"operand\": {\n                            \"number\": \"2\",\n                            \"name\": \"N_INTEGER\"\n                        }\n                    }\n                ],\n                \"name\": \"N_EXPRESSION\"\n            },\n            \"name\": \"N_ECHO_STATEMENT\"\n        }\n    ],\n    \"name\": \"N_PROGRAM\"\n}\n```\n\nKeeping up to date\n------------------\n- [Follow me on Twitter](https://twitter.com/@asmblah) for updates: [https://twitter.com/@asmblah](https://twitter.com/@asmblah)\n\nRunning the tests\n-----------------\n\nThere are two supported ways of running the Mocha test suite:\n\n1. Run the tests in Node.js from the command line:\n\n        cd uniter/\n        npm test\n\n2. Run the tests in a browser by starting a Node.js server:\n\n        npm run-script webtest\n\n   You should then be able to run the tests by visiting http://127.0.0.1:6700 in a supported web browser.\n\nLicense\n-------\n[MIT](/MIT-LICENSE.txt)\n\nContributors\n-------\n[Pharaoh Tools](https://github.com/PharaohTools)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasmblah%2Funiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasmblah%2Funiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasmblah%2Funiter/lists"}