Payment method controllers only contain logic and some configuration to identify the controllers. Within the class there is no relationship with data outside the class. The class's methods accept any input of a certain type, generate and return output and then throw away the input. Never is external data stored in the class.
This means we don't need multiple instances of controller classes. Actually we don't even need a single instance. We currently have payment_method_controller_load_multiple() that statically caches a single instance so we don't have unnecessary identical controllers lying around (identical in terms of functionality, because they are different resources). However, this is a rather ugly factory/singleton-like solution.
A better solution may be to use static methods. These clearly show developers that controller classes are not meant to be instanced and it also practically prevents the classes from being instanced, because instances simply won't work within the system.
Postponed until version 7.x-2.x, but discussion is welcome here.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | payment_1578020_6.patch | 42.48 KB | xano |
Comments
Comment #1
xanoThis issue boils down to the fact that the current situation is not ideal. It works, but there are a few possible pitfalls for people who don't fully read or understand the documentation:
Based on those possibilities, we can write down some requirements:
hook_payment_method_controller_info_alter().Comment #2
xanoSee #1821100: Convert payment method controllers, contexts, statuses and line items to plugins.
Comment #3
xanoMake payment methods be instances of payment method controllers, so we lose a abstraction and add flexibility.
Comment #4
xanoAs the next major branch will be for Drupal 8, we can leverage its plugin API:
These steps will solve all the issues raised in #1.
Comment #5
xanoComment #6
xano