sequenceDiagram
participant Developer as Developer
Trigger
participant Service instance as service
Service instance
participant Prepended module as Prepended module
Prepended module to the Service class
(Service::InstanceMethodsMiddlewaresCallers)
participant First middleware as First middleware
The first middleware
registered for Service#35;result
participant Second middleware as Second middleware
The second middleware
registered for Service#35;result
participant N_th middleware as N-th middleware
The last middleware
registered for Service#35;result
participant Original method as Original method
#35;result defined directly in the Service class
or inherited from some of its ancestors
Developer->>Service instance: result
Service instance->>Prepended module: result
Prepended module->>Prepended module: Do any middlewares are registered for Service#35;result?
alt No
Prepended module->>Original method: call(env)
else Yes
Prepended module->>First middleware: call(env)
end
First middleware->>First middleware: What is the type of the first middleware? Proxy or Decorator?
alt Proxy
First middleware->>Prepended module: return value
else Decorator
First middleware->>First middleware: Does one more middleware is registered?
alt No
First middleware->>Original method: call(env)
else Yes
First middleware->>Second middleware: call(env)
end
end
Second middleware->>Second middleware: What is the type of the second middleware? Proxy or Decorator?
alt Proxy
Second middleware->>First middleware: return value
else Decorator
Second middleware->>Second middleware: Does one more middleware is registered?
alt No
Second middleware->>Original method: call(env)
else Yes
Second middleware->>N_th middleware: call(env)
end
end
N_th middleware->>N_th middleware: What is the type of the N-th middleware? Proxy or Decorator?
alt Proxy
N_th middleware->>Second middleware: return value
else Decorator
N_th middleware->>Original method: call(env)
end
Original method->>Original method: Does the original method is called from the N-th middleware?
alt No
Original method->>Original method: Does the original method is called from the second middleware?
alt No
Original method->>Original method: Does the original method is called from the first middleware?
alt No
Original method->>Prepended module: return value
else Yes
Original method->>First middleware: call(env)
end
else Yes
Original method->>Second middleware: call(env)
end
else Yes
Original method->>N_th middleware: call(env)
end
N_th middleware->>Second middleware: return value
Second middleware->>First middleware: return value
First middleware->>Prepended module: return value
Prepended module->>Service instance: return value
Service instance->>Developer: return value