How to build wheels with composer

Source: Internet
Author: User
Composer is a dependency management tool for PHP, this article explains how to build a package and submit it to packagist so that others can easily use your package through composer.

There are several steps to developing the composer package:

    1. Initializing the Composer.json file

    2. Defining Namespaces and package names

    3. Implementing the functionality that the package needs to implement

    4. Submit to GitHub

    5. Registering packages in Packagist

Initializing the Composer.json file

After you install composer, you can run it locally composer init by setting up Composer.json on the interactive command line.

Several of these properties are described below, along with general settings:

Name

This property defines the package name, separated by the vendor name, followed by the package name, and the vendor represents the unique name provided by the developer for the Packagist Web site, which is used to organize the package and to prevent naming conflicts. Therefore, it is best to first visit Https://packagist.org/packages/yourvendorname the URL to replace the yourvendorname with the name you want to take, if the page does not have 404, the description has been registered.

License

License. About the license, we suggest two articles, open source project license Introduction, how to choose License

Require

The dependencies required to install the current package. The current package will be installed only if all dependencies are installed.

AutoLoad

This configuration is primarily PSR-4 or PSR-0 settings, and it is recommended to use the PSR-4 standard.

http://json-schema.org/introduces the definition of JSON schema and the implementation of each language to its various functions, with validator implementation, in which the JSON schema validator is an online authentication service. In fact, the simplest is composer validate composer.json to use to verify that the file is faulty.

Project structure

The project structure is a typical MVC structure,

. └──geo    └──geosso        ├──license        ├──readme.md        ├──composer.json        └──src            ├──contracts            ├── Http            │   ├──controllers            │   ├──middleware            │   └──requests            ├──paramsbean            ├── Providers            ├──support            └──config12 Directories

LICENSE, readme.md and Composer.json are tree -d added manually after the operation.

The project root is defined under SRC and is also defined in Composer.json so that when composer loads the package, it knows how to parse the file path through the namespace.

The Http directory represents the request response, the Controllers represents a legitimate request for the Controller, middleware represents the first level of the request, through the middleware to intercept the request, requests to obtain the front-end request and filter the request.

Contracts represents the interface definition. Paramsbean represents the parameter encapsulation of the application layer when communicating with the underlying service, and the parameters passed through the Bean, rather than passing the array to make the call consistent, and forcing the interface invocation to do type detection, which can be used to a large extent to unify the parameter passing between the layers.

Providers represents the service container of Laravel, through the service container, can register routing and configuration, load helper class, BIND interface and its implementation.

Support is the helper class, the encapsulation of commonly used logic-independent functions, the Config represents the application of its own configuration, and the config makes it easy to set the configuration and use global function config() calls.

Submit to GitHub

Following the previous steps, a package has a basic skeleton, which is then uploaded to GitHub, configuring the project, integrating the continuous integration service, and releasing the Open source project license.

GitHub initializes the project with the option to generate a. gitignore file, select the license, initialize the readme.md file, switch to the local project directory, and then upload the directory to GitHub as follows:

GIT init # Initialize repository git remote Set-url origin--push--add Git@github.com:jayxhj/geosso.git # Add remote tracking warehouse address git Add. Git commitgit Push Origin Master

Submit to Packagist

Packagist Gets the address of the package metadata information for composer by default, fetching the metadata information from packagist and then pulling the code from GitHub. So, when uploading your development package to GitHub, you need to register it in packagist so that people around the world can pull your code through composer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.