Skip to content
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

Add data source repository #147

Draft
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Draft

Conversation

mhsdef
Copy link
Contributor

@mhsdef mhsdef commented Oct 3, 2024

I gave this some thought early last week, and, IMO our data source interplay shakes out like this abstractly:

  • Data Source Providers (code, wpdb/ui, and eventually VIP Integrations)
  • Data Source Writers (wpdb/ui only)
  • Data Source Repository

That last one, the repository, is the single place to go to read/write from that we seek. It should encapsulate the underlying complexity so nothing higher up needs to think about it.

Our data needs, being multi-sourced, are complex enough that I suggest we try light usage of the repository pattern. We feel like a good candidates in that:

  • we have multiple sources that we have to juggle
  • we aren't using an ORM so we have to do something to contain the complexity

And the pattern, done well, makes data flow and testing a breeze.

@mhsdef mhsdef marked this pull request as draft October 3, 2024 02:27
@mhsdef
Copy link
Contributor Author

mhsdef commented Oct 3, 2024

So, init would be in the main plugin file, something like:

Data\DataSourceRepository::init(
  [
    Config\ConfigStore::class,
    DataSourceCrud::class
    // eventually VipIntegrationGoop:class or whatever
  ],
  [
    DataSourceCrud::class
  ]
)

There is a bit of an impedence mismatch at the moment between our static class usages and that this class may need instantiation to use in reality. FWIW, suggest we consider moving that way. PHP is happier path with instantiations and dependency injections in most cases.


defined( 'ABSPATH' ) || exit();

interface DataSourceRepositoryInterface {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inject this instead of a concrete DataSourceRepository into all the things that need it. Controllers, whatever. Then in testing you just pass a test class that implements the interface and you're golden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant