I'm building a plugin interface to a micro-framework I've been working on and am trying to work through a conceptual problem. The first "plugin" I've decided to make is a Stripe integration, essentially taking the PHP library for Stripe and wrapping it as a Plugin. I have a sort of factory pattern which allows retrieval of plugin instances like:
$stripe = Iceberg::getPlugin('Stripe');
Simple enough in the event that a class can be instantiated, but for the Stripe library, all of the classes are static. In their examples, they recommend doing an include() of the main Stripe file, and then you can use it like:
Stripe::setApiKey('xyz');
My disconnect is how I can make my getPlugin() method work with classes that only expose static interfaces. I obviously cannot instantiate the class and expect it to work correctly, but at the same time, I want this method to work regardless of instance or static objects.
One idea I've had is to implement a __call() method in my Stripe Plugin class, and then try to pass those calls to the Stripe library statically, like:
In Controller using Plugin
$stripe = Iceberg::getPlugin('Stripe');
$stripe->setApiKey('xyz');
In Plugin
public function __call( $name, $arguments )
{
Stripe::$name($arguments);
}
I'm not sure if something like that would even work, and even if it would, if that would be the best way.
TLDR: How can I create an object that can interface with classes in both object contexts and static contexts?