I've been writing PHP within WordPress for a while, but I'm pretty new to straight PHP applications. I'm writing a little application that uses a few different APIs to do cross posting.
I've written the classes, but I'm not sure of the best way to have them interact.
A bit of background on the classes and their functionality. I've got a class for each API (Reddit, Imgur, Twitter), a class with some Curl helper functions, a class that carries out the process. I don't think I'll ever need more than one instance of any of these current classes. Nor will they ever need to be extended.
From what I've read, I've got a few options:
- Instantiate each class as a global variable (I've heard I should avoid this)
- Make the classes singletons (Also heard I maybe should avoid this)
- Static methods - though some of the classes need to be instantiated and I'm not sure how that would work.
Those are the methods I've heard of. I'm expecting the answer will be none of the above. How do frameworks like Laravel do this?
This might be subjective, but I'm sure I'll learn something about patterns.
Edit: I probably should add some examples of the types of interactions required.
- An API class using the CurlHelper class (I'm currently using a static method:
$post_string = CurlHelper::createPostString( $post_data );
) - Generating a title in one class for use when cross posting to each API
Aucun commentaire:
Enregistrer un commentaire