Skip to content

Getting started with MyBB 1.9 development Composer

dvz edited this page Oct 31, 2021 · 7 revisions

Getting started with MyBB 1.9 development - Composer

Contents

  1. MyBB with Composer
  2. What is Composer?
  3. Installing and getting Composer on your machine
  4. Installing Dependencies
  5. Adding new Dependencies

MyBB with Composer

In MyBB 1.9, we're introducing Composer to help us manage third party libraries and autoload classes. In the past, we copied third party dependencies into the inc/3rdparty folder. This made managing library updates difficult especially if they too had dependencies. With Composer we can improve this process by now simply Adding a new Dependency

What is Composer?

Composer is a tool to manage dependencies in PHP projects, though this is not limited to PHP, Composer is designed specifically for use with PHP, similar to how Ruby has Gems. It allows us to define a list of packages that MyBB depends on and then manages installing and updating those dependencies automatically.

Installing and getting Composer on your machine

To start working with Composer and installing/updating packages, you need to install the Composer tool on your system. You can either install Composer in a path local to a copy of the MyBB repository that you're working on, or you can install it globally. In this post, we'll be installing it locally as it's useful to have a single copy that you can use across multiple projects.

The download and install process is fully documented on the Composer website. The easiest way is to run the commands from the top of that page, which we haven't copied below as the file hash of the Composer package changes with every new version release they make.

Installing the MyBB dependencies

Now that you've installed Composer on your system, you can install the libraries that MyBB 1.9 depends on. Dependencies are installed in the composer.json file found in the root of the MyBB directory. At the time of writing, we depend upon the following libraries:

To install all of these dependencies, run the following command from the MyBB root:

composer install

This will create the directory inc/vendor and fill it with several files and folders including inc/vendor/autoload.php and inc/vendor/twig/.

The version that is installed will be the same for all developers working on MyBB 1.9 thanks to the composer.lock file which specifies exact versions of packages to use.

Adding new Dependencies

The easiest way to add a new dependency is to do so via the command line. First of all, find the name of the dependency on Packagist. For the purpose of this post, I've chosen to install the Laravel translation package illuminate/translation. You can easily install the dependency by running the command found below the package title on the Packagist page. For example:

composer require illuminate/translation

This will add the dependency to the composer.json file and actually download the package itself into the inc/vendor folder for you. The library will be available via the autoloader (inc/vendor/autoload.php) and available to use straight away with no further effort.