PHP develop your own package with local composer environment

PHP develop your own package with local composer environment

2019-04-18T16:16:45.000Z

Developing your own PHP composer package locally & integrating local file symlink within your application can speeds up development immensely. It also gives you a platform to test out your package in real application on real time.

I've learned this workflow by reading out multiple articles online recently. So I thought I'll create my own version of it.

Basic PHP package setup

There are different ways to create your own package with all necessary setup included. There are different boilerplate/skeleton projects for creating packages like Spatie's PHP Skeleton or The PHP League Skeleton. Even you can create your own package setup as per your requirements.

Package development local directory structure

In my case the package I work on multiple applications on the same time & I use my packages in the multiple applications. On my development environment I always use development copy of my package also so I can modify easily when working on any project. Here is how my structure looks like:

PHP Package Development EnvironmentPHP Package Development Environment

Composer file setup for local package development

Your project/application composer file should look something like this:

 {
    .
    .
    "require": {
         .
         .
         "xyz/your-awesome-package": "*",
    }
    "repositories": {
         "whatever": {
             "type": "path",
             "url": "../packages/your-awesome-package"
         }
    }
}

This setup helps me really speed up my package development & usage on the application.