Making a PHP Composer Test Package

I recently realized the need to create a way to spin up the scaffolding of my projects more quickly. With the help of a Devpost article and chatGPT a little package prototype was born.


Here I include an example of this prototype that can be tested as a demo. You can find the repo here or visit a copy of the readme below.

This doc will show you how to set this up in 2 minutes or less.

If you prefer a video tutorial you can watch this here.


Requirements:

  • PHP must be installed (latest version is ideal)
  • Latest version of Composer must be installed
  1. Start a new project.
  2. In your root directory add a composer.json file and copy the following snippet of code:
{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/joshuaDclark/test-package"
    }
  ],
  "require": {
    "jc/test": "dev-master"
  }
}
  1. Run composer install

  2. Create a file called test.php and add the following snippet

    <?php

    require_once 'vendor/autoload.php';

    sayHello();

Save to the project root directory.

  1. Run the following command:

    php test.php

After running this command you should see the following response:

Hello from my test package! This is from V-2

Now that the test package is at this point I think I'm going to start tinkering with specific files I want to have in my projects. Thinking I may setup the autoload to install to the directory outside of the vendor files so that when a composer update command is run it doesn't break the project. Open to ideas on how I could make this better.