Last active
February 10, 2022 15:45
-
-
Save RealyUniqueName/e0c6a3c051c790c0cfae58eeebdd7fae to your computer and use it in GitHub Desktop.
Sample PHP externs for Haxe
This file contains 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
-main Main | |
-php bin | |
#this flag is required if you're using Haxe 3.4 | |
-D php7 |
This file contains 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
{ | |
"require": { | |
"zendframework/zendframework": "^3.0" | |
} | |
} |
This file contains 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
//You can use any package name here. | |
//It's not required to match the namespace of php file. | |
package; | |
import php.NativeStructArray; | |
typedef EncodingOptions = { | |
?prettyPrint:Bool, | |
?enableJsonExprFinder:Bool, | |
} | |
@:native('Zend\\Json\\Json') | |
extern class Json { | |
@:phpClassConst static var TYPE_ARRAY(default,never):Int; | |
@:phpClassConst static var TYPE_OBJECT(default,never):Int; | |
static var useBuiltinEncoderDecoder:Bool; | |
static function decode(encodedValue:String, ?objectDecodeType:Int):Any; | |
static function encode(valueToEncode:Any, ?cycleCheck:Bool, ?options:NativeStructArray<EncodingOptions>):String; | |
static function prettyPrint(json:String, ?options:NativeStructArray<{?indent:String}>):String; | |
} |
This file contains 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
import php.Global; | |
import php.Const; | |
import php.NativeArray; | |
class Main { | |
static function __init__() { | |
//Assuming you're using Composer for the dependency management | |
//and the `vendor` directory is located in the root of your project. | |
Global.require_once(Const.__DIR__ + '/../../vendor/autoload.php'); | |
} | |
static function main() { | |
var obj:NativeArray = Json.decode('{"field":"value"}', Json.TYPE_ARRAY); | |
trace(obj['field']); | |
var str = Json.encode(obj, false, {prettyPrint:true}); | |
trace(str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment