Giter Club home page Giter Club logo

Glayzzle - PHP to JS transpiler

This is a CLI library in order to run a PHP script using the NodeJS V8 engine.

npm version Gitter

Why (disclaimer) ?

I've been a PHP developper for years and now I'm mainly using JavaScript. I will debate about NodeJS versus PHP, because they come with different advantages, and honestly I like both for different reasons.

The main motivation behind this project is to empower a PHP developper to be able to do the same things you could do with NodeJS or Javascript.

You are maybe thinking, if a developper wants to do the same thing as a nodejs application can do, why not learn and use directly NodeJS ? Well, here are some personal reasons :

  • Learning curve (not a big one, everybody knows JS /@YDKJS) with a new framework/libraries/etc...
  • Grasp Prototypal principles, scopes
  • Habits & losing landmarks (coding style, core functions)
  • Losing typehinting habits, or dislike Duck Typing
  • Losing SOLID principles / patterns
  • ... and maybe others, let's chat if you want to share your experience

You are JS purist and Glayzzle hurts your eyes !

This project is not made for someone who masters JS and doesn't like PHP. It's just a matter of taste, some guys prefer SOLID vs Duck typing, and may prefer to use a friendly syntax for years instead of learning a new syntax like Typescript.

I do not say it's the best overall solution, you may choose depending on what suits you best.

What can you do with it ?

The project is still under developpement, so you can't use it yet 😄.

Seriously, I plan to :

  • Handle all PHP structures (namespace, classes, traits, interfaces)
  • Impl a PHP core specific layer (in order to support main PHP functions)
  • Impl a new syntax keyword in order to natively support any Javascript library
  • Impl a native debug support with sourcemaps
  • Impl plugins for gulp/grunt/babel in order to export code for browser
  • Add a support for apache cordova
  • Add a support for electron

Things you can do :

  • Write a mobile application
  • Write a GUI application
  • All the cool stuff you can do in NodeJS
  • Write an application for the browser
  • Use frameworks like Vue.JS, SailsJS or Express/Koa

Things you can't do :

  • Run an old application (PHP modules like PDO or lib_mysql will not be available)
  • Use a dynamic variable name lookup like $$var, I'm not sure I want to degrade overall performance in order to be able to do that
  • Maybe others, work is still in progress

For JS guys who scream : Don't block the loop !

PHP is synchronous, however some implementations with libevent/promises were done as experiments - like react php (BTW the Hello world demo is almost the same as NodeJS 😉)

The main problem here is how to run a synchronous code without blocking the loop.

My answer to this is : let I/O tasks run asynchrously, and execute the next statement when the task result is ready.

Now how to do this without breaking the structure flow, and without degrading performances ?

I still need a POC, but I think I will use generators and promises in order to achieve this, the resulting transpiled code will be easy to read and will perform well with a native support.

Install & Run :

npm install -g glayzzle
glz -r "echo 'hello world';"

To run a PHP file you can use the same parameter as PHP :

glz -f your-file.php
// or
glz your-file.php

You can also run a script as a server (using NodeJS cluster module)

glz -S 127.0.0.1:8080 index.php

Other planed things :

  • Add a standalone FCGI support in order to run it with Apache/Ngnix
  • Add a generic daemon FCGI server (something similar to php-fcgi)

Project Status :

Actually the project is a Prof Of Concept, and does not run over all PHP syntax.

Here's my todo list :

If you want to contribute, fell free to make a pull request or discuss on the chat

glayzzle's Projects

ast2xml icon ast2xml

Generates xml output from AST nodes

beautify icon beautify

Parses and rewrites your HTML/CSS/JS/PHP to be beautiful and readable

code-sniper icon code-sniper

:cyclone: A clone of code sniffer (PHPCS) written in nodejs/javascript

crane icon crane

PHP Intellisense/code-completion for VS Code

devbox icon devbox

Vagrant Glayzzle devbox (nodejs, npm, glayzzle)

doc-parser icon doc-parser

:books: Documentation parser, doc blocks and annotations (fully compliant with phpDoc and doctrine annotations)

glayzzle icon glayzzle

:rocket: CLI library - PHP transpiler to NodeJS / Javascript

grafine icon grafine

:lollipop: A tiny nodejs/javascript in memory graph database

jsdoc-template icon jsdoc-template

A clean, responsive documentation template with search and navigation highlighting for JSDoc 3

jsoop icon jsoop

Class implementation for NodeJS that respects OOP principles (no prototype oriented)

locutus icon locutus

All your standard libraries will be assimilated into our JavaScript collective. Resistance is futile.

php-core icon php-core

:elephant: Contains all bindings for php-runtime in order to mimick PHP core functions

php-linter icon php-linter

Native javascript PHP lint - without running the PHP CLI

php-parser icon php-parser

:herb: NodeJS PHP Parser - extract AST or tokens

php-reflection icon php-reflection

:mag_right: Nodejs Reflection API for PHP files based on the php-parser

php-runtime icon php-runtime

:elephant: Runtime in order to execute transpiled PHP code into NodeJS/Javascript

php-transpiler icon php-transpiler

:cactus: Transpiler API to convert php-parser AST to Javascript

tests icon tests

Contains all unit tests for the Glayzzle project

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.