Instructions for creating a PHP package for Composer

Tram Ho

Recently, I recently tried my best to upload a lot of code to open source repositories like Github and Codepen . It makes starting up new projects so much simpler when I can copy a summary from my Github or copy a piece of CSS / JS from CodePen . But what happens when I need to include libraries or modules in some projects? Cloning and copying paste just doesn’t pack it at that time.

Packed into NPM and Composer (or Packagist ). NPM is package management software for Javascript using Node , and Composer is similar but used in PHP .

Today, we are considering submiting a PHP “package” to Composer through Packagist, so we can install the package into the project using composer require

Simple steps: Make it easy with 4 steps (except for the part you code package in PHP ). Before you begin, you need to create a repository on Githib and commit the code on it. Also need an account on Github and Packagist .

  • Create composer.json file in the project:

It’s easy, no reason One of the biggest programming principles I try to apply is DRY, don’t repeat yourself. Once your code may already be hosted on Github, it’s just a two-step process to get your code where its version is controlled. Instead of relying on git clone or subodules, using a composer dependency would be much more efficient.

Get my code to test it

Reference: https://github.com/nhannguyen09cntt/php-discourse-sdk

Source: https://4rum.vn/t/h-ng-dnto-php-package-cho-composer/3077

Share the news now

Source : Viblo