What is Composer?

Written by: Sharath Shambu | December 18th, 2015

Category: Composer, Php

Create a simple Composer – Packagist PHP package This little article will guide you to create a simple composer package. What is Composer? Composer is a dependency manager for PHP. The way I’d like to look at it is – Composer facilitates the inclusion / reference of external PHP libraries in your project. In this article, we will talk about how to create a composer package instead of how to reference a library in your project. The main points ­ Create a repository on Github for your library ­ Your library needs to follow a simple file / folder structure ­ Your library should contain a composer.json file ­ You need to submit the Github repo link into Packagist Create a repository on Github I am sure you know how to do this pretty well. So go ahead and create one. Library folder structure Follow the below structure repo |­ composer.json \­ src \­ HelloWorld \­ HelloWorld.php composer.json This file mentions the configuration or setup of your composer package. See the example file below { “name”: “1985apps/inline­email”, “autoload”: { “psr­0”: { “InlineEmail”: “src” } } } name: vendor/package psr­0: namespace : path to files to include Submit your repository to Packagist This is the easy part. ­ Create an account at Packagist ­ Click on the “submit” link ­ Mention your Github link That’s it! Now anyone can include your package by using this (in their project’s composer.json). requires: { “vendor/package”: “dev­master” } You can use our package (1985apps/inline­email) as a reference on how to go about it. Feel free to download it, move files around and see how it works Helpful links: ­ 1985apps/email: https://github.com/1985apps/inline­email ­ Similar guide at Junior Grosse: http://grossi.io/2013/creating­your­first­composer- packagist­package/ ­ Composer: https://getcomposer.org/ ­ Packagist: https://packagist.org

Comments

comments

Leave Comment

We would love to hear from you and we appreciate the good and the bad.

Comments