Why I felt there was a need for Mozart

Now that Mozart is gaining more momentum and Composer is more commonly being used by WordPress plugin developers, I get asked this question more often. With popular tools like PHP-Scoper also being used in the WordPress ecosystem, I figured it was time to explain why I felt there was a need for another tool that does a similar job.

First, a bit of history…

The first public commit of Mozart was pushed to GitHub in March 2017. That’s over two years ago now. Composer was in a weird place of the WordPress ecosystem back then. Developers were using Composer to manage the dependencies for entire websites, for example to get specific versions of plugins or a theme. But using Composer to manage dependencies inside a single plugin wasn’t so common back then.

Developers were struggling with using the whole principle of packages. While very common in the larger PHP world, WordPress plugin developers have struggled to adapt to the idea of packages. Code was being reused in all sorts of ways like Git submodules inside repositories (which is fine, in a way), but most times it was a clunky and complex process. This got better over time. Using packages is now more common.

The idea for Mozart was born!

When I had the idea for Mozart all planned out, I started researching if there wasn’t a similar tool out there already. And of course there was. PHP-Scoper does a lot of what Mozart does today. In my quest to educate developers about how and why they should use Composer in their plugins (context: version conflicts between dependencies), I felt that adding the extra configuration steps with PHP-Scoper and explaining why it was needed, was making it overly complex.

Mozart had to be more simple to use. Less options, perhaps a bit more opinionated towards the WordPress ecosystem. It also had to support prefixing global class names, since that was and still is very common in WordPress code.

PHP-Scoper is a great tool

Today, the use of Composer in WordPress plugins is more common. Prefixing namespaces in order to prevent version conflicts is actually gaining traction as well. I personally don’t care if you use Mozart, PHP-Scoper or prefix your namespaces manually (although I don’t recommend that for sanity reasons). As long as you prefix your classes and namespaces properly, until WordPress has figured out a proper way to deal with these dependency management issues, I’m happy.

PHP-Scoper is a great piece of software and if you’re up for the configuration (the fine folks at Delicious Brains have written a nice tutorial about it), that’s awesome! If you want something that is a bit more opinionated towards the WordPress ecosystem, I’m positive that Mozart might suit you better.

Leave a comment

Your email address will not be published. Required fields are marked *