-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Develop] Improve extensibility #219
Conversation
This allows for an extended child class to set the global and for everything to still work provided the child class provides their own static `get_instance()` method which sets their own static `$instance` property.
196aa59
to
36c4fcd
Compare
Originally - this PR also contained the changes from PR #221 , but it made more sense to split the PR as - while related -, they really are two different things. |
…oading anticipating PR TGMPA#219
I'm +1 for this. |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof TGM_Plugin_Activation ) ) { | ||
self::$instance = new TGM_Plugin_Activation(); | ||
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { | ||
self::$instance = new self(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having an untestable singleton class, how about we put a static into load_tgm_plugin_activation()
instead?
…implementation The way the class was set up, extending from a child class would mean overloading a truck load of methods to get round the hard coded class name and some more convoluted coding to overrule the instance and the auto-instantiation of the class. These changes take the pain out of extending the class and make it so this library can have a clean upgrade path even when you extend the class. Details: * Wrap instantiation in a hooked function (so it can be unhooked) * Use the global to get to the instance. This allows for an extended child class to set the global and for everything to still work provided the child class provides their own static `get_instance()` method which sets their own static `$instance` property. * Force instantiation via `get_instance()` by making the constructor protected. props jrfnl, see #219
The changes in this PR allow for the class to be extended from a child class for a specific implementation.
The way the class was set up, extending from a child class would mean overloading a truck load of methods to get round the hard coded class name and some more convoluted coding to overrule the instance and the auto-instantiation of the class.
These changes take the pain out of extending the class and make it so this library can have a clean upgrade path even when you extend the class.
Details:
This allows for an extended child class to set the global and for everything to still work provided the child class provides their own static
get_instance()
method which sets their own static$instance
property.get_instance()
by making the constructor protected