Timeline for Proper Repository Pattern Design in PHP?
Current License: CC BY-SA 3.0
21 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 16, 2019 at 23:54 | comment | added | Mazzy | How would Eager-Loading play a part in this? In every application I have written, at some point, we had to implement eager loading; very specific to the controller. Almost never re-usable. | |
| May 23, 2017 at 11:47 | history | edited | URL Rewriter Bot | replaced http://stackoverflow.com/ with https://stackoverflow.com/ | |
| Aug 2, 2016 at 12:11 | comment | added | Andrew | With this approach there's only one entry point for updating/deleting records. This is fine if it's application logic is dictating which records should be updated/deleted but for data concentric operations this logic is best handled by the underlining persistence layer (SQL excels at this). | |
| Apr 23, 2016 at 22:54 | comment | added | Morteza Tourani | @Jonathan This Save method decides by ID if it's insert or update. What would you say for pivot tables which has two IDs and maybe (or maybe not) other fields. As I live in a C# ecosystem and there is a lot of funny things like LINQ to Entities, is there any syntax like them which accepts lambdas for conditioning? | |
| Sep 28, 2015 at 10:59 | history | edited | Jonathan | CC BY-SA 3.0 | Tweak wording to make point more clear |
| Jul 6, 2015 at 20:08 | comment | added | Jonathan | @Gizzmo Using query objects, you can pass in addition parameters to help with your more complicated queries. For example, you can do this in the constructor: new Query\ComplexUserLookup($username, $anotherCondition). Or, do this via setter methods $query->setUsername($username);. You can really design this however it makes sense for your particular application, and I think query objects leave lots of flexibility here. | |
| Jul 6, 2015 at 20:04 | history | edited | Jonathan | CC BY-SA 3.0 | An update to how I solved this problem |
| Nov 28, 2014 at 15:02 | comment | added | Luís Cruz | @Darius.V Typically a Repository is used to access data (an CRUD operations). All the logic would be best suited in a Service. Take a look at: this and this | |
| Nov 28, 2014 at 14:58 | comment | added | Dariux | Your examples are very simple. In real life applications there are more actions done. Do you put all the logic, loops, whatever in those repository classes also? Or repository classes are simple like models and logic should be in another class, lets say library but not in controller? And then controller injects library, library injects repository, repository injects model? | |
| Nov 14, 2014 at 6:51 | comment | added | Dariux | I wish that frameworks just would put in their documentation the full example of of how this should be used. Cause now people are trying to invent wheels by not knowing how to do the right way. | |
| Nov 7, 2014 at 1:23 | comment | added | scipilot | @Gizzmo yes I was thinking the same thing. I'm trying to figure out the cleanest way to pass in a set of "filter parameters" which could span related models, matching object properties in different ways (i.e. not just equality). Like setting up a sparse context bound to the model before executing the search. I don't want to propagate the eloquent/whatever tools for this up to the controller, so am faced with inventing a new query definition structure. I'm sure there's a pattern for that! | |
| Oct 28, 2014 at 8:09 | comment | added | Gizzmo | @Jonathan: How you handle queries that should fina a user not be "ID" but e.g. by "username" or even more complicated queries with more than one condition? | |
| Oct 13, 2014 at 12:06 | comment | added | Boedy | @Jonathan It's been one and a half year since you answered your own question. I was wondering if you are still happy with your answer and if this is your main solution now for most of your projects? The last few weeks I've been reading allot on repositories and I've seen allot of people have their own interpretation of how it should be implemented. Your calling it query objects, but this an existing pattern right? I think I've seen it being used in other languages. | |
| S Aug 12, 2014 at 17:54 | history | suggested | Lionel | CC BY-SA 3.0 | Access to DB object via $this needed |
| Aug 12, 2014 at 17:46 | review | Suggested edits | |||
| S Aug 12, 2014 at 17:54 | |||||
| Jun 26, 2014 at 8:54 | comment | added | Adam | Interesting that you split up your Create, Update and Delete from your Read. Thought it would be worth mentioning Command Query Responsibility Segregation (CQRS) which formally does just that. martinfowler.com/bliki/CQRS.html | |
| Apr 24, 2014 at 18:38 | comment | added | Jonathan | @PeeHaa Again, it was to keep the examples simple. It's very common to leave pieces of code out of an example if they don't pertain specifically to the topic at hand. In reality, I would pass in my dependencies. | |
| Apr 24, 2014 at 18:10 | comment | added | Jonathan | @PeeHaa Simply to keep my examples clean and simple. It's also something people quickly understand. | |
| Apr 24, 2014 at 15:43 | comment | added | PeeHaa | Why are you still tightly coupling Response with your controller? | |
| Dec 11, 2013 at 16:41 | vote | accept | Jonathan | ||
| Apr 26, 2013 at 13:45 | history | answered | Jonathan | CC BY-SA 3.0 |