Conversation
Implements a factory for getting Post and Term objects Abstracts the class mapping functionality previously available only to posts
Current coverage is 92.77% (diff: 0.00%)@@ master #1218 diff @@
==========================================
Files 43 47 +4
Lines 3181 3280 +99
Methods 424 436 +12
Messages 0 0
Branches 0 0
==========================================
Hits 3043 3043
- Misses 138 237 +99
Partials 0 0
|
|
Note that the travis-run unit tests appear to have failed due to an http/svn-related issue. The test passed on all but one environment. I'm running PHP7 locally, but didn't make use of any features that are specific to > 5.4. |
|
@joshlevinson I'm about to get to bed, but I'm super excited about what I see. This seems to really clean things up (I didn't realize how much of the Post and Term class could really be delegated to the Factory to handle the BS like |
|
I don't have any good books handy to recommend; most of my reading has been online. |
This style provides different factories for Posts vs Terms, and allows direct instantiation of the factory vs strictly a static method. This is more future proof than the purely static method of timber#1218, and opens the door for stubs and better testing.
|
@jarednova @gchtr @joshlevinson I would be interested in picking this up again if there's any chance of getting a feature like this into 2.x. Especially with regard to being able to (somehow) specify a factory to use when calling Example use-case:
|
|
Doing some cleanup with @acobster deep into Factories over on this branch: https://github.com/timber/timber/tree/2.x-factories ... closing @joshlevinson's greatly appreciated PR here. Even if the exact code won't live on, the spirit will. Thanks for getting us started down this path! |
Issue
Begins to solve the problem of a lack of control over which classes Timber uses to instantiate WordPress objects.
Solution
This introduces a factory for creating Timber posts and terms.
Abstracts the class mapping functionality previously available only to posts
Impact
This change doesn't itself introduce back compat issues; future changes/usage might.
Usage
Changes how Timber WP objects are instantiated. These should be created with the appropriate Factory, rather than directly instantiating the Timber class objects.
Considerations
This solution doesn't introduce a factory for instantiating every Timber object. That may or may not be desirable. I'm up for discussion 🙂
Testing
Yet to be done!