I am currently in the midst of developing a new side-project and wanted to use the same class as a base for two separate elements of the project. This class features some helper classes I want available. Each element has its own repo which is using composer as its package manager. I wanted to create my own package from a git repo which will house my base class.
In the examples below, my reusable package will feature two classes, on called Utils
and the other Base
. They will both be scoped to the Mikestreety
namespace.
This blog post also assumes you have basic knowledge of composer
Create a new repo with your classes in. A common convention is to put your classes in a src/
folder inside of the repository. Create a new composer.json
file too - and place it in the root of the repo. The folder structure should be something like:
/
composer.json
src/
Base.php
Utils.php
The next step is to namespace you classes - this prevents any other classes with the same name in your application or in another package.
#php