Working on a project where certain objects are getting large in scope. For example, I have a listing. Each listing has a user associated with it, several images, possibly a merchant account, billing, reviews, etc.
Whenever I retrieve a listing, I also want to grab this associated data. This quickly gets messy in the controllers and even more so when dealing with validation, updating the database, and so on. I've moved some of the code into a Listing_Search class file and have looked into modules and packages, but I'm not sure they are the right fit (am I wrong? If so, please let me know). I saw that Laravel separates their models into Entities, Services, and Repositories.
This seems like a good idea and something that could be done in Fuel (by someone more intelligent than myself). Has anyone attempted this before? I'm not sure how it would all fit together but my current theory is:
Classes
- Entity
- Model
- Controller
- Service
Entity_Listing would implement iterator, countable, ArrayAccess, and SeekableIterator. One could do something like Entity_Listing->find(seachdata); and have it retrieve all of the listing information nice and easily.
Not sure if the services would each deal with an entity or with individual models and then have an entity service as well which pulls in all of the service models. E.g.,
Service_Merchant
Service_User
Service_ListingImages
...
and Service_Listing can use the merchant, user, and listingimages services as well.
The models would remain as they currently are I suppose. Haven't seen a reason to change them.
Has anyone looked into this before and come to some different conclusions? Should I take another look at modules or packages? The project has grown in scope that I continuing the way I have been will only make things more and more difficult to maintain. Any help here would be appreciated.
Laravel just suggests an implementation of these design patterns. In the end they are all plain classes, so you can do exactly the same in FuelPHP with no effort at all.
You can copy all examples from their models and libraries docs page and paste them into FuelPHP classes, pick the correct filename (so Trackler\Repositories\Location_Repository goes into app/classes/trackler/repositories/location/repository) and off you go.