php-next

0.1.2 • Public • Published

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;

Package Sidebar

Install

npm i php-next

Weekly Downloads

4

Version

0.1.2

License

MIT

Unpacked Size

6.37 kB

Total Files

4

Last publish

Collaborators

  • khalyomede