Created
March 5, 2014 01:24
-
-
Save jakubkulhan/9359412 to your computer and use it in GitHub Desktop.
js2php's usage example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log("hello, world!"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once __DIR__ . "/build/image.php"; | |
| require_once __DIR__ . "/build/JSInterpreter.php"; | |
| $interpreter = new JSInterpreter(file_get_contents("some.file.js"), "some.file.js"); | |
| $compiledCode = $interpreter->compile(); | |
| $mainFunction = eval($compiledCode); | |
| file_put_contents( | |
| "some.file.php", | |
| "<?php\n" . | |
| preg_replace( | |
| "/\n([^\n]|\n\n)+$/", | |
| "\nrequire_once __DIR__ . '/build/image.php';\n$mainFunction(JS::\$global);", | |
| $compiledCode | |
| ) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once __DIR__ . "/build/image.php"; | |
| require_once __DIR__ . "/build/JSInterpreter.php"; | |
| $interpreter = new JSInterpreter(file_get_contents("some.file.js"), "some.file.js"); | |
| $interpreter->run(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment