-
Notifications
You must be signed in to change notification settings - Fork 21
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
WIP PHP Plugin scaffolding #32
Conversation
b47151c
to
7de5710
Compare
b588c95
to
fe43cac
Compare
Just noting that I needed to switch to woocommerce Looks like the Dependency Injection container work was only merged recently woocommerce/woocommerce#27733 So I think we would need WC 4.7+ place which is in RC Also, I think some of the php syntax being used might be 7.1+ and we have a 7.0 minimum for Woo core. I've added some notes to the main readme under prerequisites |
Not 100% sure why but I need to delete the updated package-json.lock file on this branch and start fresh to be able to run the build properly. |
@ecgan can you try out this branch (you will need WooCommerce 4.7-rc1 +) and see if you have the same problem with package-lock.json |
@jconroy ,
Could you provide more details? Do you see an error when running build? I checkout the branch and run the usual
The above has been (temporarily) fixed in a PR for wp-scripts, WordPress/gutenberg#26591. In my local, I merge the trunk branch into this feature/scaffolding branch, and then re-run
Actually, why do I need the WooCommerce core plugin? 🤔 I did the above process without the plugin. |
That’s the same error - thanks - just wanted to confirm you were seeing the same. Thats interesting about merging in trunk - must be something in the dependencies somewhere
You don’t to run npm - my comment was just in relation what you’ll need to run this branch (to be able to install the plugin etc) |
@jconroy ,
Yes indeed, it's with the @wordpress/scripts, the merge I did bumps "@wordpress/scripts": "^12.2.1" to "@wordpress/scripts": "^12.5.0". |
PHP Plugin Scaffolding
This PR implements an initial framework to continue building out this plugin. I'll cover that approach I'm using, my ideas for the long term, as well as what is needed as next steps.
Approach
I had in mind to utilize as much modern PHP practice as possible. For inspiration, I tuned to some of the recent work done in WooCommere core (dependency injection), plus a framework developed by others in the WordPress community (Alain Schlesser's speaking page plugin. There are a few key concepts that I feel are important:
instance()
methods. As much as possible, ensuring that classes be instantiated only once should be handled outside of each class.With these points in mind, I've set up an initial version of this plugin. The main plugin file calls a factory class to kick off the main plugin on the
woocommerce_loaded
hook. We make use of containers and services, as modeled in WooCommerce core, to provide our functionality to the plugin.Any kind of asset handling (such as scripts and styles) outside of PHP has a bit of a special case. Essentially, each individual asset should be instantiated with a class that implements the
\Automattic\WooCommerce\GoogleForWC\Assets\Asset
interface, and enqueuing should be mostly automatic.Long Term Ideas
New functionality should be separated into components that make sense. I've tried to start that process by creating the
\Automattic\WooCommerce\GoogleForWC\Menu
and\Automattic\WooCommerce\GoogleForWC\Pages
namespaces. We'll likely need other top-level components likeRestAPI
and some others. This structure can be determined by us all as we work on the project to figure out what makes the most sense.Next Steps
Right now, I've got an initial version of this working. Here are some of the next steps:
StyleAsset
for handling our style registration.ScriptAsset
class\Automattic\WooCommerce\Internal\DependencyManagement\Definition
class. This is specially built for legacy code in WC core that relies on a staticinstance()
method. We should be careful to avoid using that class and instead use the originalDefinition
class. Aside from that issue, I don't feel very happy with how it's currently working, so I'm very much open to ideas for improvement there.Plus all of the things still missing from the original issue.