浏览代码

added "instance"

Nicolas Cannasse 17 年之前
父节点
当前提交
0bbf7535cf
共有 1 个文件被更改,包括 11 次插入0 次删除
  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 ){