Develop composer package, upload packagist and Live Update + release stable version

Source: Internet
Author: User
Tags autoload

This period of time is busy, have no time to write something, today to write casually.
Background: In the new company found a phenomenon, many have been working for six or seven of years old programmers do not use git, and will not search online, and for the use of composer development package is also less understanding, and now I do a primer summary.

不说废话,直奔主题  ——  鲁迅 ^_^参考文档:https://laravel-china.org/docs/composer/2018协议:http://www.ruanyifeng.com/blog/2011/05/how_to_choose_free_software_licenses.html

Steps:

  1. Create a project directory
    mkdir composer-test
    CD Comopser-test
  2. Initialization
    Composer Init
    Tips for configuring Packagist information:
    Enter the project namespace name: Packagist name, suggested GitHub username/project name, Leesin/composer-test
    Project Description Description: Project description, will now be in Packagist project introduction
    Author Information author:leesin <[email protected]>
    Enter the lowest stable version: stable, RC, beta, alpha, dev
    Enter project type: library, Project, Metapackage, Composer-plugin
    Enter authorization type: Open source software general Choice MIT
    Input dependency Information:yes-> Search package name (can be PHP, etc.) input version
    = >= <= or something.
    Whether you need Require-dev: Ibid.
    Build: Yes, generate Composr.json
  3. Upload GitHub
    Git init && echo ' Hello World ' >> readme.md
    git Add. && git commit-m ' init '
    Git remote add Origin warehouse address
    git Push origin-u warehouse address
  4. Submit Packagist
    Submit a package on GitHub to packagist registration
    submit-> Input Warehouse address->check-> through the detection to submit to the Packagist
    If the hint already exists, you can modify the package name or submit it directly
  5. Set composer Package Automatic Updates
    By default, GitHub code updates, composer packages are not automatically updated
    scenarios: Using GitHub service hooks
    Setting->integrations & Services->add Service Search packagist-> fill in the information:
    user:packagist user name
    token:packagist.org profile Show API token check See
    domain:https://packagist.org/
    Edit, test service, [Okay, the test payload is on its-means.] To automatically update the
  6. Use
    Pull GitHub code through packagist
    Composer Create-project packagist name Project name--prefer-dist dev-master [Specify version]

      References other packages composer require package_name for automatic loading: include vendor/autoload.php or modify Composer.json, increase AutoLoad configuration items, files represents the file to be loaded automatically, psr-4 represents the namespace to be automatically loaded Classmap is generally used to automatically load some development classes, psr-4 is the automatic loading of project code, psr-0 is basically replaced by psr-4, files mode                    Mainly for the global helper, such as function loading, after the configuration is done composer Dump-autoload can "AutoLoad": {"Files": [ "Src/functions.php", "", ...], "psr-4": {" leesin\\ ":" src ",//front namespace, behind directory}} composer dump/dump-autoload Follow configuration file, reload configuration  
    li>
  7. Supplement: Common package Structure
    .
    ├──composer.json
    ├──readme.md
    └──src//source directory
    └──hello.php

      mkdir src && Touch Src/hell                            o.php <?php namespace Leesin;                                    Class Hello {public static function SayHello () {                                Return ' Hello World '; }} Configure auto-load "AutoLoad": {"psr-4": {"Le esin\\ ":" src/"#" namespace \ ":" Directory Name/", which means the namespace under SRC is leesin}} composer dump create test File Touch test.php <?php require __dir__. '                            /vendor/autoload.php ';                            Use Leesin\hello;    Echo Hello::sayhello (); Test: PHP test.php output Hello World indicates success  
  8. Git tag release stable version composer package
    git tag-a v0.1-m ' version 0.1 '
    Git push Origin--tags
    Refresh in packagist to see

Develop composer package, upload packagist and Live Update + release stable version

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.