Sfoglia il codice sorgente

[php7] made php.Lib.objectOfAssociativeArray() recursive (#6698)

Alexander Kuzmenko 8 anni fa
parent
commit
fe30645e71
3 ha cambiato i file con 21 aggiunte e 0 eliminazioni
  1. 1 0
      extra/CHANGES.txt
  2. 5 0
      std/php7/Lib.hx
  3. 15 0
      tests/unit/src/unit/TestPhp.hx

+ 1 - 0
extra/CHANGES.txt

@@ -5,6 +5,7 @@
 	js : fixed saving setter to `tmp` var before invocation (#6672)
 	php7 : don't fail on generating import aliases for classes with the similar names (#6680)
 	php7 : fixed appending "sqlite:" prefix to the names of files created by `sys.db.Sqlite.open()` (#6692)
+	php7 : made php.Lib.objectOfAssociativeArray() recursive (#6698)
 	php/php7 : fixed `sys.net.Socket.bind()` (#6693)
 
 2017-10-08: 3.4.4

+ 5 - 0
std/php7/Lib.hx

@@ -108,6 +108,11 @@ class Lib {
 	}
 
 	public static inline function objectOfAssociativeArray(arr : NativeArray) : Dynamic {
+		Syntax.foreach(arr, function(key:Scalar, value:Dynamic) {
+			if(Global.is_array(value)) {
+				arr[key] = objectOfAssociativeArray(value);
+			}
+		});
 		return Boot.createAnon(arr);
 	}
 

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

@@ -66,6 +66,21 @@ class TestPhp extends Test
 	}
 
 #if php7
+
+	function testIssue6698() {
+		var arr = new NativeAssocArray<Dynamic>();
+		var innerArr = new NativeAssocArray<Int>();
+		innerArr['one'] = 1;
+		innerArr['two'] = 2;
+		arr['inner'] = innerArr;
+
+		var obj = Lib.objectOfAssociativeArray(arr);
+		var innerObj = obj.inner;
+		t(Global.is_object(innerObj));
+		eq(1, innerObj.one);
+		eq(2, innerObj.two);
+	}
+
 	/**
 		Check compiler will generate proper function signature with `Ref<T>` arguments
 	**/