Home >Development Tools >composer >Teach you how to create your first composer package

Teach you how to create your first composer package

藏色散人
藏色散人forward
2022-02-01 05:00:312961browse

This article is provided by the composer tutorial column to introduce how to create the first composer package. I hope it will be helpful to friends in need!

uses the following two websites:
https://github.com/
https: //packagist.org

(0)Article structure:

1 Build:

  • Create github project;
  • Submit to packagist;

2 Use;

(1)Build

A composer package is a github repository plus a composer.json;

My hello_world project Screenshot:

Teach you how to create your first composer package

git log screenshot. See clearly that tag is added (reference: https://docs.phpcomposer.com/... A tag must be added to automatically generate a stable version.

Teach you how to create your first composer package

How to submit to packagist, see https://packagist.org/Homepage:

Teach you how to create your first composer package

Follow the registration and operation:

Teach you how to create your first composer packageVerify that if there is no problem, you will see it on the package page. Pay attention to the package version in the lower right corner. My project has three version numbers (version Description of the number generation rules: the git master branch automatically generates the "dev-master" version, and each of the two tags generates a version number "1.0.0" and "1.0.1")

Teach you how to create your first composer package

(2) Use

Then you can download the package and use it. Take my project as an example:

composer create-project linzh/hello_world , so that it will download my latest version by default stable version (non-dev);
If you want to download other versions, you can specify it yourself, eg:composer create-project linzh/hello_world=dev-master, so that the "dev-master" version will be downloaded

If you do not add a tag, you must also specify the version number yourself, otherwise an error will be reported

Teach you how to create your first composer package

The above is the detailed content of Teach you how to create your first composer package. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete