Explorar o código

added "instance"

Nicolas Cannasse %!s(int64=17) %!d(string=hai) anos
pai
achega
0bbf7535cf
Modificáronse 1 ficheiros con 11 adicións e 0 borrados
  1. 11 0
      std/mtwin/web/Handler.hx

+ 11 - 0
std/mtwin/web/Handler.hx

@@ -165,6 +165,17 @@ class Handler<T> {
 		},lock);
 	}
 
+
+	function instance<T>( h : T -> Void, get : Int -> Bool -> T, lock : Bool ) : Void -> Void {
+		var me = this;
+		return function() {
+			var id = Std.parseInt(me.request.getPathInfoPart(me.level+1));
+			var inst = get(id,lock);
+			if( inst == null ) throw ObjectNotFound(id);
+			h(inst);
+		};
+	}
+
 	// action declarators
 
 	function free( n:String, ?t:String, ?cb:Void->Void ){