浏览代码

[php] Allow passing php class names as strings to `Syntax.instanceof()`

Alexander Kuzmenko 7 年之前
父节点
当前提交
235e8ef8f8
共有 2 个文件被更改,包括 8 次插入0 次删除
  1. 1 0
      std/php/Syntax.hx
  2. 7 0
      tests/unit/src/unit/TestPhp.hx

+ 1 - 0
std/php/Syntax.hx

@@ -162,6 +162,7 @@ extern class Syntax {
         Haxe generates `Std.is(value, Type)` calls as `$value instanceof Type` automatically where possible.
         Haxe generates `Std.is(value, Type)` calls as `$value instanceof Type` automatically where possible.
         So you may need this only if you have a `Class` stored in a variable.
         So you may need this only if you have a `Class` stored in a variable.
     **/
     **/
+    @:overload(function( value:AsVar<Dynamic>, phpClassName:AsVar<String> ) : Bool {})
     static function instanceof<V,C>( value:AsVar<V>,  type:AsVar<Class<C>> ) : Bool;
     static function instanceof<V,C>( value:AsVar<V>,  type:AsVar<Class<C>> ) : Bool;
 
 
     /**
     /**

+ 7 - 0
tests/unit/src/unit/TestPhp.hx

@@ -193,6 +193,13 @@ class TestPhp extends Test
 		t(a.indexOf(fn2) < 0);
 		t(a.indexOf(fn2) < 0);
 		f(a.remove(fn2));
 		f(a.remove(fn2));
 	}
 	}
+
+	function testSyntaxInstanceof() {
+		var o = new ClosureDummy();
+		var phpClassName = Boot.castClass(ClosureDummy).phpClassName;
+		t(Syntax.instanceof(o, ClosureDummy));
+		t(Syntax.instanceof(o, phpClassName));
+	}
 }
 }
 
 
 private class ClosureDummy {
 private class ClosureDummy {