phpcore

2019-08-14 admin

phpcore是什么

什么是phpcore,Minimal PHP core library for PHP environments

phpcore使用教程帮助文档

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;
        },
        'My\\Tools\\Worker': function () {
            function Worker() {}

            Worker.prototype.run = function () {
                console.log('running');
            };

            return Worker;
        }
    },
    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

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-72470.html

文章标题:phpcore

回到顶部