Franco Ponticelli 13 роки тому
батько
коміт
85061fb0a3
2 змінених файлів з 15 додано та 4 видалено
  1. 1 1
      genphp.ml
  2. 14 3
      std/php/Lib.hx

+ 1 - 1
genphp.ml

@@ -1381,7 +1381,7 @@ and gen_expr ctx e =
 		old()
 	| TObjectDecl fields ->
 		spr ctx "_hx_anonymous(array(";
-		concat ctx ", " (fun (f,e) -> print ctx "\"%s\" => " f; gen_value ctx e) fields;
+		concat ctx ", " (fun (f,e) -> print ctx "\"%s\" => " (escape_bin f); gen_value ctx e) fields;
 		spr ctx "))"
 	| TFor (v,it,e) ->
 		let b = save_locals ctx in

+ 14 - 3
std/php/Lib.hx

@@ -60,11 +60,22 @@ class Lib {
 		untyped __php__("reset($arr); while(list($k, $v) = each($arr)) $h->set($k, $v)");
 		return h;
 	}
-	
+
 	public static function associativeArrayOfHash(hash : Hash<Dynamic>) : NativeArray {
 		return untyped hash.h;
 	}
 
+	public static function objectOfAssociativeArray(arr : NativeArray) : Dynamic {
+		untyped __php__("foreach($arr as $key => $value){
+			if(is_array($value)) $arr[$key] = php_Lib::objectOfAssociativeArray($value);
+		}");
+		return untyped __call__("_hx_anonymous", arr);
+	}
+
+	public static function associativeArrayOfObject(ob : Dynamic) : NativeArray {
+		return untyped __php__("(array) $ob");
+	}
+
 	/**
 		For neko compatibility only.
 	**/
@@ -97,7 +108,7 @@ class Lib {
 		}
 		return o;
 	}
-	
+
 	/**
 	*  Loads types defined in the specified directory.
  	*/
@@ -108,7 +119,7 @@ class Lib {
  		$_hx_cache_content = '';
  		//Calling this function will put all types present in the specified types in the $_hx_types_array
  		_hx_build_paths($pathToLib, $_hx_types_array, array(), $prefix);
- 
+
  		for($i=0;$i<count($_hx_types_array);$i++) {
  			//For every type that has been found, create its description
  			$t = null;