Closed s0me0ther closed 8 years ago
Klein is basically a pure router, not a framework. This use case shouldn't be handled by the router, in my opinion.
A better pattern if you need to consistent handling of behavior between HTTP and console is to create a service layer between your controllers and the rest of your code that encapsulate all of the high-level business logic. Then you can use the Symfony console component (or another harness, but symfony\console is the best standalone component for my money) to create commands that can be run directly. Both commands and http requests end up calling the same set of services, the only difference is that in the first case, the Console command object handles mapping the command's parameters to services, while in the second, the Controller object handles mapping the HTTP request data to services.
This is, of course, the service layer pattern from PEAA, and not something I came up with on my own.
Great respone, thank you.
I would like to create an application which can be handled over http(s) and console. Are there console Routes Supported in Klein?