PHP develop your own package with local composer environment

PHP develop your own package with local composer environment

Apr 17, 2019 / Ramesh Mhetre

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 Environment

PHP 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.


Similar Articles

Compiling assets with Laravel Mix

Compiling assets with Laravel Mix

Laravel Mix provides a fluent API for defining Webpack build steps
Read more...
Using Laravel's Eloquent ORM Efficiently

Using Laravel's Eloquent ORM Efficiently

Tips & tricks for Laravel's Eloquent ORM.
Read more...
Laravel Scout: Standard way to use algolia search with your Laravel application

Laravel Scout: Standard way to use algolia search with your Laravel application

Algolia search engine within your Laravel application using Laravel Scout.
Read more...