npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

uniter

v2.18.0

Published

Uniter - PHP in the browser and Node.js

Downloads

258

Readme

Uniter PHP

Build Status Join the chat at https://gitter.im/asmblah/uniter

Run PHP client-side in the browser or in Node.js.

Manipulating the DOM using PHP with Uniter

Try it now

Demos

Packages

Uniter is split into several NPM packages, each with a separate repository:

| Package | Version | Dependencies | |--------|-------|------------| | uniter | npm | Dependency Status | | phptoast | npm | Dependency Status | | phptojs | npm | Dependency Status | | phpcore | npm | Dependency Status | | phpruntime | npm | Dependency Status | | phpcommon | npm | Dependency Status | | phpify | npm | Dependency Status | | dotphp | npm | Dependency Status |

uniter is the main Uniter library (this repository). It pulls in all the required components (below) to take a string of PHP code, evaluate it and return the result with a simple API.

phptoast is the parser for Uniter. It takes PHP code as a string and returns an AST comprised of plain JavaScript objects.

phptojs is the transpiler. It takes an AST (such as the one returned by phptoast) and translates it into JavaScript that can then be executed.

phpcore is the minimal runtime library required for code transpiled by phptojs to execute. It contains some builtin PHP classes and functions, but only those that are required (eg. the Closure class or spl_autoload_register(...) function).

phpruntime is the extended "full" runtime library. After pulling in phpcore, it installs the remaining builtin classes and functions, such as array_merge(...). Only a small subset of PHP's standard library has been implemented so far - please open a GitHub issue in the phpruntime repository if you would like to request something that is missing.

phpcommon contains various tools that are shared between the different packages, such as the PHPFatalError class used by both the parser (phptoast) and runtime (phpcore).

phpify is a Browserify transform that can be used to require PHP modules (and entire libraries) from JavaScript. For an example of compiling a PHP library down to JavaScript, see the Uniter Symfony EventDispatcher demo.

dotphp allows for easily including PHP files from Node.js. A require(...) extension may be installed by using the /register script or PHP files may simply be required with the exported .require(...) method. Stderr and stdout are mapped to the process' stderr and stdout respectively, and the filesystem/ include/require/_once(...) access is mapped to the real filesystem.

Getting started

$ npm install uniter
$ node
> var php = require('uniter').createEngine('PHP');
> php.getStdout().on('data', function (text) { console.log(text); });
> php.execute('<?php print "Hello from PHP!";');
Hello from PHP!

Features

  • Environment-agnostic architecture: should run in any modern browser (IE < 9 support coming soon) and Node.js

  • PHP statements, constructs and operators:

    • if, else and else if statements
    • while loop support
    • for loop support
    • foreach loop support
    • function statements with type hinting (as syntactic sugar only: no enforcement is performed yet)
    • Closure function expressions
    • switch statements
    • Forward and backward goto statements (but no overlap support yet)
    • class object support (new operator, extends support etc.)
    • Instance property/method access (-> operator)
    • Static class property/method access (:: operator), self:: construct
    • use statement for class, namespace and function importing and aliasing
    • Magic __autoload(...) function
    • Magic __DIR__, __FILE__ and __LINE__ constants
    • Ternary operator
    • Loose equality == and inequality != comparison operators
    • Strict equality === and inequality !== comparison operators

    And others... see the Engine integration tests for more info.

Using on the command line

You can use Uniter from the command line after installing it via NPM, eg.:

# Install Uniter globally
$ npm install -g uniter

# Execute PHP code
$ uniter -r 'echo 7 + 2;'
9

# Parse PHP but just dump the AST as JSON, don't attempt to execute
$ uniter -r 'echo 7 + 2;' --dump-ast
{
    "statements": [
        {
            "expression": {
                "left": {
                    "number": "7",
                    "name": "N_INTEGER"
                },
                "right": [
                    {
                        "operator": "+",
                        "operand": {
                            "number": "2",
                            "name": "N_INTEGER"
                        }
                    }
                ],
                "name": "N_EXPRESSION"
            },
            "name": "N_ECHO_STATEMENT"
        }
    ],
    "name": "N_PROGRAM"
}

Keeping up to date

Running the tests

There are two supported ways of running the Mocha test suite:

  1. Run the tests in Node.js from the command line:

     cd uniter/
     npm test
  2. Run the tests in a browser by starting a Node.js server:

     npm run-script webtest

    You should then be able to run the tests by visiting http://127.0.0.1:6700 in a supported web browser.

License

MIT

Contributors

Pharaoh Tools