Decouple from a web framework

114 views
Skip to first unread message

w3bj...@gmail.com

unread,
Jan 28, 2015, 1:25:50 PM1/28/15
to clean-code...@googlegroups.com
Hello all,
I can't see how to decouple a php web application from a MVC web framework such as Cake Php.

The framework require specific files to be put in specific places 

(e.g.  
  1. controllers/ PostsController.php
  2. models/ Posts.php
  3. views/Posts/ index.ctp
  4. views/Posts/ single.ctp)
)

Should we create the application independently, and then create some "routing files" in proper places that act as proxy for our app ?
What's another way of decoupling our architecture ?

Julian Seeger

unread,
Jan 29, 2015, 3:43:52 PM1/29/15
to clean-code...@googlegroups.com
Hey,

first of all, you should take a look at php autoloaders. Composer for example has autoloading functionality integrated and makes it pretty easy to define where your classes are according to their namespace.
This allows you to put your "normal" classes wherever you want. Oh and never use App::uses in your cake application ;)

If you want a quick example for how to decouple your application from the web framework, take a look at https://github.com/igorw/doucheswag
It's a small php project. At https://github.com/igorw/doucheswag/tree/master/src you see two subdirectories:
- "Douche", containing the deliverymechanism-independent application) and
- "DoucheWeb", containing the web-application that uses the Douche-Application.

The classes in the Douche package know nothing about the DoucheWeb package (so in your case there would be no cake-dependent code).
The DouchWeb package is pretty small because it's only responsibility is to call the Douche application with the correct arguments and display the results as html. This is where your cake application could be. And your Controllers would use the Douche package to do their job.

w3bj...@gmail.com

unread,
Jan 30, 2015, 12:27:25 PM1/30/15
to clean-code...@googlegroups.com
That was exactly the kind of answer I've been looking for, thanks !
Reply all
Reply to author
Forward
0 new messages