TL;DR: To dynamically load classes by namespaces in PHP, you need a Registry, and a way to parse the concrete files from a directory based on its namespace.
Whenever I’m working on a project that has an object-oriented code base and that uses Subscribers and Services, I often use a
Registry. This makes it easy to
- register the subscribers with the core application whenever the code runs,
- de-couple any
Service classes so they can be tested or even run isolation,
- and maintain the code base whenever something has to be added or taken away.
One challenge with this approach though, at least in PHP, is that I’ve found myself having to go back into the Registry and set a reference to a given
Subscriber whenever I want to add it (or remove it whenever I want to, you know, remove it).
Ideally, I want my registry to know where the subscribers are and how to set them up. This way, I can focus on working on the rest of the code.
TL;DR: There are a few PHP Code Sniffer extensions for Visual Studio Code. The one I prefer is PHP Sniffer & Beautifier by Samuel Hilson. Here’s where to get it and how to configure it.
Though this isn’t directly related to the material I’m writing about in my series on Ray on WordPress, it’s relevant enough to share at this point because:
- the series is only going to include more code and i use this extension for writing said code,
- over the last few months, I’ve found this extension to be really good in comparison to others that are available.
There are some other ones out that that are really good, and I’ve used them, but this is the one I’ve settled on using.
TL;DR: This is everything that needs to be done to install Xdebug with a Homebrew-based environment and to work with the software within Visual Studio Code.
Though I’ve recently become a fan of using Ray (1, 2) for much of my lightweight debugging, this doesn’t mean I don’t think it’s important to have Xdebug installed and configured in Visual Studio Code.
If you follow the steps I’ve outlined starting in the previous post, it’s relatively easy though it still requires a little bit of manual work to get started.
This is how you can set up Xdebug with a Homebrew-based configuration and Visual Studio Code.
TL;DR: How to uninstall PHP 8.1, install PHP 7.4, why you should do so, and one extra utility to helps manage PHP packages and modules.
When I wrote about how to fix WordPress, PHP, MariaDB, and Homebrew, I didn’t cover some of the other larger issues that I experienced when working backwards into the solution.
I need to give Ihor a hat tip here because he and I spoke about this more on Twitter regarding the relationship between WordPress, PHP 7.4, 8.0, and 8.1.
I’d be remiss if I didn’t clarify the following:
- I was running PHP 8.1.
- WordPress is not compatible with PHP 8.1
- WordPress is [allegedly] compatible with PHP 8.0 but I’ve not tested it or my tools against this version because I wanted to have full compatibility.
- I downgraded my system to PHP 7.4.27 until I get my entire set up configured as I like. Then I’ll start upgrading components.
So if you’ve followed the aforementioned post, here’s a more complete set of things I’ve set up to make sure everything is working well together – including things I’m working on writing about 🙂.
TL;DR: I find the using a registry, subscribers, and services very useful when building backend-centric plugins and utilities for WordPress. This post walks through how to do it.
After working in with design patterns, object-oriented programming, and WordPress for years, common ways of solving problems are bound to arise.
This is how we got object-oriented design patterns to begin with, so maybe this is a WordPress-centric variation of that.
Though I’ve written about things such as registries in previous articles (and ones that are not that old even), it’s never a bad idea to revisit the same topic especially when there’s something to continue to add to the previous take.