pronamic / wp-pay-core

Core components for the WordPress payment processing library. This library is used in the WordPress plugin Pronamic Pay: https://www.pronamicpay.com/, but also allows other plugin developers to set up a payment plugin.
https://www.wp-pay.org/
GNU General Public License v3.0
27 stars 3 forks source link

Make dealing with singletons easier #118

Closed remcotolsma closed 1 week ago

remcotolsma commented 1 year ago

Within a WordPress environment it is sometimes important that instances of classes are only created once, for example to prevent double filter and action hooks. For example, there are several iDEAL Basic providers, but it is not necessary to register several pronamic-pay/ideal-basic/v1/notification REST API endpoints.

Within the Pronamic Pay plugins only 1 \Pronamic\WordPress\Pay\Gateways\IDealBasic\NotificationController instance needs to exist. The Pronamic\WordPress\Pay\Plugin is already a singleton class, we could use this object to keep track of other singletons (container).

https://github.com/pronamic/wp-pay-core/blob/d2f591e9482272b62eda0dd1df9cfc669e7faec1/src/Plugin.php#L78-L91

remcotolsma commented 1 week ago

I'll close this for now, let's keep this idea in mind for future developments.