UNPKG

node-web-mvc

Version:
81 lines (80 loc) 2.83 kB
/** * @module HandlerMethod * @description action执行器 */ import MethodParameter from './MethodParameter'; import { BeanFactory } from '../../ioc/factory/BeanFactory'; import { ClazzType } from '../../interface/declare'; import { IAnnotation } from '../annotations/annotation/type'; export interface BeanTypeClazz { new (...args: any[]): any; } export default class HandlerMethod { private isBeanType; readonly beanFactory: BeanFactory; /** * 对应的action */ readonly method: Function; readonly methodName: string; get beanTypeName(): string; /** * 当前bean的类型 */ readonly beanType: BeanTypeClazz; /** * 对应controller实例 */ readonly bean: any; readonly parameters: Array<MethodParameter>; /** * 调用当前方法的参数值 */ argumentValues: any[]; /** * 当前请求返回的状态码 */ responseStatus: number; /** * 当前状态码产生的原因 */ responseStatusReason: string; readonly resolvedFromHandlerMethod: HandlerMethod; /** * 构造一个方法执行器 */ constructor(bean: InstanceType<BeanTypeClazz>, method: Function); constructor(bean: InstanceType<BeanTypeClazz>, method: HandlerMethod); constructor(beanType: ClazzType, method: Function, beanFactory?: BeanFactory); private initMethodParameters; /** * 获取当前方法上的指定注解信息 * @param { Annotation } annotationType 要获取的注解类型类 */ getAnnotation<T extends IAnnotation>(annotationType: T): T extends { NativeAnnotation: abstract new (...args: any) => infer A; } ? A : T extends abstract new (...args: any[]) => infer A_1 ? A_1 : T; /** * 获取当前方法上的指定注解信息 * @param { Annotation } annotationType 要获取的注解类型类 */ getMethodAnnotation<T extends IAnnotation>(annotationType: T): T extends { NativeAnnotation: abstract new (...args: any) => infer A; } ? A : T extends abstract new (...args: any[]) => infer A_1 ? A_1 : T; /** * 获取当前方法所在类的指定类注解信息 * @param annotationType 要获取的类注解类型类 */ getClassAnnotation<T extends IAnnotation>(annotationType: T): T extends { NativeAnnotation: abstract new (...args: any) => infer A; } ? A : T extends abstract new (...args: any[]) => infer A_1 ? A_1 : T; /** * 判定当前方法是否存在指定类型的注解 */ hasMethodAnnotation<T extends IAnnotation>(annotationType: T): boolean; createWithResolvedBean(): HandlerMethod; /** * 从 ResponseStatus 获取当前action设定的返回状态,如果没有获取到则使用默认的 */ private evaluateResponseStatus; }