Skip to content

mcanthony/phpcore

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPCore

Build Status

Minimal PHP core library for PHP environments.

Who would use this?

After getting started with Uniter and PHPRuntime, you might want only a subset of the standard PHP library. You can include PHPCore and then only expose the builtin functions, classes or constants you need.

var phpCore = require('phpcore');

phpCore.install({
    functionGroups: [
        function (internals) {
            return {
                'add_one_to': function (argReference) {
                    return internals.valueFactory.createInteger(argReference.getNative() + 1);
                }
            };
        }
    ],
    classes: {
        'TwentyOne': function () {
            function TwentyOne() {}

            TwentyOne.prototype.getIt = function () {
                return 21;
            };

            return TwentyOne;
        }
    },
    constantGroups: [
        function (internals) {
            return {
                'MY_CONSTANT': 1000
            };
        }
    ]
});

phpCore.compile(
    // Example JS code transpiled from PHP by PHPToJS:
    function (stdin, stdout, stderr, tools, namespace) {
        var namespaceScope = tools.createNamespaceScope(namespace), namespaceResult, scope = tools.globalScope, currentClass = null;
        return tools.valueFactory.createInteger(
            namespaceScope.getConstant('MY_CONSTANT').getNative() +
            namespaceScope.getFunction('add_one_to')(tools.valueFactory.createInteger(21)).getNative()
        );
    }
)().execute().then(function (result) {
    console.log(result.unwrapForJS()); // Prints "1022"
});

Keeping up to date

About

Minimal PHP core library for PHP environments

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%