Wrapping External PHP Libraries
An example
Comments and explanations to be completed at a later time.
Simple.class.php
<?php
function makeSimple($text) {
return new Simple($text);
}
function printSimple($simple) {
$simple-> doPrint();
}
class Simple
{
public $text;
public function __construct($text) {
$this->text = $text;
}
public function doPrint() {
echo $this->text;
}
protected function changeText($text) {
$this->text = $text;
}
}
class Simple2 extends Simple{
public function __construct($text) {
parent::__construct($text);
}
public function makeChange($text) {
changeText($text);
}
}
?>
src/test/Simple.hx
package test; extern class Simple { static function __init__():Void untyped { __call__("require_once", "Simple.class.php"); } public var text:Dynamic; public function new(something:Dynamic):Void; public function doPrint():Void; function changeText(text:Dynamic):Void; }
src/test/Simple2.hx
package test; extern class Simple2<T> extends Simple { static function __init__():Void { untyped __call__("require_once", "Simple.class.php"); } public function new(text:T):Void; public function makeChange(text:T):Void; }
src/test/SimpleHelper.hx
package test; class SimpleHelper { public static inline function makeSimple(text):Simple return untyped __call__("makeSimple", text) public static inline function makeSimple2<T>(vari:T) return new Simple2(vari) public static inline function printSimple(simple:Simple) untyped __call__("printSimple", simple) }
version #7255, modified 2009-11-19 00:08:10 by tylermac