Composer - creating and publishing your library

March 21, 2017 9 Yehor Rykhnov

A brief guide to creating and publishing your library, extensions, additions with the help of composer.

Create the folders of your library:

mkdir mylib
mkdir mylib/mypackage

Create a simple class (the filename must match the class name):

<?php
// mylib/mypackage/MyTestClass
namespace mylib\mypackage;
class MyTestClass { public function __construct() { echo __CLASS__; } }

If you were in the mylib/mypackage directory, return to the root of your library.

Now, you need to create a repository (for example, on github) and push your project there.

Create a project in composer:

composer init

As a result, the program will offer you several tips that you will need to fill out.

After that, you need to push in the changes to your external repository.

Publish the package.
Go to the site https://packagist.org, log in and go to the page https://packagist.org/packages/submit. On this page, in the field: Repository URL (Git/Svn/Hg) specify a link to your external repository and save the changes..

After saving, you can install your library through composer.