The Router is the entry point of the application.
| 132 | |
| 133 | |
| 134 | class Router: |
| 135 | """The Router is the entry point of the application.""" |
| 136 | |
| 137 | def __init__(self): |
| 138 | self.routes = {} |
| 139 | |
| 140 | def register( |
| 141 | self, |
| 142 | path: str, |
| 143 | controller_class: type[Controller], |
| 144 | model_class: type[Model], |
| 145 | view_class: type[View], |
| 146 | ) -> None: |
| 147 | model_instance: Model = model_class() |
| 148 | view_instance: View = view_class() |
| 149 | self.routes[path] = controller_class(model_instance, view_instance) |
| 150 | |
| 151 | def resolve(self, path: str) -> Controller: |
| 152 | if self.routes.get(path): |
| 153 | controller: Controller = self.routes[path] |
| 154 | return controller |
| 155 | else: |
| 156 | raise KeyError(f"No controller registered for path '{path}'") |
| 157 | |
| 158 | |
| 159 | def main(): |
no outgoing calls