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:
- Create a project directory
mkdir composer-test
CD Comopser-test
- 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
- 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
- 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
- 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
-
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>
-
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
- 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