2
0
Эх сурвалжийг харах

SPOD Object update is back to dynamic
variables in __php__ are now escaped

Franco Ponticelli 17 жил өмнө
parent
commit
4f5c0e7672

+ 4 - 1
genphp.ml

@@ -467,6 +467,9 @@ let gen_function_header ctx name f params p =
 		ctx.local_types <- old_t;
 		ctx.local_types <- old_t;
 	)
 	)
 
 
+let s_escape_php_vars ctx code =
+	String.concat ((escphp ctx.quotes) ^ "$") (ExtString.String.nsplit code "$")
+	
 let rec gen_call ctx e el =
 let rec gen_call ctx e el =
 	match e.eexpr , el with
 	match e.eexpr , el with
 	| TConst TSuper , params ->
 	| TConst TSuper , params ->
@@ -517,7 +520,7 @@ let rec gen_call ctx e el =
 		concat ctx ", " (gen_value ctx) el;
 		concat ctx ", " (gen_value ctx) el;
 		spr ctx ")";
 		spr ctx ")";
 	| TLocal "__php__", [{ eexpr = TConst (TString code) }] ->
 	| TLocal "__php__", [{ eexpr = TConst (TString code) }] ->
-		spr ctx code
+		spr ctx (s_escape_php_vars ctx code)
 	| TLocal "__physeq__" ,  [e1;e2] ->
 	| TLocal "__physeq__" ,  [e1;e2] ->
 		gen_value ctx e1;
 		gen_value ctx e1;
 		spr ctx " === ";
 		spr ctx " === ";

+ 1 - 0
std/php/db/Manager.hx

@@ -67,6 +67,7 @@ class Manager<T : Object> {
 		apriv.push("__cache__");
 		apriv.push("__cache__");
 		apriv.push("__noupdate__");
 		apriv.push("__noupdate__");
 		apriv.push("__manager__");
 		apriv.push("__manager__");
+		apriv.push("update");
 
 
 		// get the proto fields not marked private (excluding methods)
 		// get the proto fields not marked private (excluding methods)
 		table_fields = new List();
 		table_fields = new List();

+ 8 - 16
std/php/db/Object.hx

@@ -42,14 +42,6 @@ class Object #if spod_rtti implements haxe.rtti.Infos #end {
 	static var manager = new php.db.Manager();
 	static var manager = new php.db.Manager();
 */
 */
 
 
-	static var local_managers = new Hash<{
-		private function doUpdate( o : Object ) : Void;
-		private function doInsert( o : Object ) : Void;
-		private function doSync( o : Object ) : Void;
-		private function doDelete( o : Object ) : Void;
-		private function objectToString( o : Object ) : String;
-	}>();
-
 	var __cache__ : Object;
 	var __cache__ : Object;
 	var __noupdate__ : Bool;
 	var __noupdate__ : Bool;
 	var __manager__ : {
 	var __manager__ : {
@@ -66,10 +58,13 @@ class Object #if spod_rtti implements haxe.rtti.Infos #end {
 
 
 	private function __init_object() {
 	private function __init_object() {
 		__noupdate__ = false;
 		__noupdate__ = false;
-		var cname = Type.getClassName(Type.getClass(this));
-		__manager__ = Manager.managers.get(cname);
-		if(!local_managers.exists(cname))
-			local_managers.set(cname, __manager__);
+		var me = this;
+		update = function() {
+			if(me.__noupdate__) throw "Cannot update not locked object";
+			me.__manager__.doUpdate(me);
+		}
+
+		__manager__ = Manager.managers.get(Type.getClassName(Type.getClass(this)));
 		var rl : Array<Dynamic>;
 		var rl : Array<Dynamic>;
 		try {
 		try {
 			rl = untyped __manager__.cls.RELATIONS();
 			rl = untyped __manager__.cls.RELATIONS();
@@ -82,10 +77,7 @@ class Object #if spod_rtti implements haxe.rtti.Infos #end {
 		__manager__.doInsert(this);
 		__manager__.doInsert(this);
 	}
 	}
 
 
-	public /*dynamic*/ function update() {
-		if(__noupdate__) throw "Cannot update not locked object";
-		__manager__.doUpdate(this);
-	}
+	public dynamic function update();
 
 
 	public function sync() {
 	public function sync() {
 		__manager__.doSync(this);
 		__manager__.doSync(this);