Giter Site home page Giter Site logo

php-next's Introduction

php-next

Write modern PHP code.

Write modern PHP

array_filter($posts, $post => $post->published);

And transpile it

array_filter($posts, function($post) {
  return $post->published;
});

Summary

Installation

npm install --save-dev php-next@0.*

or

yarn add --dev php-next@0.*

Examples

Example 1: basic usage

const phpNext = require('php-next');
const arrowFunction = require('php-next-arrow-function');

const transpiled = phpNext('./path/to/file.php', {
    features: [arrowFunction]
});

Features list

If you want your feature to be listed here, please propose a Pull Request and update this file.

Create features

Features are functions that returns a string, transpiling the code given in first parameter.

You can inspire from the use-from feature source code:

lib/feature/use-from.js (simplified)

const useFrom = function (code) {
  return code.replace(/use(.+)from(.+);/g, function (match, classes, namespace) {
    // "DB, Session" becames ["DB", "Session"]
    const classList = classes.split(",");
    let statements = [];

    namespace = namespace.trim();

    // ["DB"] becames "use ...\DB;"
    for (const className of classList) {
      statements.push("use " + namespace + "\\" + className + ";");
    }

    return statements.join("\n");
  });
};

module.exports = useFrom;

php-next's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.