My app has a an event table, and corresponding model, and an EventProcessor CComponent. Events can be instantiated and processed synchronously. Or they can be saved to the table and run asynchronously by another process, either immediately or in the future by a cron job. EventProcessor renders views for some events, which can be decorated for browser display (sync processing only) or HTML email (sync or async both work).
I ran into trouble writing the console app for async processing. CConsoleApplication lacks stuff EventProcessor needed. So I started rewriting those parts of it with branches to deal with web vs. cli contexts, instantiating and using a controller, writing url creators that don’t need Yii::app()->request, resolving view file references, …
Eventually I stopped. It felt wrong. And I was concerned about breaking functionality that already worked.
CConsoleApplication is great for mapping the CLI into actions, etc. But it doesn’t do V in MVC and some of the C is different too.
I considered writing a hybrid of CConsoleApplication and CWebApplication. It seemed more work that the previously abandoned architecture but with the same problems plus new maintenance issues.
After discussions on #yii (Freenode) came another idea: Rewrite the console app as a web service and client. The console app would run cURL instead of calling methods in EventProcessor, which the web service would call instead.
From one point of view this is perverse. I don’t need a web service. Its just to provide an interface between the CWebApplication class and a console app. (Plus I need to deal with security on that interface.) But it might be the easiest architecture to maintain.
what do you think? Good architecture? Or is there a better one?
Is this a very exotic use of Yii? Or is my question too long for anyone to read?
You write a component that uses all 3 of MV&C and you want to use it in a webapp and in a console app. How do you make all the usual Yii stuff like render, createUrl, resolveView/File, etc. work the same in both contexts?