How to develop your own php expansion package with composer
Editor to share with you how to use composer to develop their own php expansion package, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Composer is a tool used by PHP to manage dependencies
Development process
Initialize your own expansion pack composer init
$composer init Welcome to the Composer config generator This command will guide you through creating your composer.json config.Package name (/) [administrator/self_composer]: victor/composer-self / / package name-cannot be capitalized Otherwise invalid Description []: composer-self package / / description Author [victor24680, n to skip]: / / author Minimum Stability []: dev / / minimum stable version Package Type (e.g. Library, project, metapackage, composer-plugin) []: library / / Type License []: MITDefine your dependencies.Would you like to define your dependencies (require) interactively [yes]? N / / do you define the dependency Would you like to define your dev dependencies (require-dev) interactively [yes]? N {"name": "victor/composer-self", "description": "This is a composer-send package", "type": "victor", "license": "MIT", "authors": [{"name": "victor24680", "email": "490319148@qq.com"}], "minimum-stability": "dev" "require": {}} Do you confirm generation [yes]? Yes
Modify the dependency of your own package, as follows
{"name": "victor/sendtool-package", "description": "sendtool package", "type": "victor", "license": "MIT", "authors": [{"name": "victor24680", "email": "490319148@qq.com"}], "minimum-stability": "dev" "require": {"php": "> = 5.6" / / php version requirements}, "autoload": {"psr-4": {/ / loading specification "App\": "src/App", "Contract\": "src/Contract"}
To prepare the source code, please see: https://github.com/victor24680/self-composer/tree/master/src
Install and test composer install
$composer installLoading composer repositories with package informationUpdating dependencies (including require-dev) Content-Length mismatch, received 37487 bytes out of the expected 2005372 http://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of dateNothing to install or updateWriting lock fileGenerating autoload files
Create a composer-self repository on GitHub
Git initgit add .git commit-m "initial component library" git remote add origin https://github.com/victor24680/self-composer.gitgit push origin master
Submit the address of the composer-self warehouse created by your github on Packagist
Registered address: https://packagist.org/, after the submission is successful, you can start the following test
Test, directory A represents the project root directory
Create an A directory and execute it under the project root: composer require victor24680/self-composer dev-master
$composer require victor24680/self-composer dev-master./composer.json has been updatedLoading composer repositories with package informationUpdating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals-Installing victor24680/self-composer (dev-master 0935c75): Cloning 0935c75eda from cacheWriting lock fileGenerating autoload files